You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you prefer a streamlined solution to build and deploy your model, SageMaker Python SDK offers additional APIs that apply intelligent defaults to help you create a SageMaker-deployable model in fewer steps. ``ModelBuilder`` simplifies model creation by performing the following tasks for you:
826
+
827
+
- Converts machine learning models trained using various frameworks like XgBoost or PyTorch into SageMaker-deployable models with a single line of code.
828
+
- Performs automatic container selection based on the model framework, so you don’t have to manually specify your container. You can still bring your own container by passing your own URI to `ModelBuilder`.
829
+
- Handles the serializing of data on the client side before sending it to the server for inference, and deserializing the results returned by the server. Data is correctly formatted without manual processing.
830
+
- Automated capture of dependencies, libraries and packages needed by your model. You don’t have to package the dependencies and upload to S3. The deployment environment matches the development environment to ensure a smooth transition from development to deployment.
831
+
832
+
Build your model with ModelBuilder
833
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
834
+
835
+
The ``ModelBuilder`` class can take your framework (Xgboost or Pytorch) model and convert it into a SageMaker-deployable model, generating the artifacts according the model server. If you don’t want to supply a model directly, you can provide inference code to specify a model source - this method is discussed in the following sections. There are many available options for `ModelBuilder`, but if your model doesn’t require extensive customization and you want to deploy immediately, you can supply at minimum a framework model, input, and output. If you did not set up a default role ARN, you need to provide it as well. To view all options offered in `ModelBuilder`, see the `ModelBuilder documentation
In the following code example, ``ModelBuilder`` is called with a framework model and an instance of ``SchemaBuilder`` with minimum arguments (to infer the corresponding functions for serializing and deserializing the endpoint input and output). No container is specified and no packaged dependencies are passed - SageMaker saves you preparation time and effort by automatically inferring these resources when you build your model.
839
+
840
+
.. code:: python
841
+
842
+
model_builder = ModelBuilder(
843
+
model=model,
844
+
schema_builder=SchemaBuilder(X_test, y_pred),
845
+
)
846
+
847
+
model_builder.build()
848
+
849
+
If you want to bring your own container, you can also specify the image URI and set the mode argument to ``Mode.LOCAL_CONTAINER`` as shown in the following example. When you want to deploy to SageMaker, change the argument to ``Mode.SAGEMAKER_ENDPOINT``.
``SchemaBuilder`` accepts sample input and output and can infer corresponding functions for serializing and deserializing the endpoint input and output. For example, the following example would work:
864
+
865
+
.. code:: python
866
+
867
+
input="How is the demo going?"
868
+
output ="Comment la démo va-t-elle?"
869
+
schema = SchemaBuilder(input, output)
870
+
871
+
However, you might want to further customize your serialization and deserialization functions. For example, you might want to pass an image and want your serializer to converts the image to a tensor before prediction. You can define this translation in ``CustomPayloadTranslator`` for input, output, or both, and pass them to ``SchemaBuilder``. For an example that creates custom input and output translators with ``CustomPayloadTranslator``, see `ModelBuilder examples
Call the build() function to create your deployable model. This step creates an inference.py in your working directory with the code necessary to create your schema, run serialization and deserialization of inputs and outputs, and perform other user-specified custom logic.
918
+
919
+
.. code:: python
920
+
921
+
# Build the model according to the model server specification and save it to as files in the working directory
922
+
model = model_builder.build()
923
+
924
+
Deploy your model with the model’s existing ``deploy()`` method. A model constructed from ``ModelBuilder`` enables live logging during deployment as an added feature.
925
+
926
+
.. code:: python
927
+
928
+
predictor = model.deploy(
929
+
initial_instance_count=1,
930
+
instance_type="ml.c6i.xlarge"
931
+
)
932
+
933
+
For more examples of using ``ModelBuilder`` to build your models, see
0 commit comments