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
@@ -36,61 +35,100 @@ As a quick example, we'll package a [text classification pipeline](https://huggi
36
35
37
36
To get started, create a Truss with the following terminal command:
38
37
39
-
```
38
+
```sh
40
39
truss init text-classification
41
40
```
42
41
43
-
This will create an empty Truss at `./text-classification`.
42
+
When prompted, give your Truss a name like `Text classification`.
43
+
44
+
Then, navigate to the newly created directory:
45
+
46
+
```sh
47
+
cd text-classification
48
+
```
44
49
45
50
### Implement the model
46
51
47
-
The model serving code goes in `./text-classification/model/model.py` in your newly created Truss.
52
+
One of the two essential files in a Truss is `model/model.py`. In this file, you write a `Model` class: an interface between the ML model that you're packaging and the model server that you're running it on.
53
+
54
+
There are two member functions that you must implement in the `Model` class:
55
+
56
+
*`load()` loads the model onto the model server. It runs exactly once when the model server is spun up or patched.
57
+
*`predict()` handles model inference. It runs every time the model server is called.
58
+
59
+
Here's the complete `model/model.py` for the text classification model:
48
60
49
61
```python
50
-
from typing import List
51
62
from transformers import pipeline
52
63
53
64
54
65
classModel:
55
-
def__init__(self, **kwargs) -> None:
66
+
def__init__(self, **kwargs):
56
67
self._model =None
57
68
58
69
defload(self):
59
70
self._model = pipeline("text-classification")
60
71
61
-
defpredict(self, model_input: str) -> List:
72
+
defpredict(self, model_input):
62
73
returnself._model(model_input)
63
74
```
64
75
65
-
There are two functions to implement:
66
-
67
-
*`load()` runs once when the model is spun up and is responsible for initializing `self._model`
68
-
*`predict()` runs each time the model is invoked and handles the inference. It can use any JSON-serializable type as input and output.
69
-
70
76
### Add model dependencies
71
77
72
-
The pipeline model relies on Transformers and PyTorch. These dependencies must be specified in the Truss config.
78
+
The other essential file in a Truss is `config.yaml`, which configures the model serving environment. For a complete list of the config options, see [the config reference](https://truss.baseten.co/reference/config).
73
79
74
-
In `./text-classification/config.yaml`, find the line `requirements`. Replace the empty list with:
80
+
The pipeline model relies on [Transformers](https://huggingface.co/docs/transformers/index) and [PyTorch](https://pytorch.org/). These dependencies must be specified in the Truss config.
81
+
82
+
In `config.yaml`, find the line `requirements`. Replace the empty list with:
75
83
76
84
```yaml
77
85
requirements:
78
86
- torch==2.0.1
79
87
- transformers==4.30.0
80
88
```
81
89
82
-
No other configuration needs to be changed.
90
+
No other configuration is needed.
83
91
84
92
## Deployment
85
93
86
-
You can deploy a Truss to your [Baseten](https://baseten.co) account with:
94
+
Truss is maintained by [Baseten](https://baseten.co), which provides infrastructure for running ML models in production. We'll use Baseten as the remote host for your model.
87
95
88
-
```
89
-
cd ./text-classification
96
+
Other remotes are coming soon, starting with AWS SageMaker.
97
+
98
+
### Get an API key
99
+
100
+
To set up the Baseten remote, you'll need a [Baseten API key](https://app.baseten.co/settings/account/api_keys). If you don't have a Baseten account, no worries, just [sign up for an account](https://app.baseten.co/signup/) and you'll be issued plenty of free credits to get you started.
101
+
102
+
### Run `truss push`
103
+
104
+
With your Baseten API key ready to paste when prompted, you can deploy your model:
105
+
106
+
```sh
90
107
truss push
91
108
```
92
109
93
-
Truss will support other remotes soon, starting with AWS SageMaker.
110
+
You can monitor your model deployment from [your model dashboard on Baseten](https://app.baseten.co/models/).
111
+
112
+
### Invoke the model
113
+
114
+
After the model has finished deploying, you can invoke it from the terminal.
0 commit comments