Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HWORKS-1885] Improve vLLM-related docs #445

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion docs/user_guides/mlops/registry/frameworks/llm.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 4 additions & 0 deletions docs/user_guides/mlops/registry/frameworks/python.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
description: Documentation on how to export a Python model to the model registry
---

# How To Export a Python Model

## Introduction
Expand Down
4 changes: 4 additions & 0 deletions docs/user_guides/mlops/registry/frameworks/skl.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
79 changes: 79 additions & 0 deletions docs/user_guides/mlops/registry/frameworks/tch.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions docs/user_guides/mlops/registry/frameworks/tf.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
description: Documentation on how to export a Tensorflow model to the model registry
---

# How To Export a TensorFlow Model

## Introduction
Expand Down
4 changes: 3 additions & 1 deletion docs/user_guides/mlops/registry/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 19 additions & 10 deletions docs/user_guides/mlops/serving/deployment.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand All @@ -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

Expand Down
Loading