@inject
def save(name: str, model: t.Union[('PathType', 'tf_ext.KerasModel', 'tf_ext.Module')], *, signatures: t.Optional['tf_ext.ConcreteFunction']=None, options: t.Optional['tf_ext.SaveOptions']=None, labels: t.Optional[t.Dict[(str, str)]]=None, custom_objects: t.Optional[t.Dict[(str, t.Any)]]=None, metadata: t.Optional[t.Dict[(str, t.Any)]]=None, model_store: 'ModelStore'=Provide[BentoMLContainer.model_store]) -> Tag:
    '\n    Save a model instance to BentoML modelstore.\n\n    Args:\n        name (:code:`str`):\n            Name for given model instance. This should pass Python identifier check.\n        model (:code:`Union[keras.Model, tf.Module, path-like objects]`):\n            Instance of model to be saved\n        labels (:code:`Dict[str, str]`, `optional`, default to :code:`None`):\n            user-defined labels for managing models, e.g. team=nlp, stage=dev\n        custom_objects (:code:`Dict[str, Any]]`, `optional`, default to :code:`None`):\n            user-defined additional python objects to be saved alongside the model,\n            e.g. a tokenizer instance, preprocessor function, model configuration json\n        metadata (:code:`Dict[str, Any]`, `optional`,  default to :code:`None`):\n            Custom metadata for given model.\n        model_store (:mod:`~bentoml._internal.models.store.ModelStore`, default to :mod:`BentoMLContainer.model_store`):\n            BentoML modelstore, provided by DI Container.\n        signatures (:code:`Union[Callable[..., Any], dict]`, `optional`, default to :code:`None`):\n            Refers to `Signatures explanation <https://www.tensorflow.org/api_docs/python/tf/saved_model/save>`_\n            from Tensorflow documentation for more information.\n        options (`tf.saved_model.SaveOptions`, `optional`, default to :code:`None`):\n            :obj:`tf.saved_model.SaveOptions` object that specifies options for saving.\n\n    Raises:\n        ValueError: If :obj:`obj` is not trackable.\n\n    Returns:\n        :obj:`~bentoml.Tag`: A :obj:`tag` with a format `name:version` where `name` is the user-defined model\'s name, and a generated `version` by BentoML.\n\n    Examples:\n\n    .. code-block:: python\n\n        import tensorflow as tf\n        import numpy as np\n        import bentoml\n\n        class NativeModel(tf.Module):\n            def __init__(self):\n                super().__init__()\n                self.weights = np.asfarray([[1.0], [1.0], [1.0], [1.0], [1.0]])\n                self.dense = lambda inputs: tf.matmul(inputs, self.weights)\n\n            @tf.function(\n                input_signature=[tf.TensorSpec(shape=[1, 5], dtype=tf.float64, name="inputs")]\n            )\n            def __call__(self, inputs):\n                return self.dense(inputs)\n\n        # then save the given model to BentoML modelstore:\n        model = NativeModel()\n        tag = bentoml.tensorflow.save("native_toy", model)\n\n    .. note::\n\n       :code:`bentoml.tensorflow.save` API also support saving `RaggedTensor <https://www.tensorflow.org/guide/ragged_tensor>`_ model and Keras model. If you choose to save a Keras model\n       with :code:`bentoml.tensorflow.save`, then the model will be saved under a :obj:`SavedModel` format instead of :obj:`.h5`.\n\n    '
    context: t.Dict[(str, t.Any)] = {'framework_name': 'tensorflow', 'pip_dependencies': [f'tensorflow=={get_tf_version()}'], 'import_from_tfhub': False}
    with bentoml.models.create(name, module=MODULE_NAME, options=None, context=context, labels=labels, custom_objects=custom_objects, metadata=metadata) as _model:
        if isinstance(model, (str, bytes, os.PathLike, pathlib.Path)):
            assert os.path.isdir(model)
            copy_tree(str(model), _model.path)
        else:
            if options:
                logger.warning(f"Parameter 'options: {str(options)}' is ignored when using tensorflow {get_tf_version()}")
            tf.saved_model.save(model, _model.path, signatures=signatures, options=options)
        return _model.tag
Save a model instance to BentoML modelstore.

Args:
    name (:code:`str`):
        Name for given model instance. This should pass Python identifier check.
    model (:code:`Union[keras.Model, tf.Module, path-like objects]`):
        Instance of model to be saved
    labels (:code:`Dict[str, str]`, `optional`, default to :code:`None`):
        user-defined labels for managing models, e.g. team=nlp, stage=dev
    custom_objects (:code:`Dict[str, Any]]`, `optional`, default to :code:`None`):
        user-defined additional python objects to be saved alongside the model,
        e.g. a tokenizer instance, preprocessor function, model configuration json
    metadata (:code:`Dict[str, Any]`, `optional`,  default to :code:`None`):
        Custom metadata for given model.
    model_store (:mod:`~bentoml._internal.models.store.ModelStore`, default to :mod:`BentoMLContainer.model_store`):
        BentoML modelstore, provided by DI Container.
    signatures (:code:`Union[Callable[..., Any], dict]`, `optional`, default to :code:`None`):
        Refers to `Signatures explanation <https://www.tensorflow.org/api_docs/python/tf/saved_model/save>`_
        from Tensorflow documentation for more information.
    options (`tf.saved_model.SaveOptions`, `optional`, default to :code:`None`):
        :obj:`tf.saved_model.SaveOptions` object that specifies options for saving.

Raises:
    ValueError: If :obj:`obj` is not trackable.

Returns:
    :obj:`~bentoml.Tag`: A :obj:`tag` with a format `name:version` where `name` is the user-defined model's name, and a generated `version` by BentoML.

Examples:

.. code-block:: python

    import tensorflow as tf
    import numpy as np
    import bentoml

    class NativeModel(tf.Module):
        def __init__(self):
            super().__init__()
            self.weights = np.asfarray([[1.0], [1.0], [1.0], [1.0], [1.0]])
            self.dense = lambda inputs: tf.matmul(inputs, self.weights)

        @tf.function(
            input_signature=[tf.TensorSpec(shape=[1, 5], dtype=tf.float64, name="inputs")]
        )
        def __call__(self, inputs):
            return self.dense(inputs)

    # then save the given model to BentoML modelstore:
    model = NativeModel()
    tag = bentoml.tensorflow.save("native_toy", model)

.. note::

   :code:`bentoml.tensorflow.save` API also support saving `RaggedTensor <https://www.tensorflow.org/guide/ragged_tensor>`_ model and Keras model. If you choose to save a Keras model
   with :code:`bentoml.tensorflow.save`, then the model will be saved under a :obj:`SavedModel` format instead of :obj:`.h5`.
@inject
def save(name: str, model: t.Union[('PathType', 'tf_ext.KerasModel', 'tf_ext.Module')], *, signatures: t.Optional['tf_ext.ConcreteFunction']=None, options: t.Optional['tf_ext.SaveOptions']=None, labels: t.Optional[t.Dict[(str, str)]]=None, custom_objects: t.Optional[t.Dict[(str, t.Any)]]=None, metadata: t.Optional[t.Dict[(str, t.Any)]]=None, model_store: 'ModelStore'=Provide[BentoMLContainer.model_store]) -> Tag:
    '\n    Save a model instance to BentoML modelstore.\n\n    Args:\n        name (:code:`str`):\n            Name for given model instance. This should pass Python identifier check.\n        model (:code:`Union[keras.Model, tf.Module, path-like objects]`):\n            Instance of model to be saved\n        labels (:code:`Dict[str, str]`, `optional`, default to :code:`None`):\n            user-defined labels for managing models, e.g. team=nlp, stage=dev\n        custom_objects (:code:`Dict[str, Any]]`, `optional`, default to :code:`None`):\n            user-defined additional python objects to be saved alongside the model,\n            e.g. a tokenizer instance, preprocessor function, model configuration json\n        metadata (:code:`Dict[str, Any]`, `optional`,  default to :code:`None`):\n            Custom metadata for given model.\n        model_store (:mod:`~bentoml._internal.models.store.ModelStore`, default to :mod:`BentoMLContainer.model_store`):\n            BentoML modelstore, provided by DI Container.\n        signatures (:code:`Union[Callable[..., Any], dict]`, `optional`, default to :code:`None`):\n            Refers to `Signatures explanation <https://www.tensorflow.org/api_docs/python/tf/saved_model/save>`_\n            from Tensorflow documentation for more information.\n        options (`tf.saved_model.SaveOptions`, `optional`, default to :code:`None`):\n            :obj:`tf.saved_model.SaveOptions` object that specifies options for saving.\n\n    Raises:\n        ValueError: If :obj:`obj` is not trackable.\n\n    Returns:\n        :obj:`~bentoml.Tag`: A :obj:`tag` with a format `name:version` where `name` is the user-defined model\'s name, and a generated `version` by BentoML.\n\n    Examples:\n\n    .. code-block:: python\n\n        import tensorflow as tf\n        import numpy as np\n        import bentoml\n\n        class NativeModel(tf.Module):\n            def __init__(self):\n                super().__init__()\n                self.weights = np.asfarray([[1.0], [1.0], [1.0], [1.0], [1.0]])\n                self.dense = lambda inputs: tf.matmul(inputs, self.weights)\n\n            @tf.function(\n                input_signature=[tf.TensorSpec(shape=[1, 5], dtype=tf.float64, name="inputs")]\n            )\n            def __call__(self, inputs):\n                return self.dense(inputs)\n\n        # then save the given model to BentoML modelstore:\n        model = NativeModel()\n        tag = bentoml.tensorflow.save("native_toy", model)\n\n    .. note::\n\n       :code:`bentoml.tensorflow.save` API also support saving `RaggedTensor <https://www.tensorflow.org/guide/ragged_tensor>`_ model and Keras model. If you choose to save a Keras model\n       with :code:`bentoml.tensorflow.save`, then the model will be saved under a :obj:`SavedModel` format instead of :obj:`.h5`.\n\n    '
    context: t.Dict[(str, t.Any)] = {'framework_name': 'tensorflow', 'pip_dependencies': [f'tensorflow=={get_tf_version()}'], 'import_from_tfhub': False}
    with bentoml.models.create(name, module=MODULE_NAME, options=None, context=context, labels=labels, custom_objects=custom_objects, metadata=metadata) as _model:
        if isinstance(model, (str, bytes, os.PathLike, pathlib.Path)):
            assert os.path.isdir(model)
            copy_tree(str(model), _model.path)
        else:
            if options:
                logger.warning(f"Parameter 'options: {str(options)}' is ignored when using tensorflow {get_tf_version()}")
            tf.saved_model.save(model, _model.path, signatures=signatures, options=options)
        return _model.tag