Skip to content

Commit 35f6013

Browse files
sangstarwillgoldby
authored andcommitted
[Docs] Update Tensorizer usage documentation (vllm-project#21190)
Signed-off-by: Sanger Steel <sangersteel@gmail.com> Signed-off-by: William Goldby <willgoldby@gmail.com> Co-authored-by: William Goldby <willgoldby@gmail.com> Signed-off-by: x22x22 <wadeking@qq.com>
1 parent 54870f6 commit 35f6013

File tree

2 files changed

+110
-18
lines changed

2 files changed

+110
-18
lines changed

docs/models/extensions/tensorizer.md

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,98 @@ vLLM model tensors that have been serialized to disk, an HTTP/HTTPS endpoint, or
55
at runtime extremely quickly directly to the GPU, resulting in significantly
66
shorter Pod startup times and CPU memory usage. Tensor encryption is also supported.
77

8-
For more information on CoreWeave's Tensorizer, please refer to
9-
[CoreWeave's Tensorizer documentation](https://github.com/coreweave/tensorizer). For more information on serializing a vLLM model, as well a general usage guide to using Tensorizer with vLLM, see
10-
the [vLLM example script](../../examples/others/tensorize_vllm_model.md).
8+
vLLM fully integrates Tensorizer in to its model loading machinery. The following will give a brief overview on how to get started with using Tensorizer on vLLM.
119

12-
!!! note
13-
Note that to use this feature you will need to install `tensorizer` by running `pip install vllm[tensorizer]`.
10+
## Installing Tensorizer
11+
12+
To install `tensorizer`, run `pip install vllm[tensorizer]`.
13+
14+
## The basics
15+
16+
To load a model using Tensorizer, the model first needs to be serialized by
17+
Tensorizer. [The example script](../../examples/others/tensorize_vllm_model.md) takes care of this process.
18+
19+
Let's walk through a basic example by serializing `facebook/opt-125m` using the script, and then loading it for inference.
20+
21+
## Serializing a vLLM model with Tensorizer
22+
23+
To serialize a model with Tensorizer, call the example script with the necessary
24+
CLI arguments. The docstring for the script itself explains the CLI args
25+
and how to use it properly in great detail, and we'll use one of the examples from the docstring directly, assuming we want to serialize and save our model at our S3 bucket example `s3://my-bucket`:
26+
27+
```bash
28+
python examples/others/tensorize_vllm_model.py \
29+
--model facebook/opt-125m \
30+
serialize \
31+
--serialized-directory s3://my-bucket \
32+
--suffix v1
33+
```
34+
35+
This saves the model tensors at `s3://my-bucket/vllm/facebook/opt-125m/v1`. If you intend on applying a LoRA adapter to your tensorized model, you can pass the HF id of the LoRA adapter in the above command, and the artifacts will be saved there too:
36+
37+
```bash
38+
python examples/others/tensorize_vllm_model.py \
39+
--model facebook/opt-125m \
40+
--lora-path <lora_id> \
41+
serialize \
42+
--serialized-directory s3://my-bucket \
43+
--suffix v1
44+
```
45+
46+
## Serving the model using Tensorizer
47+
48+
Once the model is serialized where you want it, you can load the model using `vllm serve` or the `LLM` entrypoint. You can pass the directory where you saved the model to the `model` argument for `LLM()` and `vllm serve`. For example, to serve the tensorized model saved previously with the LoRA adapter, you'd do:
49+
50+
```bash
51+
vllm serve s3://my-bucket/vllm/facebook/opt-125m/v1 \
52+
--load-format tensorizer \
53+
--enable-lora
54+
```
55+
56+
Or, with `LLM()`:
57+
58+
```python
59+
from vllm import LLM
60+
llm = LLM(
61+
"s3://my-bucket/vllm/facebook/opt-125m/v1",
62+
load_format="tensorizer",
63+
enable_lora=True
64+
)
65+
```
66+
67+
## Options for configuring Tensorizer
68+
69+
`tensorizer`'s core objects that serialize and deserialize models are `TensorSerializer` and `TensorDeserializer` respectively. In order to pass arbitrary kwargs to these, which will configure the serialization and deserialization processes, you can provide them as keys to `model_loader_extra_config` with `serialization_kwargs` and `deserialization_kwargs` respectively. Full docstrings detailing all parameters for the aforementioned objects can be found in `tensorizer`'s [serialization.py](https://github.com/coreweave/tensorizer/blob/main/tensorizer/serialization.py) file.
70+
71+
As an example, CPU concurrency can be limited when serializing with `tensorizer` via the `limit_cpu_concurrency` parameter in the initializer for `TensorSerializer`. To set `limit_cpu_concurrency` to some arbitrary value, you would do so like this when serializing:
72+
73+
```bash
74+
python examples/others/tensorize_vllm_model.py \
75+
--model facebook/opt-125m \
76+
--lora-path <lora_id> \
77+
serialize \
78+
--serialized-directory s3://my-bucket \
79+
--serialization-kwargs '{"limit_cpu_concurrency": 2}' \
80+
--suffix v1
81+
```
82+
83+
As an example when customizing the loading process via `TensorDeserializer`, you could limit the number of concurrency readers during deserialization with the `num_readers` parameter in the initializer via `model_loader_extra_config` like so:
84+
85+
```bash
86+
vllm serve s3://my-bucket/vllm/facebook/opt-125m/v1 \
87+
--load-format tensorizer \
88+
--enable-lora \
89+
--model-loader-extra-config '{"deserialization_kwargs": {"num_readers": 2}}'
90+
```
91+
92+
Or with `LLM()`:
93+
94+
```python
95+
from vllm import LLM
96+
llm = LLM(
97+
"s3://my-bucket/vllm/facebook/opt-125m/v1",
98+
load_format="tensorizer",
99+
enable_lora=True,
100+
model_loader_extra_config={"deserialization_kwargs": {"num_readers": 2}}
101+
)
102+
```

examples/others/tensorize_vllm_model.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,22 @@
8484
Once a model is serialized, tensorizer can be invoked with the `LLM` class
8585
directly to load models:
8686
87-
llm = LLM(model="facebook/opt-125m",
88-
load_format="tensorizer",
89-
model_loader_extra_config=TensorizerConfig(
90-
tensorizer_uri = path_to_tensors,
91-
num_readers=3,
92-
)
93-
)
87+
```python
88+
from vllm import LLM
89+
llm = LLM(
90+
"s3://my-bucket/vllm/facebook/opt-125m/v1",
91+
load_format="tensorizer"
92+
)
93+
```
94+
9495
9596
A serialized model can be used during model loading for the vLLM OpenAI
96-
inference server. `model_loader_extra_config` is exposed as the CLI arg
97-
`--model-loader-extra-config`, and accepts a JSON string literal of the
98-
TensorizerConfig arguments desired.
97+
inference server:
98+
99+
```
100+
vllm serve s3://my-bucket/vllm/facebook/opt-125m/v1 \
101+
--load-format tensorizer
102+
```
99103
100104
In order to see all of the available arguments usable to configure
101105
loading with tensorizer that are given to `TensorizerConfig`, run:
@@ -116,10 +120,9 @@
116120
`--enable-lora`. For instance:
117121
118122
```
119-
vllm serve <model_path> \
123+
vllm serve s3://my-bucket/vllm/facebook/opt-125m/v1 \
120124
--load-format tensorizer \
121-
--model-loader-extra-config '{"tensorizer_uri": "<model_path>.tensors"}' \
122-
--enable-lora
125+
--enable-lora
123126
```
124127
"""
125128

0 commit comments

Comments
 (0)