add_job
Create or update a training job. Learn more about training jobs.
Parameters
mb.add_job({training_function}, python_version=, ...)
Standard parameters
training_function:CallableThe function used to define the job. It should return a trained model object, or similar.name:Optional[str]: The name of the training job. If no name is supplied the name oftraining_functionwill be used.branch:Optional[str]: The branch where the job will be stored. By default it's the current branch of the session.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]]Thepippackages to install in the training job's environment. E.g.["scikit-learn==1.0.2"].requirements_txt_path:Optional[str]The filepath of a pip-compatiblerequirements.txtthat specifies all of the packages needed for this training job.system_packages:Optional[List[str]]Theapt-getpackages to install in the training job's environment. E.g.["libgomp1"].
Extra files parameters
extra_files:Optional[str, List[str], Dict[str, str]]Additional files to include with the training job.- 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 training job. This format is for advanced use cases needing name or path of a file to be different in the training job vs. locally.
- as
skip_extra_files_dependencies:Optional[bool]IfTruethenmb.add_jobwill not parseextra_filesto determine additional Python package dependencies. Default isFalse.skip_extra_files_discovery:Optional[bool]IfTruethenmb.add_jobwill not include additional files it discovers while parsing the files listedextra_files. Use this to limitmb.add_jobto only include theextra_filesthat are specified. Default isFalse.
Additional parameters
base_image:Optional[string]For training jobs that need special libraries, like the NVIDIA Container Toolkit, to be installed in the environment. Learn more about base images.
Returns
The call to mb.add_job is typically done in an interactive environment, like a Python notebook. The command will print out status, and then show link to open the job in Modelbit.
Examples
This example function trains a model and adds it to the model registry.
def train_model():
# code to create a model
my_model = ...
# add the model to the registry
mb.add_model(my_model)
Creating a training job
Create a training job that will run the function, train_model:
mb.add_job(train_model)
Including dependencies
Specify the Python version, extra files, or additional packages to install when creating the training job:
mb.add_job(train_model,
name="my_training_job",
python_version="3.10",
python_packages=["pandas==2.2.2"],
extra_files=["some_file.txt"])
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.add_job(train_model, python_version="3.10", requirements_txt_path="my_requirements.txt")