--deterministic-mode fails to ensure reproducibility in distributed training (Megatron-Core v0.14.0)
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 4.5k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 271
Description
## Bug Description
The `--deterministic-mode` flag does not guarantee reproducible training results in Megatron-Core v0.14.0 when running multi-node distributed training. Despite identical configurations, seeds, and deterministic environment variables, loss values and model convergence differ across runs.
This issue persists even with comprehensive deterministic configurations including:
- `CUBLAS_WORKSPACE_CONFIG`
- `NVTE_ALLOW_NONDETERMINISTIC_ALGO=0`
- Disabled NVLS and Flash Attention
- `CUDA_DEVICE_MAX_CONNECTIONS=1`
---
## Environment
| Component | Version/Details |
|-----------|----------------|
| **Megatron-Core** | v0.14.0 |
| **Docker Image** | `nvcr.io/nvidia/pytorch:25.03-py3` |
| **GPU** | NVIDIA H200 |
| **Configuration** | 2 nodes × 8 GPUs, TP=8, PP=2 |
| **PyTorch** | [auto-detected from container] |
| **CUDA** | [auto-detected from container] |
---
## Reproduction Steps
### Configuration Details
- **Model**: GPT-style, 32 layers, 4096 hidden size
- **Parallelism**: TP=8, PP=2, Sequence Parallel enabled
- **Batch Size**: Micro-batch=32, Global-batch=64
- **Training**: 10 iterations with mock data
- **Precision**: BF16
### Launch Commands
**Node 0:**
```bash
export NCCL_ALGO=^NVLS
export NVTE_ALLOW_NONDETERMINISTIC_ALGO=0
export CUBLAS_WORKSPACE_CONFIG=:4096:8
export NCCL_NVLS_ENABLE=0
export NVTE_FUSED_ATTN=1
export NVTE_FLASH_ATTN=0
export CUDA_DEVICE_MAX_CONNECTIONS=1
torchrun \
--node_rank 0 \
--nnodes 2 \
--nproc_per_node gpu \
--master_addr 10.53.249.242 \
--master_port 23456 \
./pretrain_gpt.py \
--tensor-model-parallel-size 8 \
--pipeline-model-parallel-size 2 \
--num-layers 32 \
--hidden-size 4096 \
--num-attention-heads 32 \
--seq-length 2048 \
--max-position-embeddings 2048 \
--micro-batch-size 32 \
--global-batch-size 64 \
--no-overlap-p2p-communication \
--train-iters 10 \
--deterministic-mode \
--attention-backend fused \
--use-distributed-optimizer \
--sequence-parallel \
--log-interval 1 \
--log-throughput \
--no-one-logger \
--lr-decay-iters 35 \
--lr-warmup-iters 5 \
--distributed-backend nccl \
--lr 6.0e-5 \
--min-lr 6.0e-6 \
--lr-decay-style cosine \
--merge-file /sanitycheck/data/megatron/dataset/gpt2-merges.txt \
--vocab-file /sanitycheck/data/megatron/dataset/gpt2-vocab.json \
--clip-grad 1.0 \
--weight-decay 0.1 \
--adam-beta1 0.9 \
--adam-beta2 0.95 \
--num-workers 4 \
--init-method-std 0.006 \
--bf16 \
--mock-data \
--eval-iters 0 \
--rerun-mode disabled
```
**Node 1:**
```bash
# Same environment variables as Node 0
torchrun \
--node_rank 1 \
--nnodes 2 \
--nproc_per_node gpu \
--master_addr 10.53.249.242 \
--master_port 23456 \
./pretrain_gpt.py \
[... identical arguments as Node 0 ...]
```
---
## Expected Behavior
Running the same command multiple times with `--deterministic-mode` should produce:
- ✅ Identical loss values at each iteration
- ✅ Bit-exact model weights/gradients
- ✅ Identical convergence trajectory
- ✅ Reproducible checkpoints
---
## Actual Behavior
❌ Loss and gradient norm values are non-deterministic across runs:
**Example:**
```
Run 1 - [2025-11-24 19:16:42] iteration 1/10 | consumed samples: 64 | learning rate: 1.200000E-05 | global batch size: 64 | lm loss: 1.092887E+01 | loss scale: 1.0 | grad norm: 13.095 | ...
Run 2 - [2025-11-24 19:18:05] iteration 1/10 | consumed samples: 64 | learning rate: 1.200000E-05 | global batch size: 64 | lm loss: 1.092407E+01 | loss scale: 1.0 | grad norm: 13.054 | ...
```
---
**Impact**: High - Blocks reproducibility validation and deterministic testing workflows
**Urgency**: Medium - Deterministic mode works correctly in v0.13.1 but is broken in v0.14.0, forcing users to remain on the older version to maintain reproducibility.
Contributor guide
Assessment
This issue has not been assessed yet.