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.


You can find more examples for Picklable Model in our examples/custom_python_model directory.

bentoml.picklable_model.save_model(name: Tag | 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.

  • 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.


A tag with a format name:version where name is the user-defined model’s name, and a generated version.

Return type:



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.


bento_model – Either the tag of the model to get from the store, or a BentoML Model instance to load the model from.


The picklable model loaded from the model store or BentoML Model.


import bentoml

picklable_model = bentoml.picklable_model.load_model('my_model:latest')
bentoml.picklable_model.get(tag_like: str | Tag) Model[source]#