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
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.
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.
Copy file name to clipboardexpand all lines: docs/user_guides/mlops/registry/frameworks/python.md
+27-28
Original file line number
Diff line number
Diff line change
@@ -8,55 +8,54 @@ In this guide you will learn how to export a generic Python model and register i
8
8
9
9
### Step 1: Connect to Hopsworks
10
10
11
-
```python
12
-
import hopsworks
11
+
=== "Python"
12
+
```python
13
+
import hopsworks
13
14
14
-
project = hopsworks.login()
15
+
project = hopsworks.login()
15
16
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
+
```
19
20
20
21
### Step 2: Train
21
22
22
23
Define your XGBoost model and run the training loop.
23
24
24
-
```python
25
-
# Define a model
26
-
model = XGBClassifier()
25
+
=== "Python"
26
+
```python
27
+
# Define a model
28
+
model = XGBClassifier()
27
29
28
-
# Train model
29
-
model.fit(X_train, y_train)
30
-
31
-
```
30
+
# Train model
31
+
model.fit(X_train, y_train)
32
+
```
32
33
33
34
### Step 3: Export to local path
34
35
35
36
Export the XGBoost model to a directory on the local filesystem.
36
37
37
-
```python
38
-
39
-
model_file ="model.json"
40
-
41
-
model.save_model(model_file)
38
+
=== "Python"
39
+
```python
40
+
model_file = "model.json"
42
41
43
-
```
42
+
model.save_model(model_file)
43
+
```
44
44
45
45
### Step 4: Register model in registry
46
46
47
47
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.
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.
61
+
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.
Copy file name to clipboardexpand all lines: docs/user_guides/mlops/registry/frameworks/skl.md
+26-27
Original file line number
Diff line number
Diff line change
@@ -8,54 +8,53 @@ In this guide you will learn how to export a Scikit-learn model and register it
8
8
9
9
### Step 1: Connect to Hopsworks
10
10
11
-
```python
12
-
import hopsworks
11
+
=== "Python"
12
+
```python
13
+
import hopsworks
13
14
14
-
project = hopsworks.login()
15
+
project = hopsworks.login()
15
16
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
+
```
19
20
20
21
### Step 2: Train
21
22
22
23
Define your Scikit-learn model and run the training loop.
23
24
24
-
```python
25
-
# Define a model
26
-
iris_knn = KNeighborsClassifier(..)
25
+
=== "Python"
26
+
```python
27
+
# Define a model
28
+
iris_knn = KNeighborsClassifier(..)
27
29
28
-
iris_knn.fit(..)
29
-
30
-
```
30
+
iris_knn.fit(..)
31
+
```
31
32
32
33
### Step 3: Export to local path
33
34
34
35
Export the Scikit-learn model to a directory on the local filesystem.
35
36
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"
41
40
42
-
```
41
+
joblib.dump(iris_knn, model_file)
42
+
```
43
43
44
44
### Step 4: Register model in registry
45
45
46
46
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.
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.
60
+
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.
Copy file name to clipboardexpand all lines: docs/user_guides/mlops/registry/frameworks/tf.md
+32-33
Original file line number
Diff line number
Diff line change
@@ -12,61 +12,60 @@ In this guide you will learn how to export a TensorFlow model and register it in
12
12
13
13
### Step 1: Connect to Hopsworks
14
14
15
-
```python
16
-
import hopsworks
15
+
=== "Python"
16
+
```python
17
+
import hopsworks
17
18
18
-
project = hopsworks.login()
19
+
project = hopsworks.login()
19
20
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
+
```
23
24
24
25
### Step 2: Train
25
26
26
27
Define your TensorFlow model and run the training loop.
27
28
28
-
```python
29
-
# Define a model
30
-
model = tf.keras.Sequential()
29
+
=== "Python"
30
+
```python
31
+
# Define a model
32
+
model = tf.keras.Sequential()
31
33
32
-
# Add layers
33
-
model.add(..)
34
+
# Add layers
35
+
model.add(..)
34
36
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
+
```
42
43
43
44
### Step 3: Export to local path
44
45
45
46
Export the TensorFlow model to a directory on the local filesystem.
46
47
47
-
```python
48
-
49
-
model_dir ="./model"
50
-
51
-
tf.saved_model.save(model, model_dir)
48
+
=== "Python"
49
+
```python
50
+
model_dir = "./model"
52
51
53
-
```
52
+
tf.saved_model.save(model, model_dir)
53
+
```
54
54
55
55
### Step 4: Register model in registry
56
56
57
57
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.
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.
71
+
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.
Copy file name to clipboardexpand all lines: docs/user_guides/mlops/registry/index.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Model Registry Guides
2
2
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.
4
4
5
5
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.
6
6
@@ -13,6 +13,8 @@ Follow these framework-specific guides to export a Model to the Model Registry.
Copy file name to clipboardexpand all lines: docs/user_guides/mlops/registry/input_example.md
+18-17
Original file line number
Diff line number
Diff line change
@@ -12,33 +12,34 @@ In this guide you will learn how to attach an input example to a model. An input
12
12
13
13
### Step 1: Connect to Hopsworks
14
14
15
-
```python
16
-
import hopsworks
15
+
=== "Python"
16
+
```python
17
+
import hopsworks
17
18
18
-
project = hopsworks.login()
19
+
project = hopsworks.login()
19
20
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
+
```
23
24
24
25
### Step 2: Generate an input example
25
26
26
27
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.
0 commit comments