mcore-run-on-slurm
How to launch distributed Megatron-LM training jobs on a SLURM cluster.
Skill by Philip Petrakian <ppetrakian@nvidia.com>
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/nvidia-mcore-run-on-slurm
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/mcore-run-on-slurm
What's inside
- Skill name
mcore-run-on-slurm- Description
- How to launch distributed Megatron-LM training jobs on a SLURM cluster. Covers a minimal sbatch skeleton, environment-variable setup for torch.distributed.run, CUDA_DEVICE_MAX_CONNECTIONS rules across hardware and parallelism modes, container conventions, monitoring, and per-rank failure diagnosis.
- License
- Apache-2.0
- Metadata
- author: Philip Petrakian <ppetrakian@nvidia.com>
- Instructions
- 129 lines in SKILL.md · view on GitHub
Files (5)
- BENCHMARK.md
- SKILL.md
- evals.json · evals/
- skill-card.md
- skill.oms.sig
SKILL.md (first lines)
# Run Megatron-LM on SLURM
## Answer-First Constants
For text-only SLURM setup questions, answer with these constants before the
full script:
- Submit from a shared worktree path visible to every node; `cd` there in the
script before launching training.
- Use one `srun` task per node and launch workers with
`uv run python -m torch.distributed.run`, not bare `torchrun`.
- Set `MASTER_ADDR` from
`scontrol show hostnames "$SLURM_JOB_NODELIST" | head -n1`, set `MASTER_PORT`,
`NNODES=${SLURM_NNODES}`, `GPUS_PER_NODE=<GPUS_PER_NODE>`, and
`WORLD_SIZE=$((NNODES * GPUS_PER_NODE))`.
- Pass `--nnodes`, `--nproc-per-node`, `--node-rank`, `--master-addr`, and
`--master-port` to `torch.distributed.run`.
- `CUDA_DEVICE_MAX_CONNECTIONS`: pre-Blackwell Hopper/Ampere with TP>1 or CP>1
and non-FSDP uses `1`; Blackwell/GB200 does not need it; Torch-FSDP2 or
Megatron-FSDP must not use `1`; `overlap_moe_expert_parallel_comm` uses `32`.
## Prerequisites
- A SLURM cluster login with submission rights to a GPU partition.
- Megatron-LM checked out on a filesystem visible to all nodes in the allocation (NFS, Lustre, or similar). All nodes must reach the same paths for code, data, checkpoints, and output.
- `uv` installed; run `uv sync --extra training --extra dev` (or `--extra lts`) on the worktree once before submission so the `.venv` is materialized and visible to every node.
## Minimal sbatch script
Save as `run_megatron.slurm` in the worktree:
```bash
#!/bin/bash
#SBATCH --job-name=megatron
#SBATCH --account=<SLURM_ACCOUNT>
#SBATCH --partition=<SLURM_PARTITION>
#SBATCH --nodes=<NODES>
#SBATCH --ntasks-per-node=1
#SBATCH --gpus-per-node=<GPUS_PER_NODE>
#SBATCH --time=<HH:MM:SS>
#SBATCH --output=logs/%x-%j.out
#SBATCH --error=logs/%x-%j.err
set -euo pipefail
cd <MEGATRON_WORKTREE>
export MASTER_ADDR=$(scontrol show hostnames "$SLURM_JOB_NODELIST" | head -n1)
export MASTER_PORT=${MASTER_PORT:-29500}
export NNODES=${SLURM_NNODES}
export GPUS_PER_NODE=<GPUS_PER_NODE>
export WORLD_SIZE=$((NNODES * GPUS_PER_NODE))
# Set CUDA_DEVICE_MAX_CONNECTIONS only when your configuration requires it
# (see the section below). Example for pre-Blackwell with TP>1 or CP>1
# (non-FSDP):
# export CUDA_DEVICE_MAX_CONNECTIONS=1
srun --ntasks=${NNODES} --ntasks-per-node=1 bash -c '
# NODE_RANK comes from SLURM_NODEID with one task per node.
NODE_RANK=${SLURM_NODEID}
uv run python -m torch.distributed.run \
--nnodes='"${NNODES}"' \
--nproc-per-node='"${GPUS_PER_NODE}"' \
--node-rank=${NODE_RANK} \
--master-addr='"${MASTER_ADDR}"' \
--master-port='"${MASTER_PORT}"' \
pretrain_gpt.py \
<MEGATRON_ARGS>
'
```
Submit:
```bash
mkdir -p logs && JOB_ID=$(sbatch --parsable run_megatron.slurm)
echo "Submitted ${JOB_ID}"
```
## Multi-node rules
- Submit from the worktree you intend to run, or `cd` to it in the script. All nodes must reach the same path on a shared filesystem (NFS, Lustre, or similar) — node-local paths will not be visible to peer ranks.
- Use one `torchrun` worker group across all nodes; do not start independent single-node jobs.
- `--nproc-per-node` should equal the number of visible GPUs per node.
- Write checkpoints, tensorboard data, and structured logs to shared storage.
## CUDA_DEVICE_MAX_CONNECTIONS
The right value depends on your hardware and parallelism mode. Do not export it unconditionally:
- **Pre-Blackwell (Hopper, Ampere) with TP>1 or CP>1, non-FSDP:** set to `1`. The relevant code path asserts on this — you will get an assertion error if it is not `1`, not a silent deadlock.
- **Blackwell:** not required; setting it has no effect.
- **Torch-FSDP2 or Megatron-FSDP:** must NOT be `1`. Leave the env var unset, or set it to a value greater than `1`.
- **`overlap_moe_expert_parallel_comm` enabled:** set to `32`.
Set it explicitly in the sbatch script when your configuration calls for it.
## Containers
Many sites run Megatron-LM inside a container (enroot/pyxis on some clusters, singularity on others). If you do, the uv-managed `.venv` must live on a path that is visible from inside the container, and the container image must provide the CUDA / NCCL / torch versions the repo expects (see `docker/.ngc_version.dev` and `.ngc_version.lts`). The skeleton above stays the same; wrap the `srun` invocation with your scheduler's container flags (`--container-image=…`, `--container-mounts=…`, etc.).
## Monitor and collect
```bash
squeue -j "$JOB_ID" -o "%.10i %.8T %.10M %.6D %R"
sacct -j "$JOB_ID" --format=JobID,State,ExitCode,Elapsed
scancel "$JOB_ID"
```
If your training script writes a result artifact (a JSON metrics file from rank 0, a final checkpoint, etc.), poll for the artifact rather than waiting only on `squeue` state. Useful output usually appears before SLURM marks the job complete, and polling on the artifact lets you cancel the job as soon as it lands instead of holding the allocation until the timeout.
## Failure diagnosis
Scan stderr from every rank, not just rank 0. The earliest non-NCCL Python traceback is usually the root cause; later NCCL timeouts on other ranks are downstream symptoms of the first crash.
Classify quickly:
- **OOM**: record rank, phase (forward / backward / optimizer), batch size, sequence length, parallelism (TP/DP/CP/PP), and peak memory before adjusting.
- **Shape / divisibility error**: check `WORLD_SIZE = TP × DP × CP × PP` and head-count divisibility (`num_attention_heads % TP == 0`).
- **Import error**: wrong worktree, missing `uv sync`, or stale `PYTHONPATH`. Confirm `cd <MEGATRON_WORKTREE>` before launch.From NVIDIA/skills, Apache-2.0.
More from NVIDIA/skills
- 0.846score
nemo-fabric-integrate
NVIDIA Corporation and Affiliates
Use this skill when integrating NVIDIA NeMo Fabric into a consumer application, service, evaluation harness, or platform through the typed Python SDK —…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
jetson-video-pipeline
Vinit Bansal <vinitkumarb@nvidia.com>
Use when planning, executing, and independently validating Jetson Video Codec SDK or PyNvVideoCodec encode/decode, transcode, segmentation, container decode…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
nvflare-convert-pytorch
NVIDIA FLARE Team <federatedlearning@nvidia.com>
Convert existing plain or manual PyTorch training code into an NVFLARE federated job using Client API model exchange, local validation, and job export; use…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
nemo-relay-get-started
NVIDIA Corporation and Affiliates
Use this skill when first-time NeMo Relay users want help selecting and following an appropriate quick-start guide or verifying their first working integration.
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
jetson-video-recipe
Vinit Bansal <vinitkumarb@nvidia.com>
Use when turning a Jetson encoder use case into one surface-neutral recipe with native Video Codec SDK and PyNvVideoCodec projections.
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
nvidia-broadcast
NVIDIA Broadcast Team <broadcast-skills-dev@nvidia.com>
Use when controlling NVIDIA Broadcast through MCP to apply effects, process local media, select devices, or change camera resolution, or when Broadcast is…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
jetson-video-setup
Vinit Bansal <vinitkumarb@nvidia.com>
Use when installing, repairing, reusing, inspecting, or verifying readiness of the native NVIDIA Video Codec SDK or PyNvVideoCodec on Jetson, including the…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
nvflare-diagnose-job
NVIDIA FLARE Team <federatedlearning@nvidia.com>
Use when the user asks why a reported NVFLARE job failure signal occurred: the job failed, stalled, timed out, lost clients, ended with EXECUTION_EXCEPTION…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
nvflare-convert-lightning
NVIDIA FLARE Team <federatedlearning@nvidia.com>
Convert existing PyTorch Lightning training code into an NVFLARE federated job using the Lightning Client API patch, local validation, and job export; use…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
nemo-relay-install
NVIDIA Corporation and Affiliates
Use this skill when choosing or running NeMo Relay installation for an agent runtime, application language, framework integration, or plugin bundle, or…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
nvflare-fed-stats
NVIDIA FLARE Team <federatedlearning@nvidia.com>
Compute federated statistics over tabular data (count, sum, mean, stddev, var, histogram, quantile, noise-protected min/max) and image data (count…
SkillAFreshness: A★ 3.7KClaude Code +9 - 0.846score
jetson-video-capability
Vinit Bansal <vinitkumarb@nvidia.com>
Use when Jetson codec, profile, chroma, bit-depth, dimension, engine-count, or operational support must be reconciled from live APIs, authenticated NVIDIA…
SkillAFreshness: A★ 3.7KClaude Code +9
Signals
- Stars
- 3,718
- Forks
- 457
- Open issues
- 8
- Last commit (this folder)
- May 29, 2026 (5 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Apache-2.0
- Repository
- github.com/NVIDIA/skills
- Website
- docs.nvidia.com/skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from Philip Petrakian <ppetrakian@nvidia.com>
- 0.733score
mcore-linting-and-formatting
Philip Petrakian <ppetrakian@nvidia.com>
Linting and formatting for Megatron-LM.
SkillCFreshness: C★ 3.7KClaude Code +9 - 0.733score
mcore-testing
Philip Petrakian <ppetrakian@nvidia.com>
Test system for Megatron-LM.
SkillCFreshness: C★ 3.7KClaude Code +9 - 0.730score
mcore-split-pr
Philip Petrakian <ppetrakian@nvidia.com>
Split a PR into multiple PRs to reduce the number of required CODEOWNERS reviewer groups.
SkillCFreshness: C★ 3.7KClaude Code +9 - 0.730score
mcore-create-issue
Philip Petrakian <ppetrakian@nvidia.com>
Investigate a failing GitHub Actions run or job and create a GitHub issue for the failure.
SkillCFreshness: C★ 3.7KClaude Code +9
Cite this page
mcore-run-on-slurm skill. Agent Mart. https://agentmart.dev/skills/nvidia-mcore-run-on-slurm (last updated 2026-10-24)