chassis_model
ChassisModel
The Chassis Model Object.
This class inherits from chassis.builder.Buildable and is the main object that gets fed into a Chassis builder object (i.e., chassis.builder.DockerBuilder or chassis.builder.RemoteBuilder)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
process_fn | PredictFunction | Single predict function of type | required |
batch_size | int | Integer representing the batch size your model supports. If your model does not support batching, the default value is 1. | 1 |
legacy_predict_fn | bool | For internal backwards-compatibility use only. | False |
chassis_client | For internal backwards-compatibility use only. | None |
runner instance-attribute
test
Runs a test inference against the model before it is packaged.
This method supports multiple input types
- Single input: A map-like object with a string for the key and bytes as the value.
- Batch input: A list of map-like objects with strings for keys and bytes for values.
The following input types are also supported but considered deprecated and may be removed in a future release
- File: A BufferedReader object. Use of this type assumes that your predict function expects the input key to be "input".
- bytes: Any arbitrary bytes. Use of this type assumes that your predict function expects the input key to be "input".
- str: A string. If the string maps to a filesystem location, then the file at that location will be read and used as the value. If not the string itself is used as the value. Use of this type assumes that your predict function expects the input key to be "input".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_input | Union[str, bytes, _io.BufferedReader, Mapping[str, bytes], Sequence[Mapping[str, bytes]]] | Sample input data used to test the model. See above for more information. | required |
Returns:
Type | Description |
---|---|
Sequence[Mapping[str, bytes]] | Results returned by your model's predict function based on the |
Example:
merge_package
add_requirements
Declare a pip requirement for your model.
The value of each requirement can be anything supported by a line in a requirements.txt
file, including version constraints, etc.
All pip requirements declared via this method will be automatically installed when the container is built.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reqs | Union[str, list[str]] | Single python package (str) or list of python packages that are required dependencies to run the | required |
test_batch
DEPRECATED
The chassisml.ChassisModel.test method now supports supplying batches of inputs.
add_apt_packages
Add an OS package that will be installed via apt-get
.
If your model requires additional OS packages that are not part of the standard Python container, you can declare them here. Each package declared here will be apt-get install
'd when the container is built.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
packages | Union[str, list] | Single OS-level package (str) or list of OS-level packages that are required dependencies to run the | required |
get_packaged_path
Convenience method for developers wanting to implement their own subclasses of Buildable. This method will return the final path in the built container of any additional files, etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | The local path of a file. | required |
Returns:
Type | Description |
---|---|
str | The path the file will have in the final built container. |
test_env
No Longer Available
Please use chassis.client.OMIClient.test_container moving forward.
save
save(path=None, requirements=None, overwrite=False, fix_env=False, gpu=False, arm64=False, conda_env=None)
DEPRECATED
Please use chassisml.ChassisModel.prepare_context moving forward.
Saves a copy of ChassisModel to local filepath
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Optional[str] | Filepath to save chassis model. | None |
requirements | Optional[Union[str, List[str]]] | Additional pip requirements needed by the model. | None |
conda_env | Optional[dict] | A dictionary with environment requirements. | None |
overwrite | bool | No longer used. | False |
fix_env | bool | No longer used. | False |
gpu | bool | If True and | False |
arm64 | bool | If True and | False |
Returns:
Type | Description |
---|---|
BuildContext | The |
Example:
verify_prerequisites
Raises an exception if the object is not yet ready for building.
Models require having a name, version, and at least one input and one output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options | BuildOptions | The | required |
prepare_context
Constructs the build context that will be used to build the container.
A build context is a directory containing a Dockerfile
and any other resources the Dockerfile
needs to build the container.
This method is called just before the build is initiated and compiles all the resources necessary to build the container. This includes the Dockerfile
, required Chassis library code, the server implementation indicated by the BuildOptions
, the cloudpickle'd model, the serialized model metadata, copies of any additional files, and a requirements.txt
.
Typically, you won't call this method directly, it will be called automatically by a Builder. The one instance where you might want to use this method directly is if you want to inspect the contents of the build context before sending it to a Builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options | BuildOptions | The | DefaultBuildOptions |
Returns:
Type | Description |
---|---|
BuildContext | A |
publish
publish(model_name, model_version, registry_user=None, registry_pass=None, requirements=None, fix_env=True, gpu=False, arm64=False, sample_input_path=None, webhook=None, conda_env=None)
DEPRECATED
Please use chassis.builder.RemoteBuilder moving forward.
Builds the model locally using Docker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name | str | Model name that serves as model's name and docker registry repository name. | required |
model_version | str | Version of model | required |
registry_user | Optional[str] | Docker registry username | None |
registry_pass | Optional[str] | Docker registry password | None |
requirements | Optional[Union[str, list[str]]] | Additional pip requirements needed by the model. | None |
conda_env | Optional[dict] | A dictionary with environment requirements. | None |
fix_env | bool | No longer used. | True |
gpu | bool | If True, builds container image that runs on GPU hardware | False |
arm64 | bool | If True, builds container image that runs on ARM64 architecture | False |
sample_input_path | Optional[str] | No longer used. | None |
webhook | Optional[str] | No longer used. | None |
Returns:
Type | Description |
---|---|
Details about the result of the build. |
Example:
render_dockerfile
Renders an appropriate Dockerfile
for this object with the supplied BuildOptions
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options | BuildOptions | The | required |
Returns:
Type | Description |
---|---|
str | A string containing the contents for a |
parse_conda_env
Supports legacy Chassis conda_env
functionality by parsing pip dependencies and inserting into the Buildable
object via the add_requirements
function.
If supplied, the input parameter will look like this:
env = {
"name": "sklearn-chassis",
"channels": ['conda-forge'],
"dependencies": [
"python=3.8.5",
{
"pip": [
"scikit-learn",
"numpy",
"chassisml"
]
}
]
}
chassis_model = ChassisModel(process_fn=predict)
chassis_model.parse_conda_env(env)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conda_env | Optional[dict] | A conda environment structure. See above for more details. | required |