Skip to content

Commit 198a8ce

Browse files
committed
add macros
Signed-off-by: sirutBuasai <sirutbuasai27@outlook.com>
1 parent b6832c5 commit 198a8ce

File tree

6 files changed

+189
-1
lines changed

6 files changed

+189
-1
lines changed

docs/.nav.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ nav:
22
- Home: index.md
33
- Getting Started:
44
- get_started/index.md
5+
- Using Deep Learning Containers: get_started/using_dlcs.md
56
- Tutorials: tutorials
67
- Reference:
78
- Available Images: reference/available_images.md

docs/get_started/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Where:
4646
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 763104351884.dkr.ecr.us-west-2.amazonaws.com
4747

4848
# Pull PyTorch training image
49-
docker pull 763104351884.dkr.ecr.us-west-2.amazonaws.com/pytorch-training:2.9.0-gpu-py312-cu130-ubuntu22.04-sagemaker
49+
docker pull 763104351884.dkr.ecr.us-west-2.amazonaws.com/{{ images.latest_pytorch_training_ec2 }}
5050
```
5151

5252
## Next Steps

docs/get_started/using_dlcs.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Using Deep Learning Containers
2+
3+
This guide covers how to run AWS Deep Learning Containers on AWS Platforms such as SageMaker and EC2.
4+
5+
## Running on SageMaker
6+
7+
### Using SageMaker Python SDK
8+
9+
Deploy a vLLM inference endpoint:
10+
11+
```python
12+
from sagemaker.model import Model
13+
14+
model = Model(
15+
image_uri="{{ images.latest_vllm_sagemaker }}",
16+
role="arn:aws:iam::<account_id>:role/<role_name>",
17+
env={
18+
"SM_VLLM_MODEL": "meta-llama/Llama-3.1-8B-Instruct",
19+
"HF_TOKEN": "<your_hf_token>",
20+
},
21+
)
22+
23+
predictor = model.deploy(
24+
instance_type="ml.g5.2xlarge",
25+
initial_instance_count=1,
26+
)
27+
```
28+
29+
Deploy an SGLang inference endpoint:
30+
31+
```python
32+
from sagemaker.model import Model
33+
34+
model = Model(
35+
image_uri="{{ images.latest_sglang_sagemaker }}",
36+
role="arn:aws:iam::<account_id>:role/<role_name>",
37+
env={
38+
"SM_SGLANG_MODEL_PATH": "meta-llama/Llama-3.1-8B-Instruct",
39+
"HF_TOKEN": "<your_hf_token>",
40+
},
41+
)
42+
43+
predictor = model.deploy(
44+
instance_type="ml.g5.2xlarge",
45+
initial_instance_count=1,
46+
)
47+
```
48+
49+
### Using Boto3
50+
51+
Deploy a vLLM inference endpoint:
52+
53+
```python
54+
import boto3
55+
56+
sagemaker = boto3.client("sagemaker")
57+
58+
sagemaker.create_model(
59+
ModelName="vllm-model",
60+
PrimaryContainer={
61+
"Image": "{{ images.latest_vllm_sagemaker }}",
62+
"Environment": {
63+
"SM_VLLM_MODEL": "meta-llama/Llama-3.1-8B-Instruct",
64+
"HF_TOKEN": "<your_hf_token>",
65+
},
66+
},
67+
ExecutionRoleArn="arn:aws:iam::<account_id>:role/<role_name>",
68+
)
69+
70+
sagemaker.create_endpoint_config(
71+
EndpointConfigName="vllm-endpoint-config",
72+
ProductionVariants=[
73+
{
74+
"VariantName": "default",
75+
"ModelName": "vllm-model",
76+
"InstanceType": "ml.g5.2xlarge",
77+
"InitialInstanceCount": 1,
78+
}
79+
],
80+
)
81+
82+
sagemaker.create_endpoint(
83+
EndpointName="vllm-endpoint",
84+
EndpointConfigName="vllm-endpoint-config",
85+
)
86+
```
87+
88+
Deploy an SGLang inference endpoint:
89+
90+
```python
91+
import boto3
92+
93+
sagemaker = boto3.client("sagemaker")
94+
95+
sagemaker.create_model(
96+
ModelName="sglang-model",
97+
PrimaryContainer={
98+
"Image": "{{ images.latest_sglang_sagemaker }}",
99+
"Environment": {
100+
"SM_SGLANG_MODEL_PATH": "meta-llama/Llama-3.1-8B-Instruct",
101+
"HF_TOKEN": "<your_hf_token>",
102+
},
103+
},
104+
ExecutionRoleArn="arn:aws:iam::<account_id>:role/<role_name>",
105+
)
106+
107+
sagemaker.create_endpoint_config(
108+
EndpointConfigName="sglang-endpoint-config",
109+
ProductionVariants=[
110+
{
111+
"VariantName": "default",
112+
"ModelName": "sglang-model",
113+
"InstanceType": "ml.g5.2xlarge",
114+
"InitialInstanceCount": 1,
115+
}
116+
],
117+
)
118+
119+
sagemaker.create_endpoint(
120+
EndpointName="sglang-endpoint",
121+
EndpointConfigName="sglang-endpoint-config",
122+
)
123+
```
124+
125+
## Running on EC2
126+
127+
After pulling a DLC image, run it with Docker:
128+
129+
```bash
130+
# Run interactively
131+
docker run -it --gpus all <account_id>.dkr.ecr.<region>.amazonaws.com/<repository>:<tag> bash
132+
133+
# Example: Run PyTorch container
134+
docker run -it --gpus all {{ images.latest_pytorch_training_ec2 }} bash
135+
```
136+
137+
Mount local directories to persist data:
138+
139+
```bash
140+
docker run -it --gpus all -v /local/data:/data <image_uri> bash
141+
```
142+
143+
For available image URIs, see [Available Images](../reference/available_images.md).

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mkdocs-autorefs
22
mkdocs-awesome-nav
3+
mkdocs-macros-plugin
34
mkdocs-material>=9.0

docs/src/macros.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Documentation global variables for mkdocs-macros-plugin."""
14+
15+
import os
16+
17+
from utils import load_yaml
18+
19+
SRC_DIR = os.path.dirname(os.path.abspath(__file__))
20+
DATA_FILE = os.path.join(SRC_DIR, "data", "images.yml")
21+
22+
23+
def get_latest_image(repo: str, platform: str) -> str:
24+
"""Get the latest image URI for a repository and platform."""
25+
data = load_yaml(DATA_FILE)
26+
tags = data.get("images", {}).get(repo, [])
27+
for tag in tags:
28+
if tag.endswith(platform):
29+
return f"763104351884.dkr.ecr.us-west-2.amazonaws.com/{repo}:{tag}"
30+
raise ValueError(
31+
f"Image not found for {repo} with platform {platform}. Docs must be fixed to use a valid image."
32+
)
33+
34+
35+
def define_env(env):
36+
"""Define variables for mkdocs-macros-plugin."""
37+
env.variables["images"] = {
38+
"latest_pytorch_training_ec2": get_latest_image("pytorch-training", "-ec2"),
39+
"latest_vllm_sagemaker": get_latest_image("vllm", "-sagemaker"),
40+
"latest_sglang_sagemaker": get_latest_image("sglang", "-sagemaker"),
41+
}

mkdocs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ plugins:
8080
- search # Built-in search
8181
- autorefs # Auto-link to other pages/headings
8282
- awesome-nav # .nav.yml file support
83+
- macros: # Variable substitution in markdown
84+
module_name: docs/src/macros
8385

8486
# === Custom Assets ===
8587
extra_css:

0 commit comments

Comments
 (0)