Skip to content

Commit 39d3453

Browse files
peterschmidt85Andrey Cheptsov
andauthored
Improve AMD accelerator example (#3901)
* Improve AMD accelerator example * Polish AMD cluster placement note * Polish AMD training note * Clarify AMD distributed training note * Clarify AMD PD disaggregation placement * Polish AMD cluster validation wording * Add AMD cluster placement anchor * Polish AMD Docker image note * Show AMD cluster placement in navigation * Polish AMD cluster placement links --------- Co-authored-by: Andrey Cheptsov <andrey.cheptsov@github.com>
1 parent d38ae9b commit 39d3453

3 files changed

Lines changed: 143 additions & 145 deletions

File tree

Lines changed: 143 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
11
---
22
title: AMD
3-
description: Deploying and fine-tuning models on AMD MI300X GPUs using SGLang, vLLM, TRL, and Axolotl
3+
description: Running dev environments, tasks, and services on AMD GPUs
44
---
55

66
# AMD
77

8-
`dstack` supports running dev environments, tasks, and services on AMD GPUs.
9-
You can do that by setting up an [SSH fleet](../../concepts/fleets.md#ssh-fleets)
10-
with on-prem AMD GPUs or configuring a backend that offers AMD GPUs such as the `runpod` backend.
8+
`dstack` natively supports AMD GPUs. This page covers the basics of setting up
9+
fleets, running inference, training, and dev environments on AMD GPUs.
1110

12-
## Deployment
11+
## Fleets
1312

14-
Here are examples of a [service](../../concepts/services.md) that deploy
13+
`dstack` supports native cloud provisioning, and can also work with existing
14+
Kubernetes clusters or vanilla bare-metal hosts.
15+
16+
=== "Clouds"
17+
18+
`dstack` supports native provisioning of VMs with AMD GPUs across a number
19+
of clouds, including
20+
[AMD Developer Cloud](../../concepts/backends.md#amd-developer-cloud) and
21+
[Hot Aisle](../../concepts/backends.md#hot-aisle). More cloud support is
22+
coming soon.
23+
24+
To provision compute in these clouds, configure the corresponding
25+
[backend](../../concepts/backends.md) and create a
26+
[backend fleet](../../concepts/fleets.md).
27+
28+
=== "Kubernetes"
29+
30+
To use `dstack` with existing Kubernetes cluster(s), configure the
31+
[`kubernetes` backend](../../concepts/backends.md#kubernetes) and point it
32+
to your kubeconfig file. Then create a
33+
[backend fleet](../../concepts/fleets.md).
34+
35+
=== "SSH fleets"
36+
37+
If you'd like `dstack` to use a cluster or machine that is already
38+
provisioned and that you have access to, create an
39+
[SSH fleet](../../concepts/fleets.md).
40+
41+
!!! info "Cluster placement"
42+
For multi-node workloads, the fleet must
43+
[set](../../concepts/fleets.md#cluster-placement) `placement` to `cluster`.
44+
For Kubernetes and SSH fleets, the network must be properly configured.
45+
46+
To test whether the cluster is properly configured, run the
47+
[RCCL tests via a distributed task](../clusters/nccl-rccl-tests.md).
48+
49+
Once a fleet is created, you can run dev environments, tasks, and services.
50+
51+
## Inference
52+
53+
Here are examples of a [service](../../concepts/services.md) that deploys
1554
`Qwen/Qwen3.6-27B` on AMD MI300X GPUs using
1655
[SGLang](https://github.com/sgl-project/sglang) and
1756
[vLLM](https://docs.vllm.ai/en/latest/).
@@ -22,7 +61,7 @@ Here are examples of a [service](../../concepts/services.md) that deploy
2261

2362
```yaml
2463
type: service
25-
name: qwen36-service-sglang-amd
64+
name: qwen36-sglang-amd
2665

2766
image: lmsysorg/sglang:v0.5.10-rocm720-mi30x
2867

@@ -50,18 +89,26 @@ Here are examples of a [service](../../concepts/services.md) that deploy
5089
memory: 896GB..
5190
shm_size: 16GB
5291
disk: 450GB..
53-
gpu: MI300X:4
92+
gpu: MI300X:4..
5493
```
5594

5695
</div>
5796

97+
!!! info "PD disaggregation"
98+
To run SGLang with prefill and decode workers on an interconnected
99+
cluster of AMD GPU instances, see the
100+
[SGLang PD disaggregation](../inference/sglang.md#pd-disaggregation)
101+
example.
102+
103+
For multi-node PD disaggregation, the fleet must use [cluster placement](../../concepts/fleets.md#cluster-placement).
104+
58105
=== "vLLM"
59106

60107
<div editor-title="service.dstack.yml">
61108

62109
```yaml
63110
type: service
64-
name: qwen36-service-vllm-amd
111+
name: qwen36-vllm-amd
65112

66113
image: vllm/vllm-openai-rocm:v0.19.1
67114

@@ -87,164 +134,123 @@ Here are examples of a [service](../../concepts/services.md) that deploy
87134
memory: 896GB..
88135
shm_size: 16GB
89136
disk: 450GB..
90-
gpu: MI300X:4
137+
gpu: MI300X:4..
91138
```
92139

93140
</div>
94141

95-
!!! info "Docker image"
96-
AMD workloads require specifying an image with ROCm-compatible userspace and
97-
framework packages. The SGLang and vLLM examples above use pinned ROCm
98-
images.
142+
Use the [`dstack apply`](../../reference/cli/dstack/apply.md) command to apply
143+
any configuration, including services, tasks, dev environments, and fleets.
144+
145+
<div class="termy">
99146

100-
If you already have a ROCm-compatible image, use it. Otherwise, choose an
101-
image for the framework you use from
102-
[ROCm Docker images](https://hub.docker.com/u/rocm), e.g. `rocm/sgl-dev`
103-
for SGLang, `rocm/vllm` for vLLM, or `rocm/pytorch` for PyTorch. For
104-
generic AMD dev environments or tasks, use `rocm/dev-ubuntu-24.04`.
147+
```shell
148+
$ dstack apply -f service.dstack.yml
149+
```
105150

106-
To request multiple GPUs, specify the quantity after the GPU name, separated by a colon, e.g., `MI300X:4`.
151+
</div>
107152

108-
## Fine-tuning
153+
## Training
154+
155+
Below is a [task](../../concepts/tasks.md) that fine-tunes a small language
156+
model using the official
157+
[Transformers causal language modeling example](https://github.com/huggingface/transformers/tree/main/examples/pytorch/language-modeling)
158+
on AMD GPUs.
159+
160+
<div editor-title="train.dstack.yml">
161+
162+
```yaml
163+
type: task
164+
name: amd-qwen3-train
165+
166+
image: rocm/pytorch:latest
167+
168+
commands:
169+
- git clone --depth 1 https://github.com/huggingface/transformers.git
170+
- pip install -e ./transformers -r transformers/examples/pytorch/language-modeling/requirements.txt
171+
- |
172+
torchrun --standalone --nproc-per-node $DSTACK_GPUS_PER_NODE \
173+
transformers/examples/pytorch/language-modeling/run_clm.py \
174+
--model_name_or_path Qwen/Qwen3-0.6B-Base \
175+
--dataset_name Salesforce/wikitext \
176+
--dataset_config_name wikitext-2-raw-v1 \
177+
--do_train \
178+
--per_device_train_batch_size 1 \
179+
--gradient_accumulation_steps 8 \
180+
--max_steps 10 \
181+
--block_size 512 \
182+
--learning_rate 2e-5 \
183+
--bf16 \
184+
--logging_steps 1 \
185+
--output_dir /tmp/qwen3-clm
186+
187+
resources:
188+
gpu: MI300X:4..
189+
disk: 100GB..
190+
```
109191
110-
> If you're planning multi-node AMD training, validate cluster networking first
111-
with the [NCCL/RCCL tests](../clusters/nccl-rccl-tests.md)
112-
example.
192+
</div>
113193
114-
=== "TRL"
194+
!!! info "Distributed tasks"
195+
To run training across multiple nodes, use
196+
[distributed tasks](../../concepts/tasks.md#distributed-tasks). Distributed
197+
tasks may run on a cluster; in that case, the fleet must use
198+
[cluster placement](../../concepts/fleets.md#cluster-placement).
115199
116-
Below is an example of LoRA fine-tuning Llama 3.1 8B using [TRL](https://rocm.docs.amd.com/en/latest/how-to/llm-fine-tuning-optimization/single-gpu-fine-tuning-and-inference.html)
117-
and the [`mlabonne/guanaco-llama2-1k`](https://huggingface.co/datasets/mlabonne/guanaco-llama2-1k)
118-
dataset.
200+
## Dev environments
119201
120-
<div editor-title="train.dstack.yml">
202+
Here's an example of a [dev environment](../../concepts/dev-environments.md)
203+
that can be accessed via your desktop IDE.
121204
122-
```yaml
123-
type: task
124-
name: trl-amd-llama31-train
125-
126-
# Using Runpod's ROCm Docker image
127-
image: runpod/pytorch:2.1.2-py3.10-rocm6.1-ubuntu22.04
128-
129-
# Required environment variables
130-
env:
131-
- HF_TOKEN
132-
# Mount files
133-
files:
134-
- train.py
135-
# Commands of the task
136-
commands:
137-
- export PATH=/opt/conda/envs/py_3.10/bin:$PATH
138-
- git clone https://github.com/ROCm/bitsandbytes
139-
- cd bitsandbytes
140-
- git checkout rocm_enabled
141-
- pip install -r requirements-dev.txt
142-
- cmake -DBNB_ROCM_ARCH="gfx942" -DCOMPUTE_BACKEND=hip -S .
143-
- make
144-
- pip install .
145-
- pip install trl
146-
- pip install peft
147-
- pip install transformers datasets huggingface-hub scipy
148-
- cd ..
149-
- python train.py
150-
151-
# Uncomment to leverage spot instances
152-
#spot_policy: auto
205+
<div editor-title=".dstack.yml">
153206
154-
resources:
155-
gpu: MI300X
156-
disk: 150GB
157-
```
207+
```yaml
208+
type: dev-environment
209+
name: amd-vscode
158210

159-
</div>
211+
image: rocm/dev-ubuntu-24.04
160212

161-
=== "Axolotl"
162-
Below is an example of fine-tuning Llama 3.1 8B using [Axolotl](https://rocm.blogs.amd.com/artificial-intelligence/axolotl/README.html)
163-
and the [tatsu-lab/alpaca](https://huggingface.co/datasets/tatsu-lab/alpaca)
164-
dataset.
213+
ide: vscode
165214

166-
<div editor-title="train.dstack.yml">
215+
resources:
216+
gpu: MI300X:1
217+
```
167218
168-
```yaml
169-
type: task
170-
# The name is optional, if not specified, generated randomly
171-
name: axolotl-amd-llama31-train
172-
173-
# Using Runpod's ROCm Docker image
174-
image: runpod/pytorch:2.1.2-py3.10-rocm6.0.2-ubuntu22.04
175-
# Required environment variables
176-
env:
177-
- HF_TOKEN
178-
- WANDB_API_KEY
179-
- WANDB_PROJECT
180-
- WANDB_NAME=axolotl-amd-llama31-train
181-
- HUB_MODEL_ID
182-
# Commands of the task
183-
commands:
184-
- export PATH=/opt/conda/envs/py_3.10/bin:$PATH
185-
- pip uninstall torch torchvision torchaudio -y
186-
- python3 -m pip install --pre torch==2.3.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.0/
187-
- git clone https://github.com/OpenAccess-AI-Collective/axolotl
188-
- cd axolotl
189-
- git checkout d4f6c65
190-
- pip install -e .
191-
# Latest pynvml is not compatible with axolotl commit d4f6c65, so we need to fall back to version 11.5.3
192-
- pip uninstall pynvml -y
193-
- pip install pynvml==11.5.3
194-
- cd ..
195-
- wget https://dstack-binaries.s3.amazonaws.com/flash_attn-2.0.4-cp310-cp310-linux_x86_64.whl
196-
- pip install flash_attn-2.0.4-cp310-cp310-linux_x86_64.whl
197-
- wget https://dstack-binaries.s3.amazonaws.com/xformers-0.0.26-cp310-cp310-linux_x86_64.whl
198-
- pip install xformers-0.0.26-cp310-cp310-linux_x86_64.whl
199-
- git clone --recurse https://github.com/ROCm/bitsandbytes
200-
- cd bitsandbytes
201-
- git checkout rocm_enabled
202-
- pip install -r requirements-dev.txt
203-
- cmake -DBNB_ROCM_ARCH="gfx942" -DCOMPUTE_BACKEND=hip -S .
204-
- make
205-
- pip install .
206-
- cd ..
207-
- accelerate launch -m axolotl.cli.train -- axolotl/examples/llama-3/fft-8b.yaml
208-
--wandb-project "$WANDB_PROJECT"
209-
--wandb-name "$WANDB_NAME"
210-
--hub-model-id "$HUB_MODEL_ID"
219+
</div>
211220
212-
resources:
213-
gpu: MI300X
214-
disk: 150GB
215-
```
216-
</div>
221+
## Docker image
217222
218-
Note, to support ROCm, we need to checkout to commit `d4f6c65`. This commit eliminates the need to manually modify the Axolotl source code to make xformers compatible with ROCm, as described in the [xformers workaround](https://docs.axolotl.ai/docs/amd_hpc.html#apply-xformers-workaround). This installation approach is also followed for building Axolotl ROCm docker image. [(See Dockerfile)](https://github.com/ROCm/rocm-blogs/blob/release/blogs/artificial-intelligence/axolotl/src/Dockerfile.rocm).
223+
> If you'd like a run to use AMD GPUs, make sure to specify `image`.
219224

220-
> To speed up installation of `flash-attention` and `xformers`, we use pre-built binaries uploaded to S3.
225+
The image's ROCm runtime must be compatible with the AMD GPUs the run will use.
226+
The image should also include the packages your workload needs.
221227

222-
## Running a configuration
228+
## Metrics
223229

224-
Once a configuration is ready, save it to a `.dstack.yml` file. If your
225-
configuration references environment variables such as `HF_TOKEN` or
226-
`WANDB_API_KEY`, export them first. Then run
227-
`dstack apply -f <configuration file>`, and `dstack` will automatically
228-
provision the cloud resources and run the configuration.
230+
Run and job [metrics](../../concepts/metrics.md) include CPU, memory, and GPU
231+
usage. They are available in the UI and via the CLI:
229232

230233
<div class="termy">
231234

232235
```shell
233-
$ dstack apply -f <configuration file>
236+
$ dstack metrics &lt;run name&gt;
234237
```
235238

236239
</div>
237240

241+
> AMD GPU metrics require `amd-smi` to be available in the run image. If it
242+
> isn't present, GPU metrics may be unavailable.
243+
238244
## What's next?
239245

240246
1. Browse the dedicated [SGLang](../inference/sglang.md)
241-
and [vLLM](../inference/vllm.md) examples, plus
242-
[Axolotl](https://github.com/ROCm/rocm-blogs/tree/release/blogs/artificial-intelligence/axolotl),
243-
[TRL](https://rocm.docs.amd.com/en/latest/how-to/llm-fine-tuning-optimization/fine-tuning-and-inference.html),
244-
and [ROCm Bitsandbytes](https://github.com/ROCm/bitsandbytes)
245-
2. For multi-node training, run
246-
[NCCL/RCCL tests](../clusters/nccl-rccl-tests.md)
247-
to validate AMD cluster networking.
248-
3. Check [dev environments](../../concepts/dev-environments.md),
249-
[tasks](../../concepts/tasks.md), and
250-
[services](../../concepts/services.md).
247+
and [vLLM](../inference/vllm.md) examples, plus the
248+
[Qwen 3.6](../models/qwen36.md) model page.
249+
2. For multi-node inference, see
250+
[SGLang PD disaggregation](../inference/sglang.md#pd-disaggregation).
251+
3. For cluster validation, run
252+
[NCCL/RCCL tests](../clusters/nccl-rccl-tests.md).
253+
4. Check [dev environments](../../concepts/dev-environments.md),
254+
[tasks](../../concepts/tasks.md), [services](../../concepts/services.md),
255+
[fleets](../../concepts/fleets.md), and
256+
[backends](../../concepts/backends.md).

mkdocs/docs/examples/training/axolotl.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ resources:
5454
5555
The task uses Axolotl's Docker image, where Axolotl is already pre-installed.
5656
57-
!!! info "AMD"
58-
The example above uses NVIDIA accelerators. To use it with AMD, check out [AMD](../accelerators/amd.md#axolotl).
59-
6057
### Run the configuration
6158
6259
Once the configuration is ready, run `dstack apply -f <configuration file>`, and `dstack` will automatically provision the
@@ -182,4 +179,3 @@ Provisioning...
182179
1. Check [dev environments](../../concepts/dev-environments.md), [tasks](../../concepts/tasks.md),
183180
[services](../../concepts/services.md), and [fleets](../../concepts/fleets.md)
184181
2. Read about [cluster placement](../../concepts/fleets.md#cluster-placement)
185-
3. See the [AMD](../accelerators/amd.md#axolotl) example

mkdocs/docs/examples/training/trl.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ resources:
7575
7676
Change the `resources` property to specify more GPUs.
7777

78-
!!! info "AMD"
79-
The example above uses NVIDIA accelerators. To use it with AMD, check out [AMD](../accelerators/amd.md#trl).
80-
8178
??? info "DeepSpeed"
8279
For more memory-efficient use of multiple GPUs, consider using DeepSpeed and ZeRO Stage 3.
8380

@@ -269,4 +266,3 @@ Provisioning...
269266
1. Check [dev environments](../../concepts/dev-environments.md), [tasks](../../concepts/tasks.md),
270267
[services](../../concepts/services.md), and [fleets](../../concepts/fleets.md)
271268
2. Read about [cluster placement](../../concepts/fleets.md#cluster-placement)
272-
3. See the [AMD](../accelerators/amd.md#trl) example

0 commit comments

Comments
 (0)