Skip to content

Commit a3afc9b

Browse files
naming and consistency (#174)
* naming and consistency * update sample tests and add backwards compatability tests * predict tests * partial docs update * pankaj review updates
1 parent 3a814c1 commit a3afc9b

34 files changed

+236
-116
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ rfc = RandomForestClassifier()
6868
rfc.fit(data_x, data_y)
6969

7070
# Create the Truss (serializing & packaging model)
71-
tr = truss.mk_truss(rfc, target_directory="iris_rfc_truss")
71+
tr = truss.create(rfc, target_directory="iris_rfc_truss")
7272

7373
# Serve a prediction from the model
74-
tr.server_predict({"inputs": [[0, 0, 0, 0]]})
74+
tr.predict({"inputs": [[0, 0, 0, 0]]})
7575
```
7676

7777
### Package your model
7878

79-
The `truss.mk_truss()` command can be used with any supported framework:
79+
The `truss.create()` command can be used with any supported framework:
8080

8181
* [Hugging Face](https://truss.baseten.co/create/huggingface)
8282
* [LightGBM](https://truss.baseten.co/create/lightgbm)

docs/create/huggingface.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ model = pipeline('fill-mask', model='bert-base-uncased')
2929

3030
### Create a Truss
3131

32-
Use the `mk_truss` command to package your model into a Truss.
32+
Use the `create` command to package your model into a Truss.
3333

3434
```python
35-
from truss import mk_truss
35+
from truss import create
3636

37-
tr = mk_truss(model, target_directory="huggingface_truss")
37+
tr = create(model, target_directory="huggingface_truss")
3838
```
3939

4040
Check the target directory to see your new Truss!

docs/create/lightgbm.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ model = lgb.train(params=params, train_set=train, valid_sets=test)
5151

5252
### Create a Truss
5353

54-
Use the `mk_truss` command to package your model into a Truss.
54+
Use the `create` command to package your model into a Truss.
5555

5656
```python
57-
from truss import mk_truss
57+
from truss import create
5858

59-
tr = mk_truss(model, target_directory="lightgbm_truss")
59+
tr = create(model, target_directory="lightgbm_truss")
6060
```
6161

6262
Check the target directory to see your new Truss!

docs/create/manual.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ To familiarize yourself with the structure of Truss, review the [structure refer
1616

1717
### Adding the model binary
1818

19-
First, you'll need to add a model binary to your new Truss. On supported frameworks, this is provided automatically by the `mk_truss` command. For a custom Truss, it can come from many sources, such as:
19+
First, you'll need to add a model binary to your new Truss. On supported frameworks, this is provided automatically by the `create` command. For a custom Truss, it can come from many sources, such as:
2020

2121
* Pickling your model
2222
* Serializing your model
@@ -46,7 +46,7 @@ Also, your model gets access to certain values, including the `config.yaml` file
4646

4747
## Example code
4848

49-
While XGBoost is a supported framework — you can make a Truss from an XGBoost model with `mk_truss` — we'll use the manual method here for demonstration.
49+
While XGBoost is a supported framework — you can make a Truss from an XGBoost model with `create` — we'll use the manual method here for demonstration.
5050

5151
If you haven't already, create a Truss by running:
5252

docs/create/mlflow.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ with mlflow.start_run():
3535

3636
### Create a Truss
3737

38-
Truss uses MLflow's [pyfunc](https://www.mlflow.org/docs/latest/python_api/mlflow.pyfunc.html) module in the packaging process. Once you have loaded the model, use the `mk_truss` command to package your model into a Truss.
38+
Truss uses MLflow's [pyfunc](https://www.mlflow.org/docs/latest/python_api/mlflow.pyfunc.html) module in the packaging process. Once you have loaded the model, use the `create` command to package your model into a Truss.
3939

4040
```python
4141
import os
4242
import truss
4343

4444
model = mlflow.pyfunc.load_model(MODEL_URI)
45-
tr = truss.mk_truss(model, target_directory="./mlflow_truss")
45+
tr = truss.create(model, target_directory="./mlflow_truss")
4646
```
4747

4848
Check the target directory to see your new Truss!
@@ -53,7 +53,7 @@ To get a prediction from the Truss, try running:
5353

5454
```python
5555
data = np.array([-4, 1, 0, 10, -2, 1]).reshape(-1, 1)
56-
predictions = tr.server_predict({"inputs": data})
56+
predictions = tr.predict({"inputs": data})
5757
print(predictions)
5858
```
5959

docs/create/pytorch.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ model, _ , _ = train_the_model()
143143

144144
### Create a Truss
145145

146-
Use the `mk_truss` command to package your model into a Truss.
146+
Use the `create` command to package your model into a Truss.
147147

148148
```python
149-
from truss import mk_truss
149+
from truss import create
150150

151-
tr = mk_truss(model, target_directory="pytorch_truss")
151+
tr = create(model, target_directory="pytorch_truss")
152152
```
153153

154154
Check the target directory to see your new Truss!
@@ -165,7 +165,7 @@ inputs = datasets.MNIST("../data", train=False, transform=transform)
165165
dataset = torch.utils.data.DataLoader(inputs, batch_size=1)
166166

167167
import numpy as np
168-
print(tr.server_predict({"inputs": np.array(next(iter(dataset))[0])}))
168+
print(tr.predict({"inputs": np.array(next(iter(dataset))[0])}))
169169
```
170170

171171
For information on running the Truss locally, see [local development](../develop/localhost.md).

docs/create/sklearn.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ model.fit(data_x, data_y)
3030

3131
### Create a Truss
3232

33-
Use the `mk_truss` command to package your model into a Truss.
33+
Use the `create` command to package your model into a Truss.
3434

3535
```python
36-
from truss import mk_truss
36+
from truss import create
3737

38-
tr = mk_truss(model, target_directory="sklearn_truss")
38+
tr = create(model, target_directory="sklearn_truss")
3939
```
4040

4141
Check the target directory to see your new Truss!

docs/create/tensorflow.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ model = tf.keras.applications.ResNet50V2(
3232

3333
### Create a Truss
3434

35-
Use the `mk_truss` command to package your model into a Truss.
35+
Use the `create` command to package your model into a Truss.
3636

3737
```python
38-
from truss import mk_truss
38+
from truss import create
3939

40-
tr = mk_truss(model, target_directory="tensorflow_truss")
40+
tr = create(model, target_directory="tensorflow_truss")
4141
```
4242

4343
Check the target directory to see your new Truss!
@@ -80,7 +80,7 @@ def postprocess(predictions, k=5):
8080
With these functions in place, you can invoke the model and pass it a URL, as in:
8181

8282
```python
83-
tr.server_predict({"inputs": "https://github.com/pytorch/hub/raw/master/images/dog.jpg"})
83+
tr.predict({"inputs": "https://github.com/pytorch/hub/raw/master/images/dog.jpg"})
8484
```
8585

8686
For information on running the Truss locally, see [local development](../develop/localhost.md).

docs/create/xgboost.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ model = xgb.train(params,
4646

4747
### Create a Truss
4848

49-
Use the `mk_truss` command to package your model into a Truss.
49+
Use the `create` command to package your model into a Truss.
5050

5151
```python
52-
from truss import mk_truss
52+
from truss import create
5353

54-
tr = mk_truss(model, target_directory="xgboost_truss")
54+
tr = create(model, target_directory="xgboost_truss")
5555
```
5656

5757
Check the target directory to see your new Truss!

docs/deploy/baseten.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pip install --upgrade baseten
1515

1616
{% hint style="info" %}
1717

18-
If your model is already in memory (you created it with `mk_truss`), you can skip loading it into memory from the directory.
18+
If your model is already in memory (you created it with `create`), you can skip loading it into memory from the directory.
1919

2020
{% endhint %}
2121

@@ -24,7 +24,7 @@ Before deploying your Truss, you may need to load it into memory in a Jupyter no
2424
```python
2525
import truss
2626

27-
my_truss = truss.from_directory("my_truss_lives_here")
27+
my_truss = truss.load("my_truss_lives_here")
2828
```
2929

3030
Once your Truss is in memory, simply run the following:

docs/develop/localhost.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ There are two ways to interface with a Truss locally. The first is via [the Pyth
2121
When interacting with your Truss via the Python client, the first thing is to make sure it is in-memory. If you just created the Truss, it'll be in memory already, but if not, you'll need to load it with the following command:
2222

2323
```python
24-
tr = truss.from_directory("path_to_my_truss")
24+
tr = truss.load("path_to_my_truss")
2525
```
2626

2727
From there, you can invoke the Truss to serve the model in your Python environment. Just run:
@@ -112,7 +112,7 @@ Unlike Docker image, this mechanism requires that you already have the right Pyt
112112
In the Python environment, get a prediction without Docker by running:
113113

114114
```python
115-
tr.server_predict({"inputs": [[0, 0, 0, 0]]})
115+
tr.predict({"inputs": [[0, 0, 0, 0]]})
116116
```
117117

118118
Or in the command line, run:

docs/e2e.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ If you want to follow this tutorial for a particular framework and don't have a
2222

2323
## Step 1: Create a Truss
2424

25-
Truss works across model frameworks, and the most common model frameworks are supported with the one-line `mk_truss` command. Click the framework you built your model in to see specific packaging instructions for that format.
25+
Truss works across model frameworks, and the most common model frameworks are supported with the one-line `create` command. Click the framework you built your model in to see specific packaging instructions for that format.
2626

2727
For the following formats, if you have an in-memory trained model object `model`, just call the following:
2828

2929
```python
30-
from truss import mk_truss
30+
from truss import create
3131

32-
mk_truss(model, target_directory="my_truss")
32+
create(model, target_directory="my_truss")
3333
```
3434

3535
Supported frameworks:

docs/notebooks/aws_example.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"outputs": [],
5050
"source": [
5151
"# Make scaffold \n",
52-
"scaffold = truss.mk_truss(rfc_model, target_directory='test_rfc_1')\n",
52+
"scaffold = truss.create(rfc_model, target_directory='test_rfc_1')\n",
5353
"# This will produce a folder `test_rfc_1/` relative to your current directory. \n",
5454
"# Now we'll use Truss to build a Docker image on our local system\n",
5555
"scaffold.build_docker_image()"

docs/notebooks/huggingface_example.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
},
4545
"outputs": [],
4646
"source": [
47-
"from truss import mk_truss\n",
47+
"from truss import create\n",
4848
"\n",
49-
"tr = mk_truss(model, target_directory=\"huggingface_truss\")"
49+
"tr = create(model, target_directory=\"huggingface_truss\")"
5050
]
5151
},
5252
{
@@ -58,7 +58,7 @@
5858
"outputs": [],
5959
"source": [
6060
"# Serve a prediction from the model\n",
61-
"tr.server_predict({\"inputs\": [\"Donatello is a teenage mutant [MASK] turtle\"]})"
61+
"tr.predict({\"inputs\": [\"Donatello is a teenage mutant [MASK] turtle\"]})"
6262
]
6363
}
6464
],

docs/notebooks/lightgbm_example.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
},
6969
"outputs": [],
7070
"source": [
71-
"from truss import mk_truss\n",
71+
"from truss import create\n",
7272
"\n",
73-
"tr = mk_truss(model, target_directory=\"lightgbm_truss\")"
73+
"tr = create(model, target_directory=\"lightgbm_truss\")"
7474
]
7575
},
7676
{
@@ -81,7 +81,7 @@
8181
},
8282
"outputs": [],
8383
"source": [
84-
"tr.server_predict({\"inputs\": [[0, 0, 0, 0, 0, 0]]})"
84+
"tr.predict({\"inputs\": [[0, 0, 0, 0, 0, 0]]})"
8585
]
8686
}
8787
],

docs/notebooks/mlflow_example.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"import truss\n",
8686
"\n",
8787
"model = mlflow.pyfunc.load_model(MODEL_URI)\n",
88-
"tr = truss.mk_truss(model, target_directory=\"./mlflow_truss\")"
88+
"tr = truss.create(model, target_directory=\"./mlflow_truss\")"
8989
]
9090
},
9191
{
@@ -99,7 +99,7 @@
9999
"# Invoke the MLflow model\n",
100100
"\n",
101101
"data = np.array([-4, 1, 0, 10, -2, 1]).reshape(-1, 1)\n",
102-
"predictions = tr.server_predict({\"inputs\": data})\n",
102+
"predictions = tr.predict({\"inputs\": data})\n",
103103
"print(predictions)"
104104
]
105105
}

docs/notebooks/sklearn_example.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"outputs": [],
6161
"source": [
6262
"# Create the Truss (serializing & packaging model)\n",
63-
"tr = truss.mk_truss(rfc, \"iris-rfc\")"
63+
"tr = truss.create(rfc, \"iris-rfc\")"
6464
]
6565
},
6666
{
@@ -72,7 +72,7 @@
7272
"outputs": [],
7373
"source": [
7474
"# Serve a prediction from the model\n",
75-
"tr.server_predict({\"inputs\": [[0, 0, 0, 0]]})"
75+
"tr.predict({\"inputs\": [[0, 0, 0, 0]]})"
7676
]
7777
}
7878
],

docs/notebooks/tensorflow_example.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
},
5050
"outputs": [],
5151
"source": [
52-
"from truss import mk_truss\n",
52+
"from truss import create\n",
5353
"\n",
5454
"# Create the Truss (serializing & packaging model)\n",
55-
"tr = mk_truss(model, target_directory=\"tensorflow_truss\")"
55+
"tr = create(model, target_directory=\"tensorflow_truss\")"
5656
]
5757
},
5858
{
@@ -102,7 +102,7 @@
102102
"outputs": [],
103103
"source": [
104104
"image = preprocess(\"https://github.com/pytorch/hub/raw/master/images/dog.jpg\")\n",
105-
"results = tr.server_predict({\"inputs\": image})\n",
105+
"results = tr.predict({\"inputs\": image})\n",
106106
"postprocess(results[\"predictions\"])"
107107
]
108108
}

docs/notebooks/xgboost_example.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
},
6464
"outputs": [],
6565
"source": [
66-
"from truss import mk_truss\n",
66+
"from truss import create\n",
6767
"\n",
68-
"tr = mk_truss(model, target_directory=\"xgboost_truss\")"
68+
"tr = create(model, target_directory=\"xgboost_truss\")"
6969
]
7070
},
7171
{
@@ -76,7 +76,7 @@
7676
},
7777
"outputs": [],
7878
"source": [
79-
"tr.server_predict({\"inputs\": [[0, 0, 0, 0, 0, 0]]})"
79+
"tr.predict({\"inputs\": [[0, 0, 0, 0, 0, 0]]})"
8080
]
8181
}
8282
],

docs/reference/cli.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ Invokes the packaged model, either locally or in a Docker container.
7979
* `target_directory`: A Truss directory. If none, use current directory.
8080
* `request`: String formatted as json that represents request
8181
* `build_dir`: Directory where context is built. If none, a temp directory is created.
82-
* `tag`: Docker build image tag
83-
* `port`: Local port used to run image
84-
* `run_local`: Flag to run prediction locally (instead of on Docker)
85-
* `request_file`: Path to json file containing the request
82+
* `tag`: Docker build image tag.
83+
* `port`: Local port used to run image.
84+
* `use_docker`: Flag to run prediction on Docker, defaults to `False`.
85+
* `request_file`: Path to json file containing the request.
8686

8787
### `run-example`
8888

0 commit comments

Comments
 (0)