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-1224] Add vLLM to docs and update outdated descriptions and images #425

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/images/guides/mlops/serving/deployment_creating.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions docs/user_guides/mlops/registry/frameworks/llm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# How To Export a LLM Model

## Introduction

In this guide you will learn how to export a [Large Language Model (LLM)](https://www.hopsworks.ai/dictionary/llms-large-language-models) 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: Download the LLM

Download your base or fine-tuned LLM. LLMs can typically be downloaded using the official frameworks provided by their creators (e.g., HuggingFace, Ollama, ...)

=== "Python"
```python
# Download LLM (e.g., using huggingface to download Llama-3.1-8B base model)
from huggingface_hub import snapshot_download

model_dir = snapshot_download(
"meta-llama/Llama-3.1-8B",
ignore_patterns="original/*"
)
```

### Step 3: (Optional) Fine-tune LLM

If necessary, fine-tune your LLM with an [instruction set](https://www.hopsworks.ai/dictionary/instruction-datasets-for-fine-tuning-llms). A LLM can be fine-tuned fully or using [Parameter Efficient Fine Tuning (PEFT)](https://www.hopsworks.ai/dictionary/parameter-efficient-fine-tuning-of-llms) methods such as LoRA or QLoRA.

=== "Python"
```python
# Fine-tune LLM using PEFT (LoRA, QLoRA) or other methods
model_dir = ...
```

### Step 4: Register model in registry

Use the `ModelRegistry.llm.create_model(..)` function to register a model as LLM. 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 = {'f1-score': 0.8, 'perplexity': 31.62, 'bleu-score': 0.73}

llm_model = mr.llm.create_model("llm_model", metrics=metrics)

llm_model.save(model_dir)
```

## Going Further

You can attach an [Input Example](../input_example.md) and a [Model Schema](../input_example.md) to your model to document the shape and type of the data the model was trained on.
53 changes: 26 additions & 27 deletions docs/user_guides/mlops/registry/frameworks/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,53 @@ In this guide you will learn how to export a generic Python model and register i

### Step 1: Connect to Hopsworks

```python
import hopsworks
=== "Python"
```python
import hopsworks

project = hopsworks.login()
project = hopsworks.login()

# get Hopsworks Model Registry handle
mr = project.get_model_registry()
```
# get Hopsworks Model Registry handle
mr = project.get_model_registry()
```

### Step 2: Train

Define your XGBoost model and run the training loop.

```python
# Define a model
model = XGBClassifier()
=== "Python"
```python
# Define a model
model = XGBClassifier()

# Train model
model.fit(X_train, y_train)

```
# Train model
model.fit(X_train, y_train)
```

### Step 3: Export to local path

Export the XGBoost model to a directory on the local filesystem.

```python

model_file = "model.json"

model.save_model(model_file)
=== "Python"
```python
model_file = "model.json"

```
model.save_model(model_file)
```

### Step 4: Register model in registry

Use the `ModelRegistry.python.create_model(..)` function to register a model as a Python 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

# Model evaluation metrics
metrics = {'accuracy': 0.92}

py_model = mr.python.create_model("py_model", metrics=metrics)
=== "Python"
```python
# Model evaluation metrics
metrics = {'accuracy': 0.92}

py_model.save(model_dir)
py_model = mr.python.create_model("py_model", metrics=metrics)

```
py_model.save(model_dir)
```

## Going Further

Expand Down
51 changes: 25 additions & 26 deletions docs/user_guides/mlops/registry/frameworks/skl.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,52 @@ In this guide you will learn how to export a Scikit-learn model and register it

### Step 1: Connect to Hopsworks

```python
import hopsworks
=== "Python"
```python
import hopsworks

project = hopsworks.login()
project = hopsworks.login()

# get Hopsworks Model Registry handle
mr = project.get_model_registry()
```
# get Hopsworks Model Registry handle
mr = project.get_model_registry()
```

### Step 2: Train

Define your Scikit-learn model and run the training loop.

```python
# Define a model
iris_knn = KNeighborsClassifier(..)
=== "Python"
```python
# Define a model
iris_knn = KNeighborsClassifier(..)

iris_knn.fit(..)

```
iris_knn.fit(..)
```

### Step 3: Export to local path

Export the Scikit-learn model to a directory on the local filesystem.

```python

model_file = "skl_knn.pkl"

joblib.dump(iris_knn, model_file)
=== "Python"
```python
model_file = "skl_knn.pkl"

```
joblib.dump(iris_knn, model_file)
```

### Step 4: Register model in registry

Use the `ModelRegistry.sklearn.create_model(..)` function to register a model as a Scikit-learn 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

# Model evaluation metrics
metrics = {'accuracy': 0.92}

skl_model = mr.sklearn.create_model("skl_model", metrics=metrics)
=== "Python"
```python
# Model evaluation metrics
metrics = {'accuracy': 0.92}

skl_model.save(model_file)
skl_model = mr.sklearn.create_model("skl_model", metrics=metrics)

```
skl_model.save(model_file)
```

## Going Further

Expand Down
63 changes: 31 additions & 32 deletions docs/user_guides/mlops/registry/frameworks/tf.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,59 @@ In this guide you will learn how to export a TensorFlow model and register it in

### Step 1: Connect to Hopsworks

```python
import hopsworks
=== "Python"
```python
import hopsworks

project = hopsworks.login()
project = hopsworks.login()

# get Hopsworks Model Registry handle
mr = project.get_model_registry()
```
# get Hopsworks Model Registry handle
mr = project.get_model_registry()
```

### Step 2: Train

Define your TensorFlow model and run the training loop.

```python
# Define a model
model = tf.keras.Sequential()
=== "Python"
```python
# Define a model
model = tf.keras.Sequential()

# Add layers
model.add(..)
# Add layers
model.add(..)

# Compile the model.
model.compile(..)

# Train the model
model.fit(..)

```
# Compile the model.
model.compile(..)

# Train the model
model.fit(..)
```

### Step 3: Export to local path

Export the TensorFlow model to a directory on the local filesystem.

```python

model_dir = "./model"

tf.saved_model.save(model, model_dir)
=== "Python"
```python
model_dir = "./model"

```
tf.saved_model.save(model, model_dir)
```

### Step 4: Register model in registry

Use the `ModelRegistry.tensorflow.create_model(..)` function to register a model as a TensorFlow 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

# Model evaluation metrics
metrics = {'accuracy': 0.92}

tf_model = mr.tensorflow.create_model("tf_model", metrics=metrics)
=== "Python"
```python
# Model evaluation metrics
metrics = {'accuracy': 0.92}

tf_model.save(model_dir)
tf_model = mr.tensorflow.create_model("tf_model", metrics=metrics)

```
tf_model.save(model_dir)
```

## Going Further

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
@@ -1,6 +1,6 @@
# Model Registry Guides

Hopsworks Model Registry is a centralized repository, within an organization, to manage machine learning models. A model is the product of training a machine learning algorithm with training data.
**Hopsworks Model Registry** is a centralized repository, within an organization, to manage machine learning models. A model is the product of training a machine learning algorithm with training data.

This section provides guides for creating models and publish them to the Model Registry to make them available for download for batch predictions, or deployed to serve realtime applications.

Expand All @@ -13,6 +13,8 @@ Follow these framework-specific guides to export a Model to the Model Registry.

* [Scikit-learn](frameworks/skl.md)

* [LLM](frameworks/llm.md)

* [Other frameworks](frameworks/python.md)


Expand Down
35 changes: 18 additions & 17 deletions docs/user_guides/mlops/registry/input_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,34 @@ In this guide you will learn how to attach an input example to a model. An input

### Step 1: Connect to Hopsworks

```python
import hopsworks
=== "Python"
```python
import hopsworks

project = hopsworks.login()
project = hopsworks.login()

# get Hopsworks Model Registry handle
mr = project.get_model_registry()
```
# get Hopsworks Model Registry handle
mr = project.get_model_registry()
```

### Step 2: Generate an input example

Generate an input example which corresponds to a valid input to your model. Currently we support `pandas.DataFrame, pandas.Series, numpy.ndarray, list` to be passed as input example.

```python
import numpy as np
=== "Python"
```python
import numpy as np

input_example = np.random.randint(0, high=256, size=784, dtype=np.uint8)

```
input_example = np.random.randint(0, high=256, size=784, dtype=np.uint8)
```

### Step 3: Set input_example parameter

Set the `input_example` parameter in the `create_model` function and call `save()` to attaching it to the model and register it in the registry.
```python

model = mr.tensorflow.create_model(name="mnist",
input_example=input_example)
model.save("./model")

```
=== "Python"
```python
model = mr.tensorflow.create_model(name="mnist",
input_example=input_example)
model.save("./model")
```
Loading