The Complete Production SOP: How to Deploy and Run Megatron-LM 3D Parallelism Tensor & Pipeline in Autonomous AI Agents
Step-by-step SOP to install and run Megatron-LM 3D Parallelism in Codex, Claude Code, and Cursor. Configure TP, PP, and sequence parallelism deterministically.
Technical Overview & Architectural Context
Autonomous coding agents frequently fail when configuring multi-dimensional distributed training for 100B+ parameter models. LLMs routinely propose misaligned tensor parallelism (TP) dimensions that span across inter-node InfiniBand fabrics instead of confining TP ranks within intra-node NVLink domains, causing severe communication bottlenecks. Additionally, agents frequently omit critical sequence parallelism flags when scaling activation checkpoints, leading to catastrophic CUDA Out Of Memory (OOM) failures on DGX SuperPOD architectures. The megatron-lm-tensor-parallelism skill enforces strict mathematical and architectural constraints on agent reasoning. It binds autonomous agents to deterministic verification rules: sizing TP strictly against intra-chassis GPU counts (typically 8 GPUs per HGX node), computing pipeline parallel (PP) stages across balanced layer cuts, and orchestrating virtual pipeline scheduling (1F1B) with sequence parallelism enabled. By defining explicit boundaries in SKILL.md, agents generate mathematically sound training launch scripts without hallucinating invalid hardware topologies.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into the agent runtime.
Agent runtimes such as Claude Code, Cursor, and Codex discover procedural skills by traversing local hidden directories (.claude/skills, .cursor/rules, or .agents/skills). Installing the SKILL.md file establishes deterministic guardrails for Megatron-LM 3D parallelism configurations before the agent processes user instructions.
mkdir -p ~/.agents/skills/megatron-lm-tensor-parallelism && curl -fsSL https://askills.dev/api/skills/megatron-lm-tensor-parallelism/raw -o ~/.agents/skills/megatron-lm-tensor-parallelism/SKILL.md---
name: "megatron-lm-tensor-parallelism"
description: "Scale training of 100B+ frontier models with Megatron-LM tensor and pipeline parallelism."
metadata:
author: "NVIDIA"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "configure megatron tensor parallelism"
- "setup pipeline parallelism"
- "train 100b model megatron"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# Megatron-LM 3D Parallelism Tensor & Pipeline
Configures NVIDIA Megatron-LM: Tensor Parallelism (TP), Pipeline Parallelism (PP), Data Parallelism (DP), sequence parallelism, and custom Transformer engine kernels on DGX SuperPODs.
## When to Invoke
Invoke this skill whenever you need to:
- configure megatron tensor parallelism
- setup pipeline parallelism
- train 100b model megatron
## Execution SOP & Rules
1. Set --tensor-model-parallel-size to match the number of GPUs within a single NVLink node (typically 8).
2. Set --pipeline-model-parallel-size such that Total_Layers % PP_Size == 0.
3. Always append --sequence-parallel when TP > 1 to distribute LayerNorm and Dropout activations.
4. Ensure (TP * PP * DP) == Total World Size (NNODES * GPUS_PER_NODE).
5. Configure --num-layers-per-virtual-pipeline-stage when interleaving 1F1B schedules.Keep the SKILL.md focused solely on operational boundaries to preserve LLM token context; avoid pasting entire bash launcher templates into the skill definition.
Ensure that the agent sandbox has workspace write permissions enabled; otherwise, the runtime cannot generate the output launch scripts (.sh).
Environment Secrets & Distributed Topology Mapping
Configure distributed cluster variables and NVLink topology parameters without exposing infrastructure secrets.
Megatron-LM requires environment variables for PyTorch distributed backends (NCCL) and cluster node addresses. Define cluster node counts, MASTER_ADDR, and GPU counts in an isolated environment configuration file that the agent reads without persisting credentials to conversation history.
cat << 'EOF' > .env.distributed
MASTER_ADDR=10.240.0.1
MASTER_PORT=6000
NNODES=16
GPUS_PER_NODE=8
WORLD_SIZE=128
NCCL_IB_DISABLE=0
NCCL_NET_GDR_LEVEL=5
EOF#!/usr/bin/env bash
source .env.distributed
echo "Configuring 3D Parallelism for Cluster:"
echo "Total GPUs: $((NNODES * GPUS_PER_NODE))"
if [ $((WORLD_SIZE % (GPUS_PER_NODE))) -ne 0 ]; then
echo "ERROR: Cluster world size must align with physical nodes."
exit 1
fiStore cluster IPs and credentials in .env.distributed and add it to .gitignore; inform the agent to inspect variable names without echoing their contents.
Never execute launch scripts directly within the agent runtime when shell_exec is set to false; instruct the agent to generate and validate the script.
Intent Matching & Trigger Invocation
Activate the skill deterministically by invoking verified natural language triggers.
Autonomous runtimes parse user prompts against the declared triggers list in SKILL.md. By using explicit phrases like 'configure megatron tensor parallelism' or 'train 100b model megatron', the runtime immediately pulls the SOP constraints into active context and bypasses default non-distributed completions.
claude 'configure megatron tensor parallelism for a 128-GPU DGX H100 cluster targeting a 104B model'Include exact model architecture constraints (e.g., hidden size divisible by TP) in the trigger prompt to allow immediate mathematical verification.
Vague instructions like 'make my model run on many GPUs' can trigger generic PyTorch DDP recipes rather than Megatron-LM 3D parallelism.
Verification, Linting & Output Quality Gate
Execute automated mathematical validation of TP, PP, and DP product dimensions before applying scripts.
Instruct the agent to validate that the distributed tensor parallelism and pipeline partitioning align with the targeted model layers. Run a deterministic Python verification script to confirm zero remainder in layer division and tensor slice compatibility.
python3 -c '
tp = 8
pp = 4
dp = 4
world = 128
layers = 80
assert tp * pp * dp == world, f"Mismatch: {tp*pp*dp} != {world}"
assert layers % pp == 0, f"Layers {layers} not divisible by PP {pp}"
print("Topology verified successfully.")
'import sys
def verify_megatron_topology(tp, pp, dp, world_size, layers, hidden_size, num_heads):
assert tp * pp * dp == world_size, f"Topology error: TP({tp}) * PP({pp}) * DP({dp}) != WORLD({world_size})"
assert layers % pp == 0, f"Layers ({layers}) must be divisible by Pipeline Parallel size ({pp})"
assert hidden_size % tp == 0, f"Hidden size ({hidden_size}) must be divisible by TP ({tp})"
assert num_heads % tp == 0, f"Attention heads ({num_heads}) must be divisible by TP ({tp})"
print("Megatron-LM 3D Parallelism configuration is mathematically valid.")
if __name__ == '__main__':
verify_megatron_topology(tp=8, pp=4, dp=4, world_size=128, layers=80, hidden_size=8192, num_heads=64)Ensure the agent includes the verification script call at the top of the generated bash launcher to catch cluster dimension mismatches immediately at runtime.
Failing to check if attention heads are divisible by the tensor parallel size will cause runtime NCCL assertions inside Megatron self-attention layers.
Real-World Scenario: Configure Megatron-LM 3D Parallelism Launch Script for a 104-Billion Parameter LLM on 16 DGX H100 Nodes
“Act as an expert distributed systems engineer using the megatron-lm-tensor-parallelism skill. Generate an automated SLURM and Torchrun launch script to train 100b model megatron on 16 DGX nodes (128 total H100 GPUs). Model specifications: 80 layers, hidden dimension 8192, 64 attention heads, vocabulary size 32000, sequence length 4096. Ensure sequence parallelism and FP8 TransformerEngine are enabled.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent set Tensor Parallelism (TP) across multiple nodes without verifying that the attention head count is divisible by TP, or attempted TP spanning across inter-node InfiniBand instead of intra-node NVLink.
Adjust the launcher arguments: set --tensor-model-parallel-size to 8 (matching the 8 NVLink GPUs per node) and scale --pipeline-model-parallel-size to absorb the remaining parallelism factor.Root Cause: Activation memory exhausted because tensor parallelism was configured without sequence parallelism, leaving non-tensor-parallel layers (LayerNorm and Dropout) duplicated across ranks.
Add the following flags to the Megatron-LM arguments: --sequence-parallel --recompute-activations --recompute-granularity selectiveFrequently Asked Questions (Megatron-LM 3D Parallelism Tensor & Pipeline SOP)
Q:Can I use Megatron-LM 3D Parallelism Tensor & Pipeline across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification supported across all modern agent runtimes. By placing the SKILL.md manifest into the agent's recognized configuration paths, Codex, Claude Code, Cursor, and Windsurf will parse identical operational constraints.
Q:How does Megatron-LM 3D Parallelism Tensor & Pipeline prevent context window overflow during long agent sessions?
By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules. The skill provides terse, high-density rules for TP, PP, and DP ratios, preventing repetitive back-and-forth prompt clarifications.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100 and runs safely within workspace-scoped sandboxes. The skill requires only read access to system topology and write access to workspace bash scripts, keeping network and shell execution disabled.
Ready to equip your autonomous agent with Megatron-LM 3D Parallelism Tensor & Pipeline?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.