|
51 | 51 | }, |
52 | 52 | { |
53 | 53 | "cell_type": "code", |
54 | | - "execution_count": 4, |
| 54 | + "execution_count": null, |
55 | 55 | "id": "8dd6a36f-ee95-453d-a127-c8a7de6a026d", |
56 | 56 | "metadata": { |
57 | 57 | "tags": [] |
58 | 58 | }, |
59 | | - "outputs": [ |
60 | | - { |
61 | | - "name": "stdout", |
62 | | - "output_type": "stream", |
63 | | - "text": [ |
64 | | - "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", |
65 | | - "\u001b[0m\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", |
66 | | - "\u001b[0m" |
67 | | - ] |
68 | | - } |
69 | | - ], |
| 59 | + "outputs": [], |
70 | 60 | "source": [ |
71 | 61 | "!pip install -Uq pip\n", |
72 | 62 | "!pip install -Uq sagemaker boto3 huggingface_hub " |
73 | 63 | ] |
74 | 64 | }, |
75 | 65 | { |
76 | 66 | "cell_type": "code", |
77 | | - "execution_count": 5, |
| 67 | + "execution_count": null, |
78 | 68 | "id": "cf0c89f4-679c-4557-b95d-1d954c15a020", |
79 | 69 | "metadata": { |
80 | 70 | "tags": [] |
|
93 | 83 | }, |
94 | 84 | { |
95 | 85 | "cell_type": "code", |
96 | | - "execution_count": 6, |
| 86 | + "execution_count": null, |
97 | 87 | "id": "83d5a162-e9be-469b-910e-18cca8c359f8", |
98 | 88 | "metadata": { |
99 | 89 | "tags": [] |
100 | 90 | }, |
101 | | - "outputs": [ |
102 | | - { |
103 | | - "name": "stdout", |
104 | | - "output_type": "stream", |
105 | | - "text": [ |
106 | | - "sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml\n", |
107 | | - "sagemaker.config INFO - Not applying SDK defaults from location: /root/.config/sagemaker/config.yaml\n", |
108 | | - "sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml\n", |
109 | | - "sagemaker.config INFO - Not applying SDK defaults from location: /root/.config/sagemaker/config.yaml\n" |
110 | | - ] |
111 | | - } |
112 | | - ], |
| 91 | + "outputs": [], |
113 | 92 | "source": [ |
114 | 93 | "role = sagemaker.get_execution_role() # execution role for the endpoint\n", |
115 | 94 | "sess = sagemaker.session.Session() # sagemaker session for interacting with different AWS APIs\n", |
|
118 | 97 | }, |
119 | 98 | { |
120 | 99 | "cell_type": "code", |
121 | | - "execution_count": 7, |
| 100 | + "execution_count": null, |
122 | 101 | "id": "f68b5181-d018-4564-9762-fa8770a9672f", |
123 | 102 | "metadata": { |
124 | 103 | "tags": [] |
|
159 | 138 | }, |
160 | 139 | { |
161 | 140 | "cell_type": "code", |
162 | | - "execution_count": 8, |
| 141 | + "execution_count": null, |
163 | 142 | "id": "94af859c-4c3a-4fda-ae27-890be565a906", |
164 | 143 | "metadata": { |
165 | 144 | "tags": [] |
166 | 145 | }, |
167 | | - "outputs": [ |
168 | | - { |
169 | | - "data": { |
170 | | - "application/vnd.jupyter.widget-view+json": { |
171 | | - "model_id": "45357719d0564c0b85a87e104ef9c0e1", |
172 | | - "version_major": 2, |
173 | | - "version_minor": 0 |
174 | | - }, |
175 | | - "text/plain": [ |
176 | | - "Fetching 39 files: 0%| | 0/39 [00:00<?, ?it/s]" |
177 | | - ] |
178 | | - }, |
179 | | - "metadata": {}, |
180 | | - "output_type": "display_data" |
181 | | - }, |
182 | | - { |
183 | | - "name": "stdout", |
184 | | - "output_type": "stream", |
185 | | - "text": [ |
186 | | - "CPU times: user 151 ms, sys: 10.9 ms, total: 162 ms\n", |
187 | | - "Wall time: 546 ms\n" |
188 | | - ] |
189 | | - } |
190 | | - ], |
| 146 | + "outputs": [], |
191 | 147 | "source": [ |
192 | 148 | "%%time\n", |
193 | 149 | "from huggingface_hub import snapshot_download\n", |
|
278 | 234 | "Here is a list of settings that we use in this configuration file -\n", |
279 | 235 | "\n", |
280 | 236 | "- `engine`: The runtime engine for DJL to use. The possible values for engine include *Python*, *DeepSpeed*, *FasterTransformer*, and *MPI*. In this case, we set it to MPI. MPI, Model Parallelization and Inference facilitates partitioning the model across all the available GPUs and thus accelerate the inference.\n", |
281 | | - "- `option.tensor_parallel_degree` - This option specifies number of tensor parallel partitions performed on the model.\n", |
| 237 | + "- `option.tensor_parallel_degree` - This option specifies number of tensor parallel partitions performed on the model. Set to the number of GPU devices over which Accelerate needs to partition the model. This parameter also controls the no of workers per model which will be started up when DJL serving runs. For example if we have a 4 GPU machine and we are creating 4 partitions then we will have 1 worker per model to serve the requests.\n", |
| 238 | + "- `option.low_cpu_mem_usage` - Reduces CPU memory usage when loading models. We recommend that you set this to TRUE.\n", |
282 | 239 | "- `option.rolling_batch` – Enables iteration-level batching using one of the supported strategies. Values include `auto`, `scheduler`, and `lmi-dist`. We use `lmi-dist` for turning on continuous batching for Llama 2.\n", |
283 | 240 | "- `option.max_rolling_batch_size` – Limits the number of concurrent requests in the continuous batch. Defaults to 32.\n", |
284 | 241 | "- `option.model_id`: The model id of a pretrained model hosted inside a [model repository on huggingface](https://huggingface.co/models) or S3 path to the model artefact. \n", |
285 | | - "- `option.tensor_parallel_degree`: Set to the number of GPU devices over which Accelerate needs to partition the model. This parameter also controls the no of workers per model which will be started up when DJL serving runs. For example if we have a 4 GPU machine and we are creating 4 partitions then we will have 1 worker per model to serve the requests.\n", |
286 | | - "- `option.enable_streaming`: As we need a response streaming for inferencing have reduced perceived latency, we will set it to *true*\n", |
| 242 | + "- `option.paged_attention` - Use PagedAttention or not. Default is always use. Disable this if you plan to run on G4 or older GPU architecture\n", |
| 243 | + "\n", |
| 244 | + "For more details on the configuration options and an exhaustive list, you can refer the documentation -\n", |
287 | 245 | "\n", |
288 | | - "For more details on the configuration options and an exhaustive list, you can refer the documentation - https://docs.aws.amazon.com/sagemaker/latest/dg/realtime-endpoints-large-model-configuration.html.\n", |
| 246 | + "[Model parallelism and large model inference](https://docs.aws.amazon.com/sagemaker/latest/dg/large-model-inference-configuration.html)\n", |
289 | 247 | "\n", |
290 | | - "Since we are serving the model using deepspeed container, and Llama 2 being a large model used for inference, we are following the approach of [Large model inference with DeepSpeed and DJL Serving](https://docs.aws.amazon.com/sagemaker/latest/dg/large-model-inference-tutorials-deepspeed-djl.html)" |
| 248 | + "Since we are serving the model using deepspeed container, and Llama 2 being a large model used for inference, we are following the approach of [Large model inference with DeepSpeed and DJL Serving](https://docs.aws.amazon.com/sagemaker/latest/dg/large-model-inference-tutorials-deepspeed-djl.html)\n" |
291 | 249 | ] |
292 | 250 | }, |
293 | 251 | { |
|
304 | 262 | "model_id = base_model_s3_uri" |
305 | 263 | ] |
306 | 264 | }, |
307 | | - { |
308 | | - "cell_type": "markdown", |
309 | | - "id": "3bc7098f-9739-4504-a98f-553936b4f5ab", |
310 | | - "metadata": {}, |
311 | | - "source": [ |
312 | | - "We will also set *enable_streaming* to *true* for obtaining response stream when we inference Llama 2. Since we are deploying llama 2 70B chat, we are setting the **tensor_parallel_degree** to **8** and making use of all the 8 NVIDIA A10G Tensor core GPUs available on the [`ml.g5.48xlarge`](https://aws.amazon.com/sagemaker/pricing/#:~:text=Amazon%20SageMaker%20G5%20instance%20product%20details) instance." |
313 | | - ] |
314 | | - }, |
315 | 265 | { |
316 | 266 | "cell_type": "code", |
317 | 267 | "execution_count": null, |
|
325 | 275 | "engine = MPI\n", |
326 | 276 | "option.entryPoint=djl_python.huggingface\n", |
327 | 277 | "option.tensor_parallel_degree=8\n", |
328 | | - "option.rolling_batch_type=LmiDistRollingBatch\n", |
329 | 278 | "option.rolling_batch=lmi-dist\n", |
330 | 279 | "option.max_rolling_batch_size=64\n", |
| 280 | + "option.model_loading_timeout=900\n", |
331 | 281 | "option.max_rolling_batch_prefill_tokens=16384\n", |
332 | | - "option.model_loading_timeout=120\n", |
333 | 282 | "option.model_id={{model_id}}\n", |
334 | | - "option.paged_attention=true\n", |
335 | | - "option.enable_streaming=true" |
| 283 | + "option.paged_attention=true" |
| 284 | + ] |
| 285 | + }, |
| 286 | + { |
| 287 | + "cell_type": "markdown", |
| 288 | + "id": "3bc7098f-9739-4504-a98f-553936b4f5ab", |
| 289 | + "metadata": {}, |
| 290 | + "source": [ |
| 291 | + "If you are using djl-deepspeed container version 0.25.0, you don't need to set the serving parameter `option.enable_streaming` to true, as the streaming is enabled by default. If you are using version 0.24.0, you will need to set `option.enable_streaming` to `true` for obtaining response stream while inferencing. Since we are deploying llama 2 70B chat, we are setting the **tensor_parallel_degree** to **8** and making use of all the 8 NVIDIA A10G Tensor core GPUs available on the [`ml.g5.48xlarge`](https://aws.amazon.com/sagemaker/pricing/#:~:text=Amazon%20SageMaker%20G5%20instance%20product%20details) instance." |
336 | 292 | ] |
337 | 293 | }, |
338 | 294 | { |
|
370 | 326 | "outputs": [], |
371 | 327 | "source": [ |
372 | 328 | "inference_image_uri = image_uris.retrieve(\n", |
373 | | - " framework=\"djl-deepspeed\", region=region, version=\"0.24.0\"\n", |
| 329 | + " framework=\"djl-deepspeed\", region=region, version=\"0.25.0\"\n", |
374 | 330 | ")\n", |
375 | 331 | "inference_image_uri" |
376 | 332 | ] |
|
634 | 590 | "\n", |
635 | 591 | "- [Improve throughput performance of Llama 2 models using Amazon SageMaker](https://aws.amazon.com/blogs/machine-learning/improve-throughput-performance-of-llama-2-models-using-amazon-sagemaker/)\n", |
636 | 592 | "- [Improve performance of Falcon models with Amazon SageMaker](https://aws.amazon.com/blogs/machine-learning/improve-performance-of-falcon-models-with-amazon-sagemaker/)\n", |
637 | | - "- [serving.properties - Configurations and settings](https://docs.aws.amazon.com/sagemaker/latest/dg/large-model-inference-configuration.html)" |
| 593 | + "- [serving.properties - Configurations and settings](https://docs.aws.amazon.com/sagemaker/latest/dg/large-model-inference-configuration.html)\n", |
| 594 | + "- [Amazon SageMaker launches a new version of Large Model Inference DLC with TensorRT-LLM support](https://aws.amazon.com/about-aws/whats-new/2023/11/amazon-sagemaker-large-model-inference-dlc-tensorrt-llm-support/)" |
638 | 595 | ] |
639 | 596 | }, |
640 | 597 | { |
|
0 commit comments