Skip to content

Commit 8ce6f07

Browse files
author
Andrey Cheptsov
committed
[Docs] Minor Miles training example
1 parent 45379fc commit 8ce6f07

1 file changed

Lines changed: 44 additions & 33 deletions

File tree

‎mkdocs/docs/examples/training/miles.md‎

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
---
22
title: Miles
3-
description: RL-fine-tune Qwen2.5-32B with Miles, SGLang, Megatron-LM, and Ray across two 8xH100 nodes
3+
description: RL fine-tuning Qwen2.5-32B with Miles, SGLang, Megatron-LM, and Ray across two 8xH100 nodes
44
---
55

66
# Miles
77

88
This example shows how to use `dstack` and [Miles](https://github.com/radixark/miles)
9-
to RL-fine-tune a 32B language model with [GRPO](https://arxiv.org/abs/2402.03300) across two 8xH100 nodes. Under the hood Miles uses [SGLang](https://github.com/sgl-project/sglang) for high-throughput rollout, [Megatron-LM](https://github.com/NVIDIA/Megatron-LM) for training, and [Ray](https://docs.ray.io/en/latest/) to coordinate the trainer
10-
and rollout actors across nodes.
9+
to fine-tune a 32B language model with [GRPO](https://arxiv.org/abs/2402.03300)
10+
across a multi-node cluster.
11+
Miles uses [SGLang](https://github.com/sgl-project/sglang) for high-throughput
12+
rollouts, [Megatron-LM](https://github.com/NVIDIA/Megatron-LM) for training,
13+
and [Ray](https://docs.ray.io/en/latest/) to coordinate the trainer and rollout
14+
actors across nodes.
1115

12-
Here we fine-tune `Qwen/Qwen2.5-32B-Instruct` on [GSM8K](https://huggingface.co/datasets/openai/gsm8k) dataset.
16+
Here we fine-tune `Qwen/Qwen2.5-32B-Instruct` on the
17+
[GSM8K](https://huggingface.co/datasets/openai/gsm8k) dataset.
1318

1419
!!! info "Prerequisites"
15-
Before running a distributed task, make sure to create a fleet with `placement` set to `cluster` (can be a [managed fleet](../../concepts/fleets.md#cluster-placement) or an [SSH fleet](../../concepts/fleets.md#ssh-placement)).
20+
Before running a distributed task, make sure to create a [fleet](../../concepts/fleets.md)
21+
with `placement` set to [`cluster`](../../concepts/fleets.md#cluster-placement).
1622

1723
## Run a Ray cluster
1824

19-
The task below starts a Ray cluster across both nodes and performs the one-time setup on each node. The setup includes: downloading the model, downloading the dataset, and converting the checkpoint to Megatron's `torch_dist` format.
25+
### Define a configuration
26+
27+
The [task](../../concepts/tasks.md) below starts Ray on two nodes and prepares
28+
each node by downloading the model and dataset, then converting the checkpoint
29+
to Megatron's `torch_dist` format.
2030

2131
<div editor-title="miles-qwen32b-h100.dstack.yml">
2232

@@ -31,11 +41,11 @@ env:
3141
- NCCL_DEBUG=INFO
3242
- MODEL_ID=Qwen/Qwen2.5-32B-Instruct
3343
commands:
34-
# 1. Download Model + dataset
44+
# 1. Download the model and dataset.
3545
- pip install -U "huggingface_hub[cli]"
3646
- hf download "$MODEL_ID" --local-dir "/root/$(basename "$MODEL_ID")"
3747
- hf download --repo-type dataset openai/gsm8k --local-dir /root/gsm8k
38-
# 2. Convert HF -> Megatron torch_dist
48+
# 2. Convert the Hugging Face checkpoint to Megatron torch_dist.
3949
- |
4050
MODEL_NAME="$(basename "$MODEL_ID")"
4151
cd /root/miles && python tools/convert_hf_to_torch_dist.py \
@@ -56,7 +66,7 @@ commands:
5666
--untie-embeddings-and-output-weights \
5767
--hf-checkpoint "/root/$MODEL_NAME" \
5868
--save "/root/${MODEL_NAME}_torch_dist"
59-
# 3. Start the Ray cluster.
69+
# 3. Start Ray.
6070
- |
6171
if [ $DSTACK_NODE_RANK = 0 ]; then
6272
ray start --head --port=6379
@@ -76,7 +86,10 @@ volumes:
7686
7787
</div>
7888
79-
Now, if you run this task via `dstack apply`, it will automatically forward the Ray's dashboard port to `localhost:8265`.
89+
### Run the configuration
90+
91+
Run the task with [`dstack apply`](../../reference/cli/dstack/apply.md). By
92+
default, `dstack apply` forwards the Ray dashboard port to `localhost:8265`.
8093

8194
<div class="termy">
8295

@@ -87,11 +100,14 @@ $ dstack apply -f miles-qwen32b-h100.dstack.yml
87100

88101
</div>
89102

90-
As long as the `dstack apply` is attached, you can use `localhost:8265` to submit Ray jobs for execution. If `dstack apply` is detached, you can use `dstack attach` to re-attach.
103+
While `dstack apply` is attached, you can submit Ray jobs through
104+
`localhost:8265`. If you detach or run from another machine, use
105+
[`dstack attach`](../../reference/cli/dstack/attach.md) to re-attach and make
106+
the dashboard port accessible on `localhost`.
91107

92108
## Submit Ray jobs
93109

94-
Before you can submit Ray jobs, ensure `ray` is installed locally:
110+
Install `ray` locally before submitting jobs:
95111

96112
<div class="termy">
97113

@@ -102,7 +118,7 @@ $ pip install ray
102118
</div>
103119

104120
The submit script below runs the Miles training job on the Ray cluster. The
105-
model is sharded across all 8 GPUs per node via tensor parallelism, and SGLang
121+
model is sharded across all 8 GPUs per node with tensor parallelism, and SGLang
106122
uses the same 8 GPUs per node for rollout.
107123

108124
<div editor-title="submit-miles-train.sh">
@@ -115,7 +131,6 @@ export RAY_ADDRESS=http://localhost:8265
115131
116132
: "${NUM_NODES:?NUM_NODES is not set}"
117133
: "${GPUS_PER_NODE:?GPUS_PER_NODE is not set}"
118-
TOTAL_GPUS=$((NUM_NODES * GPUS_PER_NODE))
119134
120135
MODEL_ID="Qwen/Qwen2.5-32B-Instruct"
121136
MODEL_NAME="$(basename "$MODEL_ID")"
@@ -133,17 +148,6 @@ WANDB_GROUP="${MODEL_NAME}-gsm8k-${NUM_NODES}node-${GPUS_PER_NODE}gpu"
133148
WANDB_NAME="rollout-$(date +%Y%m%d-%H%M%S)"
134149
ROLLOUT_GPUS_PER_ENGINE=8
135150
136-
echo "===== submit-miles env ====="
137-
echo "NUM_NODES=${NUM_NODES}"
138-
echo "GPUS_PER_NODE=${GPUS_PER_NODE}"
139-
echo "TOTAL_GPUS=${TOTAL_GPUS}"
140-
echo "MODEL_ID=${MODEL_ID}"
141-
echo "HF_CHECKPOINT=${HF_CHECKPOINT}"
142-
echo "CHECKPOINT_DIR=${CHECKPOINT_DIR}"
143-
echo "============================"
144-
145-
146-
147151
CMD='cd /root/miles && python3 train.py \
148152
--actor-num-nodes '"$NUM_NODES"' \
149153
--actor-num-gpus-per-node '"$GPUS_PER_NODE"' \
@@ -246,7 +250,7 @@ ray job submit \
246250

247251
</div>
248252

249-
Then run it:
253+
Submit the job with the same cluster shape as the task:
250254

251255
<div class="termy">
252256

@@ -256,15 +260,22 @@ $ NUM_NODES=2 GPUS_PER_NODE=8 bash submit-miles-train.sh
256260

257261
</div>
258262

259-
!!! info "Important parameters"
263+
!!! info "Training parameters"
260264
1. `--tensor-model-parallel-size 8` shards the 32B model across all 8 GPUs
261265
per node.
262-
2. `--rollout-num-gpus-per-engine 8` starts SGLang engine with TP-8 on each node.
263-
3. `--sglang-server-concurrency` sets how many requests SGLang processes concurrently.
264-
4. `--max-tokens-per-gpu 9216` sets number of tokens each GPU processes. Lower this if Megatron OOM's during training.
265-
5. `--sglang-mem-fraction-static 0.7` sets fraction of GPU memory SGLang pre-allocates for its KV cache. Lower this if Megatron OOM's at startup.
266+
2. `--rollout-num-gpus-per-engine 8` starts SGLang with TP-8 on each node.
267+
3. `--sglang-server-concurrency` sets how many requests SGLang processes
268+
concurrently.
269+
4. `--max-tokens-per-gpu 9216` sets the per-GPU token budget. Lower this if
270+
Megatron OOMs during training.
271+
5. `--sglang-mem-fraction-static 0.7` sets the SGLang KV cache memory
272+
fraction. Lower this if Megatron OOMs at startup.
273+
274+
Using Ray via `dstack` gives you access to the Ray ecosystem while benefiting
275+
from `dstack`'s provisioning capabilities.
266276

267277
!!! info "What's next"
268278
1. Read about [distributed tasks](../../concepts/tasks.md#distributed-tasks)
269-
and [fleets](../../concepts/fleets.md) for larger-scale setups.
270-
2. Browse Miles' [examples](https://github.com/radixark/miles/tree/main/examples)
279+
and [fleets](../../concepts/fleets.md)
280+
2. See the [SGLang inference](../inference/sglang.md) example
281+
3. Browse Miles' [examples](https://github.com/radixark/miles/tree/main/examples)

0 commit comments

Comments
 (0)