Skip to content

Commit d174485

Browse files
committed
conform EXAONE MoE slurm conversion example to public roundtrip launcher
Signed-off-by: sangHa0411 <sangha110495@gmail.com>
1 parent 5f6f4c3 commit d174485

3 files changed

Lines changed: 64 additions & 89 deletions

File tree

examples/models/exaone/exaone_moe/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,24 @@ The Slurm scripts warm the shared `uv` cache once before all distributed ranks e
8282

8383
## Slurm Checkpoint Conversion
8484

85-
[slurm_conversion.sh](slurm_conversion.sh) runs round-trip conversion across 16 GPUs on 2 nodes with default `TP=1, PP=1, EP=16`.
85+
[slurm_conversion.sh](slurm_conversion.sh) uses `convert.sh roundtrip` to submit a fixed `TP=1, PP=1, EP=16` config and verify HF ↔ Megatron round-trip conversion across 16 GPUs on 2 nodes. Run the wrapper from a Slurm login node; it submits one job and waits for it by default.
86+
87+
Set the container and account, then launch:
8688

8789
```bash
88-
mkdir -p logs
89-
sbatch examples/models/exaone/exaone_moe/slurm_conversion.sh
90+
export CONTAINER_IMAGE=/path/to/container.sqsh
91+
export SLURM_ACCOUNT=<your-account>
92+
export SLURM_PARTITION=batch
93+
# Optional: export CONTAINER_MOUNTS, HF_TOKEN, HF_HOME, and UV_CACHE_DIR before launching.
94+
bash examples/models/exaone/exaone_moe/slurm_conversion.sh
9095
```
9196

92-
Before submitting, edit the `#SBATCH --account` and `#SBATCH --partition` lines for your cluster, or override them according to your scheduler policy.
97+
The current checkout is mounted automatically at `/opt/Megatron-Bridge` and must be on storage visible from the compute nodes. Forward any cluster-specific `srun` options your scheduler requires, for example:
98+
99+
```bash
100+
bash examples/models/exaone/exaone_moe/slurm_conversion.sh \
101+
--srun-arg=--mpi=pmix
102+
```
93103

94104
## Script Configuration
95105

@@ -107,4 +117,4 @@ Before submitting, edit the `#SBATCH --account` and `#SBATCH --partition` lines
107117

108118
## Validation
109119

110-
Focused EXAONE conversion coverage lives in `tests/functional_tests/test_groups/models/exaone/test_exaone_conversion.py`.
120+
Focused EXAONE conversion coverage lives in `tests/functional_tests/test_groups/models/exaone/test_exaone_conversion.py`.

examples/models/exaone/exaone_moe/slurm_conversion.sh

Lines changed: 39 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -13,98 +13,53 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# ==============================================================================
17-
# K-EXAONE-236B-A23B Conversion Round-Trip Verification (Slurm)
16+
# K-EXAONE-236B-A23B round-trip verification on 2 Slurm nodes (16 GPUs).
17+
# Run this wrapper from a Slurm login node; convert.sh submits one job and
18+
# waits for it by default.
1819
#
19-
# K-EXAONE is a BF16 MoE model with 128 routed experts and 8 active experts.
20-
# The default TP=1, PP=1, EP=16 configuration uses 16 GPUs across 2 nodes.
21-
#
22-
# Usage:
23-
# 1. Set CONTAINER_IMAGE and, if needed, CONTAINER_MOUNTS.
24-
# 2. Export HF_TOKEN, HF_HOME, and UV_CACHE_DIR on shared storage.
25-
# 3. Create the log directory and submit:
26-
# mkdir -p logs
27-
# sbatch examples/models/exaone/exaone_moe/slurm_conversion.sh
28-
# ==============================================================================
29-
30-
#SBATCH --job-name=k-exaone-roundtrip
31-
#SBATCH --nodes=2
32-
#SBATCH --ntasks-per-node=8
33-
#SBATCH --gpus-per-node=8
34-
#SBATCH --time=4:00:00
35-
#SBATCH --account=<your-account>
36-
#SBATCH --partition=batch
37-
#SBATCH --output=logs/k_exaone_roundtrip_%j.log
38-
#SBATCH --exclusive
20+
# Required:
21+
# export CONTAINER_IMAGE=/path/to/container.sqsh
22+
# export SLURM_ACCOUNT=<your-account>
23+
# Optional:
24+
# export CONTAINER_MOUNTS=/shared:/shared,/host/path:/container/path
25+
# bash "$0" --srun-arg=--mpi=pmix
3926

4027
set -euo pipefail
4128

42-
# -- Container ---------------------------------------------------------------
43-
CONTAINER_IMAGE="${CONTAINER_IMAGE:-}"
44-
CONTAINER_MOUNTS="${CONTAINER_MOUNTS:-}"
45-
WORKDIR="${WORKDIR:-/opt/Megatron-Bridge}"
29+
: "${CONTAINER_IMAGE:?Set CONTAINER_IMAGE to the Megatron-Bridge container}"
30+
: "${SLURM_ACCOUNT:?Set SLURM_ACCOUNT to your Slurm account}"
4631

47-
# -- Model / Parallelism -----------------------------------------------------
48-
HF_MODEL_ID="${HF_MODEL_ID:-LGAI-EXAONE/K-EXAONE-236B-A23B}"
49-
TP="${TP:-1}"
50-
PP="${PP:-1}"
51-
EP="${EP:-16}"
52-
ETP="${ETP:-1}"
32+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
33+
REPO_ROOT="$(git -C "${SCRIPT_DIR}" rev-parse --show-toplevel)"
34+
CONVERT_SH="${CONVERT_SH:-${REPO_ROOT}/scripts/conversion/convert.sh}"
5335

54-
# -- Environment -------------------------------------------------------------
55-
# Keep HF_HOME and UV_CACHE_DIR on storage shared by all nodes.
56-
# export HF_TOKEN="..."
57-
# export HF_HOME="/path/to/shared/HF_HOME"
58-
# export UV_CACHE_DIR="/path/to/shared/uv_cache"
5936
export TORCH_NCCL_AVOID_RECORD_STREAMS=1
6037
export NCCL_NVLS_ENABLE=0
61-
export NCCL_DEBUG="${NCCL_DEBUG:-WARN}"
62-
export PYTORCH_CUDA_ALLOC_CONF="${PYTORCH_CUDA_ALLOC_CONF:-expandable_segments:True}"
63-
64-
if [[ -z "$CONTAINER_IMAGE" ]]; then
65-
echo "ERROR: Set CONTAINER_IMAGE to the Enroot .sqsh image path."
66-
exit 1
67-
fi
68-
69-
WORLD_SIZE="${SLURM_NTASKS:?SLURM_NTASKS is not set}"
70-
MODEL_PARALLEL_SIZE=$((TP * PP * EP))
71-
if [[ "$MODEL_PARALLEL_SIZE" -ne "$WORLD_SIZE" ]]; then
72-
echo "ERROR: TP*PP*EP=$MODEL_PARALLEL_SIZE must equal allocated tasks=$WORLD_SIZE."
73-
exit 1
74-
fi
75-
if ((128 % EP != 0)); then
76-
echo "ERROR: EP=$EP must divide K-EXAONE's 128 routed experts."
77-
exit 1
78-
fi
79-
80-
SRUN_ARGS=(--mpi=pmix --container-image="$CONTAINER_IMAGE" --no-container-mount-home)
81-
if [[ -n "$CONTAINER_MOUNTS" ]]; then
82-
SRUN_ARGS+=(--container-mounts="$CONTAINER_MOUNTS")
83-
fi
84-
85-
echo "======================================"
86-
echo "K-EXAONE Round-Trip Conversion"
87-
echo "Job: $SLURM_JOB_ID | Nodes: $SLURM_JOB_NUM_NODES | Tasks: $WORLD_SIZE"
88-
echo "Model: $HF_MODEL_ID"
89-
echo "TP=$TP PP=$PP EP=$EP ETP=$ETP"
90-
echo "======================================"
9138

92-
# Warm the shared uv cache once before all ranks enter distributed setup.
93-
srun --nodes=1 --ntasks=1 "${SRUN_ARGS[@]}" \
94-
bash -c 'cd "$1" && uv sync' bash "$WORKDIR"
39+
MOUNT_ARGS=(--mount "${REPO_ROOT}:/opt/Megatron-Bridge")
40+
IFS=',' read -r -a EXTRA_MOUNTS <<< "${CONTAINER_MOUNTS:-}"
41+
for mount in "${EXTRA_MOUNTS[@]}"; do
42+
if [[ -n "${mount}" ]]; then
43+
MOUNT_ARGS+=(--mount "${mount}")
44+
fi
45+
done
9546

96-
srun "${SRUN_ARGS[@]}" \
97-
bash -c '
98-
cd "$1"
99-
uv run --no-sync python examples/conversion/hf_megatron_roundtrip_multi_gpu.py \
100-
--hf-model-id "$2" \
101-
--tp "$3" \
102-
--pp "$4" \
103-
--ep "$5" \
104-
--etp "$6" \
105-
--trust-remote-code
106-
' bash "$WORKDIR" "$HF_MODEL_ID" "$TP" "$PP" "$EP" "$ETP"
47+
ENV_ARGS=()
48+
for name in HF_TOKEN HF_HOME UV_CACHE_DIR TORCH_NCCL_AVOID_RECORD_STREAMS NCCL_NVLS_ENABLE; do
49+
if [[ -n "${!name:-}" ]]; then
50+
ENV_ARGS+=(--env "${name}")
51+
fi
52+
done
10753

108-
echo "======================================"
109-
echo "Round-trip conversion completed"
110-
echo "======================================"
54+
"${CONVERT_SH}" roundtrip \
55+
--executor slurm --device gpu \
56+
--nodes 2 --gpus-per-node 8 \
57+
--account "${SLURM_ACCOUNT}" --partition "${SLURM_PARTITION:-batch}" --time 04:00:00 \
58+
--container-image "${CONTAINER_IMAGE}" \
59+
"${MOUNT_ARGS[@]}" \
60+
"${ENV_ARGS[@]}" \
61+
--experiment-name k-exaone-moe-roundtrip \
62+
--hf-model LGAI-EXAONE/K-EXAONE-236B-A23B \
63+
--tp 1 --pp 1 --ep 16 --etp 1 \
64+
--trust-remote-code \
65+
"$@"

tests/unit_tests/conversion/launcher/test_slurm_examples.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
"trust_remote_code": True,
8585
},
8686
),
87+
(
88+
"examples/models/exaone/exaone_moe/slurm_conversion.sh",
89+
{
90+
"nodes": "2",
91+
"time": "04:00:00",
92+
"hf_model": "LGAI-EXAONE/K-EXAONE-236B-A23B",
93+
"config": ("1", "1", "16", "1"),
94+
"trust_remote_code": True,
95+
},
96+
),
8797
]
8898

8999

0 commit comments

Comments
 (0)