deploy
Deploy a Python function and dependencies to Modelbit. Return values of the function must be JSON-serializable.
Parameters
mb.delete_package({deployment_function}, python_version=, ...)
Standard parameters
deployment_function
:Callable
The function to deploy to Modelbit. If the function uses Python type hints for its parameters and return type, Modelbit will generate smarter sample code.python_version
:Optional["3.6"|"3.7"|"3.8"|"3.9"|"3.10"|"3.11"|"3.12"]
Python version to run in production.python_packages
:Optional[List[str]]
Thepip
packages to install in the deployment's environment. E.g.["scikit-learn==1.0.2"]
.requirements_txt_path
:Optional[str]
The filepath of a pip-compatiblerequirements.txt
that specifies all of the packages needed for this deployment.system_packages
:Optional[List[str]]
Theapt-get
packages to install in the deployment's environment. E.g.["libgomp1"]
.require_gpu
:Optional[bool|"T4"|"A10G"]
Configures the deployment to run in an environment with a GPU.name
:Optional[str]
The name of the deployment. If omitted, the name of thedeployment_function
is used.
DataFrame mode parameters
dataframe_mode
:Optional[bool]
Whether to deploy in DataFrame mode. IfTrue
,example_dataframe
must be specified.example_dataframe
:Optional[pandas.DataFrame]
DataFrame with the columns and column types to expect in production in DataFrame mode. If specified,dataframe_mode
must beTrue
.
Setup parameters
setup
:Optional[Union[str, List[str]]]
One or more names ofmodelbit.setup
blocks to include with the deployment.
Extra and common files parameters
extra_files
:Optional[str, List[str], Dict[str, str]]
Additional files to include with the deployment.- as
str
: The path to a single file or directory. - as
List[str]
: Paths to multiple files or directories. - as
Dict[str, str]
: Pairs of file paths or directories. The key is the local file path, the value is the file path in the deployment. This format is for advanced use cases where the name or path of a file is different in the deployment vs. locally.
- as
skip_extra_files_dependencies
:Optional[bool]
IfTrue
thenmb.deploy
will not parseextra_files
to determine additional Python package dependencies. Default isFalse
.skip_extra_files_discovery
:Optional[bool]
IfTrue
thenmb.deploy
will not include additional files it discovers while parsing the files listedextra_files
. Use this to limitmb.deploy
to only include theextra_files
specified. Default isFalse
.common_files
:Optional[str, List[str], Dict[str, str]]
All common files will be automatically included in the deployment unless their automatic linking setting has been disabled. To include common files that have automatic linking disabled, include them here.- as
str
: The path to a single file or directory. - as
List[str]
: Paths to multiple files or directories. - as
Dict[str, str]
: Pairs of file paths or directories. The key is the common file path, the value is the file path in the deployment.
- as
Snowflake parameters
snowflake_max_rows
:Optional[int]
For deployments that will be used from Snowflake, limit the number of rows the deployment will receive in each batch created by Snowflake. This is used to tune performance and avoid data size limitations.snowflake_mock_return_value
:Optional[Any]
Snowflake deployments can run inMOCK
mode, where they return a static value instead of calling the deployment. This can be useful for testing Snowflake changes unrelated to deployment changes. Set this parameter to the value this deployment should return when running inMOCK
mode. Default is SQL'snull
.
Returns
The call to mb.deploy
is typically done in an interactive environment, like a Python notebook. The command will print out status, and then show link to open the deployment in Modelbit.
Examples
The following examples use the simple example_deployment_function
as an example deployment function:
def example_deployment_function(a: int):
return a * 2
Deploying a simple function
Pass the inference function to mb.deploy
to create a deployment:
mb.deploy(example_deployment_function)
Deploying into a specific Python version
Specify the Python version with python_version=
mb.deploy(example_deployment_function, python_version="3.8")
Deploying with specific Python packages
Specify custom Python environments with python_packages=
and system_packages=
:
mb.deploy(example_deployment_function, python_packages=["pandas==2.0.3"])
Deploying with a requirements.txt
file
Specify the path to a pip-compatible requirements.txt
file that defines your custom Python environment with requirements_txt_path=
:
mb.deploy(example_deployment_function, requirements_txt_path="my_requirements.txt")
Deploying with dataframe_mode
Use DataFrame mode to create deployments that perform inferences on DataFrames:
mb.deploy(get_predictions, dataframe_mode=True, example_dataframe=X_train)
Deploying with a package built from git
Python packages be built from public GitHub repositories:
mb.deploy(find_cat, python_packages=["git+https://github.com/facebookresearch/segment-anything.git"])
Including local python files
Include additional files with the deployment by specifying extra_files=
:
mb.deploy(example_deployment_function, extra_files=["utils.py"])
Deploying to a GPU-enabled environment
Enable GPUs when creating the deployment by setting require_gpu=
:
mb.deploy(example_deployment, require_gpu=True)
See also
- Read the deployments section of the docs for more info on deploying to Modelbit.
get_inference