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
Copy file name to clipboardexpand all lines: examples/large_models/inferentia2/llama2/continuous_batching/Readme.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ This example can also be extended to support Mistral without code changes. Custo
15
15
| mistral | mistral.model.MistralForSampling |
16
16
17
17
18
-
The batch size in [model-config.yaml](model-config.yaml) indicates the maximum number of requests torchserve will aggregate and send to the custom handler within the batch delay. It is the batch size used for the Inf2 model compilation.
18
+
The `batchSize` in [model-config.yaml](model-config.yaml) indicates the maximum number of requests torchserve will aggregate and send to the custom handler within the batch delay. It is the batch size used for the Inf2 model compilation.
19
19
Since compilation batch size can influence compile time and also constrained by the Inf2 instance type, this is chosen to be a relatively smaller value, say 4.
20
20
21
21
`inf2-llama-2-continuous-batching.ipynb` is the notebook example.
Copy file name to clipboardexpand all lines: examples/large_models/inferentia2/llama2/continuous_batching/inf2-llama-2-continuous-batching.ipynb
+12-24
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
"cell_type": "markdown",
5
5
"source": [
6
6
"## TorchServe Continuous Batching Serve Llama-2-70B on Inferentia-2\n",
7
-
"This notebook demonstrates TorchServe continuous batching serving Llama-2-70b on Inferentia-2 `inf2.48xlarge` with DLAMI: Deep Learning AMI Neuron PyTorch 1.13 (Ubuntu 20.04) 20231226"
7
+
"This notebook demonstrates TorchServe continuous batching serving Llama-2-70b on Inferentia-2 `inf2.48xlarge` with Neuron DLAMI Deep Learning AMI Neuron (Ubuntu 22.04) 20240401 and Neuron DLC [public.ecr.aws/neuron/pytorch-inference-neuronx:2.1.2-neuronx-py310-sdk2.18.1-ubuntu20.04](https://github.com/aws-neuron/deep-learning-containers?tab=readme-ov-file#pytorch-inference-neuronx)"
8
8
],
9
9
"metadata": {
10
10
"collapsed": false
@@ -13,8 +13,7 @@
13
13
{
14
14
"cell_type": "markdown",
15
15
"source": [
16
-
"### Installation\n",
17
-
"Note: This section can be skipped once Neuron DLC 2.16 with TorchServe latest version is released."
"# Install torchserve and torch-model-archiver\n",
47
-
"python ts_scripts/install_from_src.py"
37
+
"!cd serve"
48
38
],
49
39
"metadata": {
50
40
"collapsed": false
@@ -53,10 +43,7 @@
53
43
{
54
44
"cell_type": "markdown",
55
45
"source": [
56
-
"### Create model artifacts\n",
57
-
"\n",
58
-
"Note: run `mv model/models--meta-llama--Llama-2-70b-hf/snapshots/90052941a64de02075ca800b09fcea1bdaacb939/model.safetensors.index.json model/models--meta-llama--Llama-2-70b-hf/snapshots/90052941a64de02075ca800b09fcea1bdaacb939/model.safetensors.index.json.bkp`\n",
# see https://awsdocs-neuron.readthedocs-hosted.com/en/latest/release-notes/torch/transformers-neuronx/index.html#known-issues-and-limitations for llama2-13b
Copy file name to clipboardexpand all lines: examples/large_models/inferentia2/llama2/streamer/Readme.md
+13-103
Original file line number
Diff line number
Diff line change
@@ -4,110 +4,20 @@ This document briefs on serving the [Llama 2](https://huggingface.co/meta-llama)
4
4
5
5
Inferentia2 uses [Neuron SDK](https://aws.amazon.com/machine-learning/neuron/) which is built on top of PyTorch XLA stack. For large model inference [`transformers-neuronx`](https://github.com/aws-neuron/transformers-neuronx) package is used that takes care of model partitioning and running inference.
6
6
7
-
**Note**: To run the model on an Inf2 instance, the model gets compiled as a preprocessing step. As part of the compilation process, to generate the model graph, a specific batch size is used. Following this, when running inference, we need to pass input which matches the batch size that was used during compilation. Model compilation and input padding to match compiled model batch size is taken care of by the [custom handler](inf2_handler.py) in this example.
7
+
This example can also be extended to support Mistral without code changes. Customers only set the following items in model-config.yaml. For example:
The batch size and micro batch size configurations are present in [model-config.yaml](model-config.yaml). The batch size indicates the maximum number of requests torchserve will aggregate and send to the custom handler within the batch delay.
10
-
The batch size is chosen to be a relatively large value, say 16 since micro batching enables running the preprocess(tokenization) and inference steps in parallel on the micro batches. The micro batch size is the batch size used for the Inf2 model compilation.
11
-
Since compilation batch size can influence compile time and also constrained by the Inf2 instance type, this is chosen to be a relatively smaller value, say 4.
12
-
13
-
This example also demonstrates the utilization of neuronx cache to store inf2 model compilation artifacts using the `NEURONX_CACHE` and `NEURONX_DUMP_TO` environment variables in the custom handler.
14
-
When the model is loaded for the first time, the model is compiled for the configured micro batch size and the compilation artifacts are saved to the neuronx cache.
15
-
On subsequent model load, the compilation artifacts in the neuronx cache serves as `Ahead of Time(AOT)` compilation artifacts and significantly reduces the model load time.
16
-
For convenience, the compiled model artifacts for this example are made available on the Torchserve model zoo: `s3://torchserve/mar_files/llama-2-13b-neuronx-b4`\
17
-
Instructions on how to use the AOT compiled model artifacts is shown below.
18
-
19
-
### Step 1: Inf2 instance
20
-
21
-
Get an Inf2 instance(Note: This example was tested on instance type:`inf2.24xlarge`), ssh to it, make sure to use the following DLAMI as it comes with PyTorch and necessary packages for AWS Neuron SDK pre-installed.
22
-
DLAMI Name: ` Deep Learning AMI Neuron PyTorch 1.13 (Ubuntu 20.04) 20230720 Amazon Machine Image (AMI)` or higher.
23
-
24
-
**Note**: The `inf2.24xlarge` instance consists of 6 neuron chips with 2 neuron cores each. The total accelerator memory is 192GB.
25
-
Based on the configuration used in [model-config.yaml](model-config.yaml), with `tp_degree` set to 6, 3 of the 6 neuron chips are used, i.e 6 neuron cores.
26
-
On loading the model, the accelerator memory consumed is 38.1GB (12.7GB per chip).
27
-
28
-
### Step 2: Package Installations
29
-
30
-
Follow the steps below to complete package installations
curl -X POST "http://localhost:8081/models?url=llama-2-13b"
101
-
```
102
-
103
-
### Step 8: Run inference
104
-
105
-
```bash
106
-
python test_stream_response.py
107
-
```
108
-
109
-
### Step 9: Stop torchserve
20
+
The `batchSize` in [model-config.yaml](model-config.yaml) indicates the maximum number of requests torchserve will aggregate and send to the custom handler within the batch delay. `micro_batch_size` is the batch size used for the Inf2 model compilation.
21
+
Since compilation batch size can influence compile time and also constrained by the Inf2 instance type, this is chosen to be a relatively smaller value, say 4.
110
22
111
-
```bash
112
-
torchserve --stop
113
-
```
23
+
`inf2-llama-2-micro-batching.ipynb` is the notebook example.
0 commit comments