-
Notifications
You must be signed in to change notification settings - Fork 29
[HWORKS-1885] Improve vLLM-related docs #444
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+81 KB
docs/assets/images/guides/mlops/serving/deployment_simple_form_vllm_conf_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.