diff --git a/docs/assets/images/guides/mlops/serving/deployment_simple_form_vllm_conf_file.png b/docs/assets/images/guides/mlops/serving/deployment_simple_form_vllm_conf_file.png new file mode 100644 index 000000000..a9a04b41c Binary files /dev/null and b/docs/assets/images/guides/mlops/serving/deployment_simple_form_vllm_conf_file.png differ diff --git a/docs/user_guides/mlops/registry/frameworks/llm.md b/docs/user_guides/mlops/registry/frameworks/llm.md index 986dee6bf..ee9e29a05 100644 --- a/docs/user_guides/mlops/registry/frameworks/llm.md +++ b/docs/user_guides/mlops/registry/frameworks/llm.md @@ -1,4 +1,8 @@ -# How To Export an LLM Model +--- +description: Documentation on how to export a Large Language Model (LLM) to the model registry +--- + +# How To Export a Large Language Model (LLM) ## Introduction diff --git a/docs/user_guides/mlops/registry/frameworks/python.md b/docs/user_guides/mlops/registry/frameworks/python.md index af4689c60..8a7544aa9 100644 --- a/docs/user_guides/mlops/registry/frameworks/python.md +++ b/docs/user_guides/mlops/registry/frameworks/python.md @@ -1,3 +1,7 @@ +--- +description: Documentation on how to export a Python model to the model registry +--- + # How To Export a Python Model ## Introduction diff --git a/docs/user_guides/mlops/registry/frameworks/skl.md b/docs/user_guides/mlops/registry/frameworks/skl.md index e364101a9..81d8254bf 100644 --- a/docs/user_guides/mlops/registry/frameworks/skl.md +++ b/docs/user_guides/mlops/registry/frameworks/skl.md @@ -1,3 +1,7 @@ +--- +description: Documentation on how to export a Scikit-learn model to the model registry +--- + # How To Export a Scikit-learn Model ## Introduction diff --git a/docs/user_guides/mlops/registry/frameworks/tch.md b/docs/user_guides/mlops/registry/frameworks/tch.md new file mode 100644 index 000000000..040cf61be --- /dev/null +++ b/docs/user_guides/mlops/registry/frameworks/tch.md @@ -0,0 +1,79 @@ +--- +description: Documentation on how to export a Pytorch model to the model registry +--- + +# How To Export a Torch Model + +## Introduction + +In this guide you will learn how to export a Torch model and register it in the Model Registry. + + +## Code + +### Step 1: Connect to Hopsworks + +=== "Python" + ```python + import hopsworks + + project = hopsworks.login() + + # get Hopsworks Model Registry handle + mr = project.get_model_registry() + ``` + +### Step 2: Train + +Define your Torch model and run the training loop. + +=== "Python" + ```python + # Define the model architecture + class Net(nn.Module): + def __init__(self): + super().__init__() + self.conv1 = nn.Conv2d(3, 6, 5) + ... + + def forward(self, x): + x = self.pool(F.relu(self.conv1(x))) + ... + return x + + # Instantiate the model + net = Net() + + # Run the training loop + for epoch in range(n): + ... + ``` + +### Step 3: Export to local path + +Export the Torch model to a directory on the local filesystem. + +=== "Python" + ```python + model_dir = "./model" + + torch.save(net.state_dict(), model_dir) + ``` + +### Step 4: Register model in registry + +Use the `ModelRegistry.torch.create_model(..)` function to register a model as a Torch model. Define a name, and attach optional metrics for your model, then invoke the `save()` function with the parameter being the path to the local directory where the model was exported to. + +=== "Python" + ```python + # Model evaluation metrics + metrics = {'accuracy': 0.92} + + tch_model = mr.torch.create_model("tch_model", metrics=metrics) + + tch_model.save(model_dir) + ``` + +## Going Further + +You can attach an [Input Example](../input_example.md) and a [Model Schema](../model_schema.md) to your model to document the shape and type of the data the model was trained on. diff --git a/docs/user_guides/mlops/registry/frameworks/tf.md b/docs/user_guides/mlops/registry/frameworks/tf.md index d74630cbe..64a5e7225 100644 --- a/docs/user_guides/mlops/registry/frameworks/tf.md +++ b/docs/user_guides/mlops/registry/frameworks/tf.md @@ -1,3 +1,7 @@ +--- +description: Documentation on how to export a Tensorflow model to the model registry +--- + # How To Export a TensorFlow Model ## Introduction diff --git a/docs/user_guides/mlops/registry/index.md b/docs/user_guides/mlops/registry/index.md index 0fe2f4088..ddc2adab6 100644 --- a/docs/user_guides/mlops/registry/index.md +++ b/docs/user_guides/mlops/registry/index.md @@ -11,11 +11,13 @@ Follow these framework-specific guides to export a Model to the Model Registry. * [TensorFlow](frameworks/tf.md) +* [Torch](frameworks/tch.md) + * [Scikit-learn](frameworks/skl.md) * [LLM](frameworks/llm.md) -* [Other frameworks](frameworks/python.md) +* [Other Python frameworks](frameworks/python.md) ## Model Schema diff --git a/docs/user_guides/mlops/serving/deployment.md b/docs/user_guides/mlops/serving/deployment.md index cab182975..59e4f8447 100644 --- a/docs/user_guides/mlops/serving/deployment.md +++ b/docs/user_guides/mlops/serving/deployment.md @@ -1,11 +1,15 @@ -# How To Create A Deployment +--- +description: Documentation on how to deployment Machine Learning (ML) models and Large Language Models (LLMs) +--- + +# How To Create A Model Deployment ## Introduction In this guide, you will learn how to create a new deployment for a trained model. !!! warning - This guide assumes that a model has already been trained and saved into the Model Registry. To learn how to create a model in the Model Registry, see [Model Registry Guide](../registry/frameworks/tf.md) + This guide assumes that a model has already been trained and saved into the Model Registry. To learn how to create a model in the Model Registry, see [Model Registry Guide](../registry/index.md#exporting-a-model) Deployments are used to unify the different components involved in making one or more trained models online and accessible to compute predictions on demand. For each deployment, there are four concepts to consider: @@ -41,8 +45,8 @@ After selecting the model, the rest of fields are filled automatically. We pick !!! notice "Deployment name validation rules" A valid deployment name can only contain characters a-z, A-Z and 0-9. -!!! info "Predictor script for Python models and LLMs" - For Python models and LLMs, you must select a custom [predictor script](#predictor) that loads and runs the trained model by clicking on `From project` or `Upload new file`, to choose an existing script in the project file system or upload a new script, respectively. +!!! info "Predictor script for Python models" + For Python models, you must select a custom [predictor script](#predictor) that loads and runs the trained model by clicking on `From project` or `Upload new file`, to choose an existing script in the project file system or upload a new script, respectively. If you prefer, change the name of the deployment, model version or [artifact version](#model-artifact). Then, click on `Create new deployment` to create the deployment for your model. @@ -76,10 +80,10 @@ You will be redirected to a full-page deployment creation form where you can see !!! info "Deployment advanced options" 1. [Predictor](#predictor) 2. [Transformer](#transformer) - 3. [Inference logger](#inference-logger) - 4. [Inference batcher](#inference-batcher) - 5. [Resources](#resources) - 6. [API protocol](#api-protocol) + 3. [Inference logger](predictor.md#inference-logger) + 4. [Inference batcher](predictor.md#inference-batcher) + 5. [Resources](predictor.md#resources) + 6. [API protocol](predictor.md#api-protocol) Once you are done with the changes, click on `Create new deployment` at the bottom of the page to create the deployment for your model. @@ -174,7 +178,12 @@ Inside a model deployment, the local path to the model files is stored in the `M ## Artifact Files -Artifact files are files involved in the correct startup and running of the model deployment. The most important files are the **predictor** and **transformer scripts**. The former is used to load and run the model for making predictions. The latter is typically used to transform model inputs at inference time. +Artifact files are files involved in the correct startup and running of the model deployment. The most important files are the **predictor** and **transformer scripts**. The former is used to load and run the model for making predictions. The latter is typically used to apply transformations on the model inputs at inference time before making predictions. Predictor and transformer scripts run on separate components and, therefore, scale independently of each other. + +!!! tip + Whenever you provide a predictor script, you can include the transformations of model inputs in the same script as far as they don't need to be scaled independently from the model inference process. + +Additionally, artifact files can also contain a **server configuration file** that helps detach configuration used within the model deployment from the model server or the implementation of the predictor and transformer scripts. Inside a model deployment, the local path to the configuration file is stored in the `CONFIG_FILE_PATH` environment variable (see [environment variables](../serving/predictor.md#environment-variables)). Every model deployment runs a specific version of the artifact files, commonly referred to as artifact version. ==One or more model deployments can use the same artifact version== (i.e., same predictor and transformer scripts). Artifact versions are unique for the same model version. @@ -189,7 +198,7 @@ Inside a model deployment, the local path to the artifact files is stored in the All files under `/Models` are managed by Hopsworks. Changes to artifact files cannot be reverted and can have an impact on existing model deployments. !!! tip "Additional files" - Currently, the artifact files only include predictor and transformer scripts. Support for additional files (e.g., configuration files or other resources) is coming soon. + Currently, the artifact files can only include predictor and transformer scripts, and a configuration file. Support for additional files (e.g., other resources) is coming soon. ## Predictor diff --git a/docs/user_guides/mlops/serving/predictor.md b/docs/user_guides/mlops/serving/predictor.md index 2ad777ec5..79008919c 100644 --- a/docs/user_guides/mlops/serving/predictor.md +++ b/docs/user_guides/mlops/serving/predictor.md @@ -1,3 +1,7 @@ +--- +description: Documentation on how to configure a predictor for a model deployment +--- + # How To Configure A Predictor ## Introduction @@ -13,12 +17,13 @@ Predictors are the main component of deployments. They are responsible for runni 1. [Model server](#model-server) 2. [Serving tool](#serving-tool) 3. [User-provided script](#user-provided-script) - 4. [Python environments](#python-environments) - 5. [Transformer](#transformer) - 6. [Inference Logger](#inference-logger) - 7. [Inference Batcher](#inference-batcher) - 8. [Resources](#resources) - 9. [API protocol](#api-protocol) + 4. [Server configuration file](#server-configuration-file) + 5. [Python environments](#python-environments) + 6. [Transformer](#transformer) + 7. [Inference Logger](#inference-logger) + 8. [Inference Batcher](#inference-batcher) + 9. [Resources](#resources) + 10. [API protocol](#api-protocol) ## GUI @@ -85,7 +90,22 @@ To create your own it is recommended to [clone](../../projects/python/python_env
-### Step 5 (Optional): Enable KServe + +### Step 5 (Optional): Select a configuration file + +!!! note + Only available for LLM deployments. + +You can select a configuration file to be added to the [artifact files](deployment.md#artifact-files). If a predictor script is provided, this configuration file will be available inside the model deployment at the local path stored in the `CONFIG_FILE_PATH` environment variable. If a predictor script is **not** provided, this configuration file will be directly passed to the vLLM server. You can find all configuration parameters supported by the vLLM server in the [vLLM documentation](https://docs.vllm.ai/en/v0.7.1/serving/openai_compatible_server.html). + +
+
+