Skip to content

Commit 63b9831

Browse files
committed
[HWORKS-1224] Add vLLM to docs and update outdated descriptions and images
1 parent 2b978c7 commit 63b9831

31 files changed

+744
-603
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# How To Export a LLM Model
2+
3+
## Introduction
4+
5+
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.
6+
7+
## Code
8+
9+
### Step 1: Connect to Hopsworks
10+
11+
=== "Python"
12+
```python
13+
import hopsworks
14+
15+
project = hopsworks.login()
16+
17+
# get Hopsworks Model Registry handle
18+
mr = project.get_model_registry()
19+
```
20+
21+
### Step 2: Download the LLM
22+
23+
Download your base or fine-tuned LLM. LLMs can typically be downloaded using the official frameworks provided by their creators (e.g., HuggingFace, Ollama, ...)
24+
25+
=== "Python"
26+
```python
27+
# Download LLM (e.g., using huggingface to download Llama-3.1-8B base model)
28+
from huggingface_hub import snapshot_download
29+
30+
model_dir = snapshot_download(
31+
"meta-llama/Llama-3.1-8B",
32+
ignore_patterns="original/*"
33+
)
34+
```
35+
36+
### Step 3: (Optional) Fine-tune LLM
37+
38+
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.
39+
40+
=== "Python"
41+
```python
42+
# Fine-tune LLM using PEFT (LoRA, QLoRA) or other methods
43+
model_dir = ...
44+
```
45+
46+
### Step 4: Register model in registry
47+
48+
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.
49+
50+
=== "Python"
51+
```python
52+
# Model evaluation metrics
53+
metrics = {'f1-score': 0.8, 'perplexity': 31.62, 'bleu-score': 0.73}
54+
55+
llm_model = mr.llm.create_model("llm_model", metrics=metrics)
56+
57+
llm_model.save(model_dir)
58+
```
59+
60+
## Going Further
61+
62+
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.

docs/user_guides/mlops/registry/frameworks/python.md

+26-27
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,53 @@ In this guide you will learn how to export a generic Python model and register i
88

99
### Step 1: Connect to Hopsworks
1010

11-
```python
12-
import hopsworks
11+
=== "Python"
12+
```python
13+
import hopsworks
1314

14-
project = hopsworks.login()
15+
project = hopsworks.login()
1516

16-
# get Hopsworks Model Registry handle
17-
mr = project.get_model_registry()
18-
```
17+
# get Hopsworks Model Registry handle
18+
mr = project.get_model_registry()
19+
```
1920

2021
### Step 2: Train
2122

2223
Define your XGBoost model and run the training loop.
2324

24-
```python
25-
# Define a model
26-
model = XGBClassifier()
25+
=== "Python"
26+
```python
27+
# Define a model
28+
model = XGBClassifier()
2729

28-
# Train model
29-
model.fit(X_train, y_train)
30-
31-
```
30+
# Train model
31+
model.fit(X_train, y_train)
32+
```
3233

3334
### Step 3: Export to local path
3435

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

37-
```python
38-
39-
model_file = "model.json"
40-
41-
model.save_model(model_file)
38+
=== "Python"
39+
```python
40+
model_file = "model.json"
4241

43-
```
42+
model.save_model(model_file)
43+
```
4444

4545
### Step 4: Register model in registry
4646

4747
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.
4848

49-
```python
50-
51-
# Model evaluation metrics
52-
metrics = {'accuracy': 0.92}
53-
54-
py_model = mr.python.create_model("py_model", metrics=metrics)
49+
=== "Python"
50+
```python
51+
# Model evaluation metrics
52+
metrics = {'accuracy': 0.92}
5553

56-
py_model.save(model_dir)
54+
py_model = mr.python.create_model("py_model", metrics=metrics)
5755

58-
```
56+
py_model.save(model_dir)
57+
```
5958

6059
## Going Further
6160

docs/user_guides/mlops/registry/frameworks/skl.md

+25-26
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,52 @@ In this guide you will learn how to export a Scikit-learn model and register it
88

99
### Step 1: Connect to Hopsworks
1010

11-
```python
12-
import hopsworks
11+
=== "Python"
12+
```python
13+
import hopsworks
1314

14-
project = hopsworks.login()
15+
project = hopsworks.login()
1516

16-
# get Hopsworks Model Registry handle
17-
mr = project.get_model_registry()
18-
```
17+
# get Hopsworks Model Registry handle
18+
mr = project.get_model_registry()
19+
```
1920

2021
### Step 2: Train
2122

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

24-
```python
25-
# Define a model
26-
iris_knn = KNeighborsClassifier(..)
25+
=== "Python"
26+
```python
27+
# Define a model
28+
iris_knn = KNeighborsClassifier(..)
2729

28-
iris_knn.fit(..)
29-
30-
```
30+
iris_knn.fit(..)
31+
```
3132

3233
### Step 3: Export to local path
3334

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

36-
```python
37-
38-
model_file = "skl_knn.pkl"
39-
40-
joblib.dump(iris_knn, model_file)
37+
=== "Python"
38+
```python
39+
model_file = "skl_knn.pkl"
4140

42-
```
41+
joblib.dump(iris_knn, model_file)
42+
```
4343

4444
### Step 4: Register model in registry
4545

4646
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.
4747

48-
```python
49-
50-
# Model evaluation metrics
51-
metrics = {'accuracy': 0.92}
52-
53-
skl_model = mr.sklearn.create_model("skl_model", metrics=metrics)
48+
=== "Python"
49+
```python
50+
# Model evaluation metrics
51+
metrics = {'accuracy': 0.92}
5452

55-
skl_model.save(model_file)
53+
skl_model = mr.sklearn.create_model("skl_model", metrics=metrics)
5654

57-
```
55+
skl_model.save(model_file)
56+
```
5857

5958
## Going Further
6059

docs/user_guides/mlops/registry/frameworks/tf.md

+31-32
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,59 @@ In this guide you will learn how to export a TensorFlow model and register it in
1212

1313
### Step 1: Connect to Hopsworks
1414

15-
```python
16-
import hopsworks
15+
=== "Python"
16+
```python
17+
import hopsworks
1718

18-
project = hopsworks.login()
19+
project = hopsworks.login()
1920

20-
# get Hopsworks Model Registry handle
21-
mr = project.get_model_registry()
22-
```
21+
# get Hopsworks Model Registry handle
22+
mr = project.get_model_registry()
23+
```
2324

2425
### Step 2: Train
2526

2627
Define your TensorFlow model and run the training loop.
2728

28-
```python
29-
# Define a model
30-
model = tf.keras.Sequential()
29+
=== "Python"
30+
```python
31+
# Define a model
32+
model = tf.keras.Sequential()
3133

32-
# Add layers
33-
model.add(..)
34+
# Add layers
35+
model.add(..)
3436

35-
# Compile the model.
36-
model.compile(..)
37-
38-
# Train the model
39-
model.fit(..)
40-
41-
```
37+
# Compile the model.
38+
model.compile(..)
39+
40+
# Train the model
41+
model.fit(..)
42+
```
4243

4344
### Step 3: Export to local path
4445

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

47-
```python
48-
49-
model_dir = "./model"
50-
51-
tf.saved_model.save(model, model_dir)
48+
=== "Python"
49+
```python
50+
model_dir = "./model"
5251

53-
```
52+
tf.saved_model.save(model, model_dir)
53+
```
5454

5555
### Step 4: Register model in registry
5656

5757
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.
5858

59-
```python
60-
61-
# Model evaluation metrics
62-
metrics = {'accuracy': 0.92}
63-
64-
tf_model = mr.tensorflow.create_model("tf_model", metrics=metrics)
59+
=== "Python"
60+
```python
61+
# Model evaluation metrics
62+
metrics = {'accuracy': 0.92}
6563

66-
tf_model.save(model_dir)
64+
tf_model = mr.tensorflow.create_model("tf_model", metrics=metrics)
6765

68-
```
66+
tf_model.save(model_dir)
67+
```
6968

7069
## Going Further
7170

docs/user_guides/mlops/registry/index.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Model Registry Guides
22

3-
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.
3+
**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.
44

55
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.
66

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

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

16+
* [LLM](frameworks/llm.md)
17+
1618
* [Other frameworks](frameworks/python.md)
1719

1820

docs/user_guides/mlops/registry/input_example.md

+18-17
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,34 @@ In this guide you will learn how to attach an input example to a model. An input
1212

1313
### Step 1: Connect to Hopsworks
1414

15-
```python
16-
import hopsworks
15+
=== "Python"
16+
```python
17+
import hopsworks
1718

18-
project = hopsworks.login()
19+
project = hopsworks.login()
1920

20-
# get Hopsworks Model Registry handle
21-
mr = project.get_model_registry()
22-
```
21+
# get Hopsworks Model Registry handle
22+
mr = project.get_model_registry()
23+
```
2324

2425
### Step 2: Generate an input example
2526

2627
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.
2728

28-
```python
29-
import numpy as np
29+
=== "Python"
30+
```python
31+
import numpy as np
3032

31-
input_example = np.random.randint(0, high=256, size=784, dtype=np.uint8)
32-
33-
```
33+
input_example = np.random.randint(0, high=256, size=784, dtype=np.uint8)
34+
```
3435

3536
### Step 3: Set input_example parameter
3637

3738
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.
38-
```python
39-
40-
model = mr.tensorflow.create_model(name="mnist",
41-
input_example=input_example)
42-
model.save("./model")
4339

44-
```
40+
=== "Python"
41+
```python
42+
model = mr.tensorflow.create_model(name="mnist",
43+
input_example=input_example)
44+
model.save("./model")
45+
```

0 commit comments

Comments
 (0)