NVIDIA / NVIDIA/Megatron-LM

[QUESTION] On GB200 NVL72, loss differences exist between intra-rack and inter-rack configurations

Open
#1,881 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
17.9k
Forks
4.5k
Avg merge
4d 6h
Merged PRs (30d)
271

Description

Hi, Megatron Team!

I was training on GB200 NVL72 and noticed an interesting behavior while debugging with deterministic computation enabled. Keeping the training scale fixed at 2 trays with 8 GPUs, I observed that when both trays reside within the same rack, the loss values across multiple runs align bit-for-bit. Similarly, when the two trays span two separate racks, the loss also remains bit-for-bit reproducible across runs.

However, when comparing training loss runs using one rack versus two racks, a loss discrepancy appears between the two configurations.

Would you mind provide some guidance?

Training loss on save rack:

```
[2025-10-22 16:59:16] iteration 1/73242187 | consumed samples: 8 | elapsed time per iteration (ms): 16442.7 | throughput per GPU (TFLOP/s/GPU): 1.8 | learning rate: 3.900183E-07 | global batch size: 8 | lm loss: 1.219037E+01 | seq_load_balancing_loss: 1.300237E+00 | loss scale: 1.0 | grad norm: 18.417 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-10-22 16:59:16] iteration 2/73242187 | consumed samples: 16 | elapsed time per iteration (ms): 370.2 | throughput per GPU (TFLOP/s/GPU): 81.1 | learning rate: 3.900366E-07 | global batch size: 8 | lm loss: 1.217610E+01 | seq_load_balancing_loss: 1.297935E+00 | loss scale: 1.0 | grad norm: 18.317 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-10-22 16:59:17] iteration 3/73242187 | consumed samples: 24 | elapsed time per iteration (ms): 264.7 | throughput per GPU (TFLOP/s/GPU): 113.4 | learning rate: 3.900549E-07 | global batch size: 8 | lm loss: 1.217580E+01 | seq_load_balancing_loss: 1.324713E+00 | loss scale: 1.0 | grad norm: 19.221 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-10-22 16:59:17] iteration 4/73242187 | consumed samples: 32 | elapsed time per iteration (ms): 291.5 | throughput per GPU (TFLOP/s/GPU): 102.9 | learning rate: 3.900731E-07 | global batch size: 8 | lm loss: 1.220420E+01 | seq_load_balancing_loss: 1.309981E+00 | loss scale: 1.0 | grad norm: 18.939 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-10-22 16:59:17] iteration 5/73242187 | consumed samples: 40 | elapsed time per iteration (ms): 228.3 | throughput per GPU (TFLOP/s/GPU): 131.4 | learning rate: 3.900914E-07 | global batch size: 8 | lm loss: 1.213402E+01 | seq_load_balancing_loss: 1.295601E+00 | loss scale: 1.0 | grad norm: 16.510 | number of skipped iterations: 0 | number of nan iterations: 0 |
```

Training loss across 2 racks:

```
[2025-10-22 17:02:56] iteration 1/73242187 | consumed samples: 8 | elapsed time per iteration (ms): 15723.2 | throughput per GPU (TFLOP/s/GPU): 1.9 | learning rate: 3.900183E-07 | global batch size: 8 | lm loss: 1.219037E+01 | seq_load_balancing_loss: 1.300237E+00 | loss scale: 1.0 | grad norm: 18.417 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-10-22 17:02:57] iteration 2/73242187 | consumed samples: 16 | elapsed time per iteration (ms): 680.3 | throughput per GPU (TFLOP/s/GPU): 44.1 | learning rate: 3.900366E-07 | global batch size: 8 | lm loss: 1.217501E+01 | seq_load_balancing_loss: 1.297871E+00 | loss scale: 1.0 | grad norm: 18.338 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-10-22 17:02:57] iteration 3/73242187 | consumed samples: 24 | elapsed time per iteration (ms): 330.3 | throughput per GPU (TFLOP/s/GPU): 90.9 | learning rate: 3.900549E-07 | global batch size: 8 | lm loss: 1.217724E+01 | seq_load_balancing_loss: 1.324625E+00 | loss scale: 1.0 | grad norm: 19.207 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-10-22 17:02:58] iteration 4/73242187 | consumed samples: 32 | elapsed time per iteration (ms): 312.8 | throughput per GPU (TFLOP/s/GPU): 96.0 | learning rate: 3.900731E-07 | global batch size: 8 | lm loss: 1.220339E+01 | seq_load_balancing_loss: 1.310011E+00 | loss scale: 1.0 | grad norm: 18.930 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-10-22 17:02:58] iteration 5/73242187 | consumed samples: 40 | elapsed time per iteration (ms): 294.1 | throughput per GPU (TFLOP/s/GPU): 102.0 | learning rate: 3.900914E-07 | global batch size: 8 | lm loss: 1.213474E+01 | seq_load_balancing_loss: 1.295684E+00 | loss scale: 1.0 | grad norm: 16.508 | number of skipped iterations: 0 | number of nan iterations: 0 |
```

I have tried several NCCL environment variables such as:
```shell
export NCCL_ALGO="Ring"
export NCCL_ALGO="^NVLS"
export NCCL_ALGO="allreduce:^Ring"
export NCCL_ALGO="allreduce:Tree"
```
The training loss between the one-rack and two-rack configurations has never aligned.

# To reproduce
Megatron-LM: c17d3cfab34615aa58ce933a603a06a5eff7932a
TransformerEngine: https://github.com/NVIDIA/TransformerEngine/commit/483d9594

Arguments related to deterministic mode:
```shell
# env
export CUBLAS_WORKSPACE_CONFIG=:4096:8
export NCCL_NVLS_ENABLE=0
export NCCL_ALGO="allreduce:^Ring"
export NVTE_ALLOW_NONDETERMINISTIC_ALGO=0
export NVTE_FLASH_ATTN=0
export NVTE_FUSED_ATTN=0
# mcore
--deterministic-mode
--attention-backend unfused
```

training script:

```shell
#!/bin/bash
set -ex
GPUS_PER_NODE=4

WORLD_SIZE=${WORKER_NUM:-1}
NODE_RANK=${RANK:-0}
MASTER_ADDR=${MASTER_ADDR:-127.0.0.1}
MASTER_PORT=${MASTER_PORT:-20000}
GPU_NUM=$((${GPUS_PER_NODE}*${WORLD_SIZE}))

LAUNCHER=" \
python3 -m torch.distributed.run \
--nnodes=$WORLD_SIZE \
--nproc_per_node=$GPUS_PER_NODE \
--node_rank $NODE_RANK \
--master_addr $MASTER_ADDR \
--master_port $MASTER_PORT \
"

export OMP_NUM_THREADS=1
export NCCL_DEBUG_SUBSYS=INIT,ENV,TUNING
export NCCL_DEBUG=INFO

export TORCH_NCCL_AVOID_RECORD_STREAMS="1"
export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"
export NCCL_NVLS_ENABLE=0
export CUBLAS_WORKSPACE_CONFIG=:4096:8
export NCCL_ALGO="allreduce:Tree"
export NVTE_FUSED_ATTN=0
export NVTE_FLASH_ATTN=0
export NVTE_ALLOW_NONDETERMINISTIC_ALGO=0
export NVTE_NORM_FWD_USE_CUDNN=0
export NVTE_NORM_BWD_USE_CUDNN=0

DEVICE_MODEL="gb200"

JOB_DIR="/path/to/deterministic_mcore0.14_ngc2506_deepseek_gqa_bf16_${DEVICE_MODEL}_${GPU_NUM}p"
mkdir -p ${JOB_DIR}
if [ "$RANK" -eq 0 ]; then
cp -r ${0} ${JOB_DIR}
fi
CHECKPOINT_PATH=$JOB_DIR
TENSORBOARD_LOGS_PATH=${JOB_DIR}

LOG_PATH="${JOB_DIR}/log_8layer_4p_${NODE_RANK}.txt"

MOE_ARGS=(
--moe-grouped-gemm
--moe-permute-fusion
--moe-token-dispatcher-type alltoall
--num-experts 64
--moe-ffn-hidden-size 2048
--moe-router-score-function sigmoid
--moe-router-topk 8
--moe-router-enable-expert-bias
--moe-router-topk-scaling-factor 2.5
--moe-router-load-balancing-type "seq_aux_loss"
--moe-router-group-topk 4
--moe-router-num-groups 8
--moe-router-dtype "fp32"
--moe-aux-loss-coeff "1e-4"
--moe-router-bias-update-rate 1e-3
--moe-router-pre-softmax
)

GPT_MODEL_ARGS=(
--num-layers 8
--hidden-size 2048
--ffn-hidden-size 5120
--num-attention-heads 16
--num-query-groups 4
--group-query-attention
--mscale 1.0
--mscale-all-dim 1.0
--max-position-embeddings 4096
--make-vocab-size-divisible-by 3232
--position-embedding-type "rope"
--rotary-base 10000
--rotary-percent 1.0
--rotary-scaling-factor 40
--swiglu
--untie-embeddings-and-output-weights
--normalization "RMSNorm"
--norm-epsilon "1e-06"
--disable-bias-linear
--transformer-impl "transformer_engine"
--attention-dropout 0
--hidden-dropout 0
)

MLA_ARGS=(
--multi-latent-attention
--kv-channels 128
--q-lora-rank 1536
--kv-lora-rank 512
--qk-head-dim 128
--qk-pos-emb-head-dim 64
--v-head-dim 128
)

TRAINING_ARGS=(
--micro-batch-size 1
--global-batch-size 8
--seq-length "4096"
--weight-decay 0.1
--adam-beta1 0.9
--adam-beta2 0.95
--init-method-std 0.02
--clip-grad 1.0
--bf16
--qk-layernorm
--train-samples 585937500
--lr-decay-samples 584765624
--lr-warmup-samples 1536000
--lr-warmup-init "3.9e-7"
--lr "3.9e-6"
--min-lr "3.9e-7"
--lr-decay-style cosine
--no-check-for-nan-in-loss-and-grad
)

MODEL_PARALLEL_ARGS=(
--tensor-model-parallel-size 1
--expert-model-parallel-size 8
--expert-tensor-parallel-size 1
--context-parallel-size 1
--sequence-parallel
--disable-gloo-process-groups
)

DATA_ARGS=(
--data-path "/path/to/code/mxfp8_loadckpt/h800_baseline/CC-MAIN-2024-10_merged/CC-MAIN-2024-10_merged"
--tokenizer-type "HuggingFaceTokenizer"
--tokenizer-model "/path/to/code/data/DeepSeek-V3-Config"
--split 949,50,1
--dataloader-type "single"
--no-create-attention-mask-in-dataloader
)

EVAL_AND_LOGGING_ARGS=(
--save-interval 100000
--eval-interval 100
--save $CHECKPOINT_PATH
--load /tmp
--no-load-rng
--ckpt-format "torch_dist"
--async-save
--eval-iters 1
--log-interval 1
--log-throughput
--tensorboard-dir $TENSORBOARD_LOGS_PATH
--log-timers-to-tensorboard
--log-memory-to-tensorboard
--log-world-size-to-tensorboard
--log-validation-ppl-to-tensorboard
)

KERNEL_ARGS=(
--deterministic-mode
--attention-backend unfused
--no-masked-softmax-fusion
--attention-softmax-in-fp32
)

CMD="${LAUNCHER} pretrain_gpt.py \
${MOE_ARGS[@]}
${GPT_MODEL_ARGS[@]} \
${TRAINING_ARGS[@]} \
${MODEL_PARALLEL_ARGS[@]} \
${DATA_ARGS[@]} \
${EVAL_AND_LOGGING_ARGS[@]} \
${KERNEL_ARGS[@]} \
"
echo ${CMD}

nohup ${CMD} > ${LOG_PATH} 2>&1 &
```

# Pytorch ENV

ENV

```
PyTorch version: 2.8.0a0+5228986c39.nv25.06
Is debug build: False
CUDA used to build PyTorch: 12.9
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.2 LTS (aarch64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: 18.1.3 (1ubuntu1)
CMake version: version 4.0.3
Libc version: glibc-2.39

Python version: 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.6.47-002.ant8.aarch64-aarch64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: 12.9.86
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA GB200
GPU 1: NVIDIA GB200
GPU 2: NVIDIA GB200
GPU 3: NVIDIA GB200

Nvidia driver version: 580.65.06
cuDNN version: Probably one of the following:
/usr/lib/aarch64-linux-gnu/libcudnn.so.9.10.2
/usr/lib/aarch64-linux-gnu/libcudnn_adv.so.9.10.2
/usr/lib/aarch64-linux-gnu/libcudnn_cnn.so.9.10.2
/usr/lib/aarch64-linux-gnu/libcudnn_engines_precompiled.so.9.10.2
/usr/lib/aarch64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.10.2
/usr/lib/aarch64-linux-gnu/libcudnn_graph.so.9.10.2
/usr/lib/aarch64-linux-gnu/libcudnn_heuristic.so.9.10.2
/usr/lib/aarch64-linux-gnu/libcudnn_ops.so.9.10.2
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 144
On-line CPU(s) list: 0-143
Vendor ID: ARM
Model name: Neoverse-V2
Model: 0
Thread(s) per core: 1
Core(s) per cluster: 72
Socket(s): -
Cluster(s): 2
Stepping: r0p0
Frequency boost: disabled
CPU(s) scaling MHz: 95%
CPU max MHz: 3411.0000
CPU min MHz: 81.0000
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh
L1d cache: 9 MiB (144 instances)
L1i cache: 9 MiB (144 instances)
L2 cache: 144 MiB (144 instances)
L3 cache: 228 MiB (2 instances)
NUMA node(s): 34
NUMA node0 CPU(s): 0-71
NUMA node1 CPU(s): 72-143
NUMA node2 CPU(s):
NUMA node3 CPU(s):
NUMA node4 CPU(s):
NUMA node5 CPU(s):
NUMA node6 CPU(s):
NUMA node7 CPU(s):
NUMA node8 CPU(s):
NUMA node9 CPU(s):
NUMA node10 CPU(s):
NUMA node11 CPU(s):
NUMA node12 CPU(s):
NUMA node13 CPU(s):
NUMA node14 CPU(s):
NUMA node15 CPU(s):
NUMA node16 CPU(s):
NUMA node17 CPU(s):
NUMA node18 CPU(s):
NUMA node19 CPU(s):
NUMA node20 CPU(s):
NUMA node21 CPU(s):
NUMA node22 CPU(s):
NUMA node23 CPU(s):
NUMA node24 CPU(s):
NUMA node25 CPU(s):
NUMA node26 CPU(s):
NUMA node27 CPU(s):
NUMA node28 CPU(s):
NUMA node29 CPU(s):
NUMA node30 CPU(s):
NUMA node31 CPU(s):
NUMA node32 CPU(s):
NUMA node33 CPU(s):
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Not affected
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] flake8==7.3.0
[pip3] mypy_extensions==1.1.0
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.9.1.4
[pip3] nvidia-cuda-cupti-cu12==12.9.79
[pip3] nvidia-cuda-nvrtc-cu12==12.9.86
[pip3] nvidia-cuda-runtime-cu12==12.9.79
[pip3] nvidia-cudnn-cu12==9.11.0.98
[pip3] nvidia-cudnn-frontend==1.12.0
[pip3] nvidia-cufft-cu12==11.4.1.4
[pip3] nvidia-curand-cu12==10.3.10.19
[pip3] nvidia-cusolver-cu12==11.7.5.82
[pip3] nvidia-cusparse-cu12==12.5.10.65
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-nccl-cu12==2.27.6
[pip3] nvidia-nvjitlink-cu12==12.9.86
[pip3] nvidia-nvtx-cu12==12.9.79
[pip3] nvtx==0.2.11
[pip3] onnx==1.17.0
[pip3] onnx-ir==0.1.4
[pip3] onnxscript==0.3.1
[pip3] optree==0.16.0
[pip3] pynvjitlink==0.3.0
[pip3] pytorch-triton==3.3.0+git96316ce52.nvinternal
[pip3] torch==2.8.0a0+5228986c39.nv25.6
[pip3] torch_tensorrt==2.8.0a0
[pip3] torchao==0.11.0+git
[pip3] torchprofile==0.0.4
[pip3] torchvision==0.22.0a0+95f10a4e
[conda] Could not collect
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.