Picklable Model#
About this page
This is an API reference the bentoml.picklable_model
module, which can be used for custom
Python-based ML models in BentoML. To learn more, visit Picklable Model guide.
Note
You can find more examples for Picklable Model in our examples/custom_python_model directory.
- bentoml.picklable_model.save_model(name: str, model: ModelType, *, signatures: dict[str, ModelSignature] | None = None, labels: t.Dict[str, str] | None = None, custom_objects: t.Dict[str, t.Any] | None = None, external_modules: t.List[ModuleType] | None = None, metadata: t.Dict[str, t.Any] | None = None) bentoml.Model [source]#
Save a model instance to BentoML modelstore.
- Parameters:
name β Name for given model instance. This should pass Python identifier check.
model β Instance of model to be saved.
signatures β Methods to expose for running inference on the target model. Signatures are used for creating Runner instances when serving model with bentoml.Service
labels β user-defined labels for managing models, e.g. team=nlp, stage=dev
custom_objects β user-defined additional python objects to be saved alongside the model, e.g. a tokenizer instance, preprocessor function, model configuration json
external_modules β user-defined additional python modules to be saved alongside the model or custom objects, e.g. a tokenizer module, preprocessor module, model configuration module
metadata β Custom metadata for given model.
- Returns:
A
tag
with a formatname:version
wherename
is the user-defined modelβs name, and a generatedversion
.- Return type:
Examples:
import bentoml bento_model = bentoml.picklable.save_model('picklable_pyobj', model)
- bentoml.picklable_model.load_model(bento_model: str | Tag | Model) ModelType [source]#
Load the picklable model with the given tag from the local BentoML model store.
- Parameters:
bento_model β Either the tag of the model to get from the store, or a BentoML
Model
instance to load the model from.- Returns:
The picklable model loaded from the model store or BentoML
Model
.
Example:
import bentoml picklable_model = bentoml.picklable_model.load_model('my_model:latest')
- bentoml.picklable_model.get(tag_like: str | bentoml._internal.tag.Tag) Model [source]#