[BUG] deepspeed zero2 training hangon and timeout after a fixed step
Describe the bug I use deepspeed zero2 to train a transformer-based dit model. However, the script always gets stuck at a fixed step after one hour of training. When I disable deepspeed and use pure pytorch DDP to train the code, the problem disappears. Moreover, even if I change the mixed-precision from fp16 to bf16 or adjust the learning rate, the same problem occurs and the script gets stuck at the same training step.
I have also tried changing the model initialization and resuming the training, but the script still gets stuck after the same training step. For example, if the script gets stuck after training 14K steps, I save the checkpoint at the 10K step and resume training with the 10K-step checkpoint. Then, after training another 14K steps again, the script gets stuck once more.
ds_report output
[rank0]:[E217 07:24:07.938443115 ProcessGroupNCCL.cpp:616] [Rank 0] Watchdog caught collective operation timeout: WorkNCCL(SeqNum=54053, OpType=ALLREDUCE, NumelIn=497464352, NumelOut=497464352, Timeout(ms)=600000) ran for 600087 milliseconds before timing out.
[rank0]:[E217 07:24:07.938551513 ProcessGroupNCCL.cpp:1785] [PG ID 1 PG GUID 1 Rank 0] Exception (either an error or timeout) detected by watchdog at work: 54053, last enqueued NCCL work: 54054, last completed NCCL work: 54052.
[rank0]:[E217 07:24:08.990085728 ProcessGroupNCCL.cpp:1834] [PG ID 1 PG GUID 1 Rank 0] Timeout at NCCL work: 54053, last enqueued NCCL work: 54054, last completed NCCL work: 54052.
[rank0]:[E217 07:24:08.990112551 ProcessGroupNCCL.cpp:630] [Rank 0] Some NCCL operations have failed or timed out. Due to the asynchronous nature of CUDA kernels, subsequent GPU operations might run on corrupted/incomplete data.
[rank0]:[E217 07:24:08.990119150 ProcessGroupNCCL.cpp:636] [Rank 0] To avoid data inconsistency, we are taking the entire process down.
[rank0]:[E217 07:24:08.991954167 ProcessGroupNCCL.cpp:1595] [PG ID 1 PG GUID 1 Rank 0] Process group watchdog thread terminated with exception: [Rank 0] Watchdog caught collective operation timeout: WorkNCCL(SeqNum=54053, OpType=ALLREDUCE, NumelIn=497464352, NumelOut=497464352, Timeout(ms)=600000) ran for 600087 milliseconds before timing out.
Exception raised from checkTimeout at /opt/tiger/compile_path/src/code.byted.org/pytorch/pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:618 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x91 (0x7f6aa3f5fdd1 in /usr/local/lib/python3.11/dist-packages/torch/lib/libc10.so)
frame #1:
terminate called after throwing an instance of 'c10::DistBackendError'
System info (please complete the following information):
- Python version: Python 3.11.2
- Pytorch version: 2.5.1+cu124
- Deepspeed version: 0.16.3
- Any other relevant info about your setup
Launcher context python -m torch.distributed.launch --nnodes=1 --nproc_per_node=8 --master_port=12345 train_deepspeed.py --xxx
Additional context Add any other context about the problem here.
I inserted some log code into my code to make the script print certain information, aiming to check at which step the code gets stuck. Then, I found that the script hangs during the backward pass on rank 0 after several steps. Here is an example of the log information: the backward pass occurs in step 33417, but not in step 33418.
================================================
pass index selection on device 0 step 33417 pass index selection on device 2 step 33417 pass index selection on device 5 step 33417 pass index selection on device 6 step 33417 pass index selection on device 3 step 33417 pass index selection on device 1 step 33417 pass index selection on device 7 step 33417 pass index selection on device 4 step 33417
pass forward on device 2 step 33417 pass forward on device 0 step 33417 pass forward on device 6 step 33417 pass forward on device 1 step 33417 pass forward on device 3 step 33417 pass forward on device 5 step 33417 pass forward on device 7 step 33417 pass forward on device 4 step 33417
pass backward on device 7 step 33417 pass backward on device 1 step 33417 pass backward on device 6 step 33417 pass backward on device 0 step 33417 pass backward on device 3 step 33417 pass backward on device 2 step 33417 pass backward on device 4 step 33417 pass backward on device 5 step 33417
pass optimization step on device 2 step 33417 pass optimization step on device 7 step 33417 pass optimization step on device 6 step 33417 pass optimization step on device 5 step 33417 pass optimization step on device 4 step 33417 pass optimization step on device 3 step 33417 pass optimization step on device 0 step 33417 pass optimization step on device 1 step 33417 train_steps: 33417, shared_interval_idx: tensor([1], device='cuda:7', dtype=torch.int32), running_loss: 5.311360597610474, device: 7 train_steps: 33417, shared_interval_idx: tensor([1], device='cuda:0'), running_loss: 5.180153250694275, device: 0 train_steps: 33417, shared_interval_idx: tensor([1], device='cuda:1', dtype=torch.int32), running_loss: 5.240574240684509, device: 1 train_steps: 33417, shared_interval_idx: tensor([1], device='cuda:2', dtype=torch.int32), running_loss: 5.239009439945221, device: 2 train_steps: 33417, shared_interval_idx: tensor([1], device='cuda:5', dtype=torch.int32), running_loss: 5.259356379508972, device: 5 train_steps: 33417, shared_interval_idx: tensor([1], device='cuda:3', dtype=torch.int32), running_loss: 5.346103191375732, device: 3 train_steps: 33417, shared_interval_idx: tensor([1], device='cuda:6', dtype=torch.int32), running_loss: 5.2149001359939575, device: 6 train_steps: 33417, shared_interval_idx: tensor([1], device='cuda:4', dtype=torch.int32), running_loss: 5.125726819038391, device: 4
pass index selection on device 4 step 33418 pass index selection on device 2 step 33418 pass index selection on device 3 step 33418 pass index selection on device 5 step 33418 pass index selection on device 1 step 33418 pass index selection on device 7 step 33418 pass index selection on device 6 step 33418
pass forward on device 2 step 33418 pass forward on device 7 step 33418 pass forward on device 4 step 33418 pass forward on device 1 step 33418 pass forward on device 5 step 33418 pass forward on device 3 step 33418 pass forward on device 6 step 33418 pass forward on device 0 step 33418
pass backward on device 2 step 33418 pass backward on device 6 step 33418 pass backward on device 5 step 33418 pass backward on device 7 step 33418 pass backward on device 4 step 33418 pass backward on device 1 step 33418 pass backward on device 3 step 33418
pass optimization step on device 5 step 33418 pass optimization step on device 4 step 33418 pass optimization step on device 2 step 33418 pass optimization step on device 6 step 33418 pass optimization step on device 3 step 33418 pass optimization step on device 7 step 33418 pass optimization step on device 1 step 33418
train_steps: 33418, shared_interval_idx: tensor([2], device='cuda:5', dtype=torch.int32), running_loss: 6.078900039196014, device: 5 train_steps: 33418, shared_interval_idx: tensor([2], device='cuda:4', dtype=torch.int32), running_loss: 5.950639605522156, device: 4 train_steps: 33418, shared_interval_idx: tensor([2], device='cuda:2', dtype=torch.int32), running_loss: 6.0558441281318665, device: 2 train_steps: 33418, shared_interval_idx: tensor([2], device='cuda:3', dtype=torch.int32), running_loss: 6.203619062900543, device: 3 train_steps: 33418, shared_interval_idx: tensor([2], device='cuda:6', dtype=torch.int32), running_loss: 6.059363543987274, device: 6 train_steps: 33418, shared_interval_idx: tensor([2], device='cuda:7', dtype=torch.int32), running_loss: 6.090326964855194, device: 7 train_steps: 33418, shared_interval_idx: tensor([2], device='cuda:1', dtype=torch.int32), running_loss: 6.035567224025726, device: 1
[rank0]:[E218 08:45:14.863205760 ProcessGroupNCCL.cpp:616] [Rank 0] Watchdog caught collective operation timeout: WorkNCCL(SeqNum=54043, OpType=ALLREDUCE, NumelIn=497464352, NumelOut=497464352, Timeout(ms)=600000) ran for 600008 milliseconds before timing out. [rank0]:[E218 08:45:14.865658012 ProcessGroupNCCL.cpp:1785] [PG ID 1 PG GUID 1 Rank 0] Exception (either an error or timeout) detected by watchdog at work: 54043, last enqueued NCCL work: 54044, last completed NCCL work: 54042. [rank0]:[E218 08:45:14.865679631 ProcessGroupNCCL.cpp:1834] [PG ID 1 PG GUID 1 Rank 0] Timeout at NCCL work: 54043, last enqueued NCCL work: 54044, last completed NCCL work: 54042. [rank0]:[E218 08:45:14.865685345 ProcessGroupNCCL.cpp:630] [Rank 0] Some NCCL operations have failed or timed out. Due to the asynchronous nature of CUDA kernels, subsequent GPU operations might run on corrupted/incomplete data. [rank0]:[E218 08:45:14.865690479 ProcessGroupNCCL.cpp:636] [Rank 0] To avoid data inconsistency, we are taking the entire process down. [rank0]:[E218 08:45:14.867338996 ProcessGroupNCCL.cpp:1595] [PG ID 1 PG GUID 1 Rank 0] Process group watchdog thread terminated with exception: [Rank 0] Watchdog caught collective operation timeout: WorkNCCL(SeqNum=54043, OpType=ALLREDUCE, NumelIn=497464352, NumelOut=497464352, Timeout(ms)=600000) ran for 600008 milliseconds before timing out.
I output more logs and found that the error was caused by the mismatch in different [components?]. However, I have no idea why this happens. I am training a moe-model with a fixed routing. For example, I route the computation to the same expert by first setting an index to 0 (which means routing to the first expert). Then, before the forward pass, I broadcast the index to all processes to ensure that all processes activate the same expert. Here is the example code:
if dist.get_rank() == 0:
probs = torch.tensor([0.2395, 0.521, 0.2395])
shared_interval_idx = torch.multinomial(probs, 1).to("cuda")
else:
shared_interval_idx = torch.zeros(1, dtype=torch.int32, device="cuda")
dist.broadcast(shared_interval_idx, src=0)
model.forward(x,y,shared_interval_idx)
When I output the shared_interval_idx, the number is the same for all the processes. However, the script crashes after several steps, accompanied by the following log. Does anyone have any advice?
Rank 0: Before broadcast Rank 2: Before broadcast Rank 4: Before broadcast Rank 6: Before broadcast Rank 3: Before broadcast Rank 5: Before broadcast Rank 1: Before broadcast Rank 7: Before broadcast
Rank 0: Tensor shape torch.Size([1]), dtype torch.int32 Rank 2: Tensor shape torch.Size([1]), dtype torch.int32
Rank 4: Tensor shape torch.Size([1]), dtype torch.int32 Rank 6: Tensor shape torch.Size([1]), dtype torch.int32
Rank 3: Tensor shape torch.Size([1]), dtype torch.int32 Rank 5: Tensor shape torch.Size([1]), dtype torch.int32 Rank 7: Tensor shape torch.Size([1]), dtype torch.int32 Rank 1: Tensor shape torch.Size([1]), dtype torch.int32
Rank 1: After broadcast
Rank 4: After broadcast
Rank 0: After broadcast
Rank 3: After broadcast
Rank 6: After broadcast
Rank 5: After broadcast
Rank 2: After broadcast
Rank 7: After broadcast
pass index selection on device 1 step 3942 with shared_interval_idx as tensor([1], device='cuda:1', dtype=torch.int32)
pass index selection on device 2 step 3942 with shared_interval_idx as tensor([1], device='cuda:2', dtype=torch.int32)
pass index selection on device 4 step 3942 with shared_interval_idx as tensor([1], device='cuda:4', dtype=torch.int32)
pass index selection on device 0 step 3942 with shared_interval_idx as tensor([1], device='cuda:0', dtype=torch.int32)
pass index selection on device 3 step 3942 with shared_interval_idx as tensor([1], device='cuda:3', dtype=torch.int32)
pass index selection on device 6 step 3942 with shared_interval_idx as tensor([1], device='cuda:6', dtype=torch.int32)
pass index selection on device 5 step 3942 with shared_interval_idx as tensor([1], device='cuda:5', dtype=torch.int32)
pass index selection on device 7 step 3942 with shared_interval_idx as tensor([1], device='cuda:7', dtype=torch.int32)
pass forward on device 3 step 3942
pass forward on device 2 step 3942
pass forward on device 4 step 3942
pass forward on device 5 step 3942
pass forward on device 1 step 3942
pass forward on device 6 step 3942
pass forward on device 7 step 3942
pass forward on device 0 step 3942
Error during backward on rank0: Detected mismatch between collectives on ranks. Rank 2 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[344502304], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[497464352], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 344502304vs 497464352
pass backward on device 2 step 3942
Error during backward on rank0: Detected mismatch between collectives on ranks. Rank 6 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[344502304], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[497464352], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 344502304vs 497464352
pass backward on device 6 step 3942
Error during backward on rank0: Detected mismatch between collectives on ranks. Rank 3 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[344502304], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[497464352], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 344502304vs 497464352
pass backward on device 3 step 3942
Error during backward on rank0: Detected mismatch between collectives on ranks. Rank 4 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[344502304], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[497464352], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 344502304vs 497464352
pass backward on device 4 step 3942
Error during backward on rank0: Detected mismatch between collectives on ranks. Rank 1 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[344502304], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[497464352], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 344502304vs 497464352
pass backward on device 1 step 3942
Error during backward on rank0: Detected mismatch between collectives on ranks. Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[497464352], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 1 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[344502304], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 497464352vs 344502304
pass backward on device 0 step 3942
Error during backward on rank0: Detected mismatch between collectives on ranks. Rank 5 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[344502304], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[497464352], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 344502304vs 497464352
pass backward on device 5 step 3942
Error during backward on rank0: Detected mismatch between collectives on ranks. Rank 7 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[344502304], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=16150, OpType=ALLREDUCE, TensorShape=[497464352], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 344502304vs 497464352
pass backward on device 7 step 3942
[rank1]: Traceback (most recent call last):
[rank1]: File "/mnt/bn/genai-nebula/liruibin/codes/DiT/train_deepspeed_debug.py", line 488, in
@leeruibin I met the same problem, have you figure it out ?
I increase reduce bucket size. Model can train with longer time but still meet these question. I use H20 GPU
@cedricgsh Not yet. I have experimented with various parameters and batch sizes, but the issue persists. I am actively seeking a solution. For now, I am using PyTorch DDP (Distributed Data Parallel) to train the model instead of integrating DeepSpeed, and the training process is functioning normally.
python -m torch.distributed.launch --nnodes=1 --nproc_per_node=8 --master_port=12345 train_deepspeed.py --xxx
@leeruibin, @cedricgsh are you able to share full repro steps?
@leeruibin But in this way, you cannot speed up your training process
@tjruwase Here is a mini demo of my training code. I use deepspeed zero 2 to train the model.
import torch
torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.allow_tf32 = True
import torch.distributed as dist
from torch.utils.data import DataLoader
from torch.utils.data.distributed import DistributedSampler
import argparse
import deepspeed
import torch.nn as nn
import torch.nn.functional as F
import torch.profiler
from torch.utils.data import Dataset
#################################################################################
# Training Helper Functions #
#################################################################################
def requires_grad(model, flag=True):
"""
Set requires_grad flag for all parameters in a model.
"""
for p in model.parameters():
p.requires_grad = flag
class DemoDataset(Dataset):
def __init__(self, ):
self.samples = [torch.randn([3,224,224]) for i in range(1000)]
def __getitem__(self, index):
img = self.samples[index]
target = 100
return img, target
def __len__(self):
return len(self.samples)
from timm.layers.patch_embed import PatchEmbed
from timm.models.vision_transformer import PatchEmbed, Attention, Mlp
def modulate(x, shift, scale):
return x * (1 + scale.unsqueeze(1)) + shift.unsqueeze(1)
class Block(nn.Module):
def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, use_flash_attn=False, **block_kwargs):
super().__init__()
self.norm1 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
self.attn = Attention(hidden_size, num_heads=num_heads, qkv_bias=True, **block_kwargs)
self.norm2 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
mlp_hidden_dim = int(hidden_size * mlp_ratio)
approx_gelu = lambda: nn.GELU(approximate="tanh")
self.mlp = Mlp(in_features=hidden_size, hidden_features=mlp_hidden_dim, act_layer=approx_gelu, drop=0)
def forward(self, x):
x = x + self.attn(self.norm1(x))
x = x + self.mlp(self.norm2(x))
return x
class FinalLayer(nn.Module):
def __init__(self, hidden_size, patch_size, out_channels):
super().__init__()
self.norm_final = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
self.linear = nn.Linear(hidden_size, patch_size * patch_size * out_channels, bias=True)
def forward(self, x):
x = self.norm_final(x)
x = self.linear(x)
return x
class DemoModel(nn.Module):
def __init__(self,):
super().__init__()
self.hidden_size = 512
self.first_layer = PatchEmbed(img_size=224,patch_size=2,in_chans=3,embed_dim=self.hidden_size,bias=True)
self.blocks_1 = nn.ModuleList([
Block(self.hidden_size, 4, mlp_ratio=4.0) for _ in range(6)
])
self.blocks_2 = nn.ModuleList([
Block(self.hidden_size, 4, mlp_ratio=4.0) for _ in range(6)
])
self.blocks_3 = nn.ModuleList([
Block(self.hidden_size, 4, mlp_ratio=4.0) for _ in range(6)
])
self.final_layer = FinalLayer(self.hidden_size,patch_size=2,out_channels=3)
def unpatchify(self, x):
"""
x: (N, T, patch_size**2 * C)
imgs: (N, H, W, C)
"""
c = 3
p = 2
h = w = int(x.shape[1] ** 0.5)
assert h * w == x.shape[1]
x = x.reshape(shape=(x.shape[0], h, w, p, p, c))
x = torch.einsum('nhwpqc->nchpwq', x)
imgs = x.reshape(shape=(x.shape[0], c, h * p, h * p))
return imgs
def forward(self, x, index):
x = self.first_layer(x)
if index == 0:
for block in self.blocks_1:
x = block(x)
elif index == 1:
for block in self.blocks_2:
x = block(x)
else:
for block in self.blocks_3:
x = block(x)
x = self.final_layer(x)
x = self.unpatchify(x)
return x
#################################################################################
# Training Loop #
#################################################################################
def main(args):
assert torch.cuda.is_available(), "Training currently requires at least one GPU."
deepspeed.init_distributed()
rank = args.local_rank
device = rank % torch.cuda.device_count()
seed = args.global_seed * dist.get_world_size() + rank
torch.manual_seed(seed)
torch.cuda.set_device(device)
print(f"Starting rank={rank}, seed={seed}, world_size={dist.get_world_size()}.")
model = DemoModel()
dataset = DemoDataset()
sampler = DistributedSampler(
dataset,
num_replicas=dist.get_world_size(),
rank=rank,
shuffle=True,
seed=args.global_seed
)
loader = DataLoader(
dataset,
batch_size=args.train_batch_size,
shuffle=False,
sampler=sampler,
num_workers=args.num_workers,
pin_memory=True,
drop_last=True
)
model_engine, opt, _, __ = deepspeed.initialize(
args=args, model=model, model_parameters=model.parameters())
train_steps = 0
for epoch in range(1000):
sampler.set_epoch(epoch)
data_iter_step = 0
for x, y in loader:
model_engine.train()
x = x.to(device,dtype=torch.float16)
y = y.to(device)
if dist.get_rank() == 0:
probs = torch.tensor([0.2395, 0.521, 0.2395])
shared_interval_idx = torch.multinomial(probs, 1).to("cuda",dtype=torch.int32)
else:
shared_interval_idx = torch.zeros(1, dtype=torch.int32, device="cuda")
dist.broadcast(shared_interval_idx, src=0)
output = model(x,shared_interval_idx)
loss = F.mse_loss(output,x)
model_engine.backward(loss)
model_engine.step()
if rank==0:
out_loss = loss.item()
print(f"training loss: {out_loss}")
train_steps += 1
data_iter_step += 1
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--train_batch_size", type=int, default=32)
parser.add_argument("--global-seed", type=int, default=2023)
parser.add_argument("--num-workers", type=int, default=4)
parser.add_argument('--accum_iter', default=1, type=int,)
parser.add_argument('--local_rank', type=int, default=-1, help='local rank passed from distributed launcher')
parser = deepspeed.add_config_arguments(parser)
args = parser.parse_args()
print(args)
main(args)
And here is the deepspeed config
{
"fp16": {
"enabled": true,
"loss_scale": 0,
"loss_scale_window": 1000,
"initial_scale_power": 16,
"hysteresis": 2,
"min_loss_scale": 1,
"verbose": true
},
"optimizer": {
"type": "AdamW",
"params": {
"lr": 0.0001,
"betas": [
0.9,
0.999
],
"eps": 1e-08,
"weight_decay": 0
}
},
"bf16": {
"enabled": false
},
"train_micro_batch_size_per_gpu": 32,
"gradient_accumulation_steps": 1,
"zero_optimization": {
"stage": 2,
"overlap_comm": true,
"contiguous_gradients": true,
"sub_group_size": 1000000000.0
},
"logging": {
"level": "DEBUG",
"print_rank": "all"
},
"steps_per_print": 10000
}
I am facing the same issue, is there any update?
I am facing the same issue, is there any update?
@googe859 I am unable to repro on master branch with above example. Can you please try with master branch or share a different repro if possible?
Closing due to lack of response. Please re-open if needed.
I encounter the same issue when I train InternVL with GRPO, after turning off DeepSpeed, the issue was gone.
@gaoyinfeng can you please share steps to repro this problem? Thanks!
@sfc-gh-truwase Hi, I've been working on my project, and the issue is gone after turning off DeepSpeed (stage=0). I plan to keep the current setup for now. I will revisit this problem and try to reproduce it with a minimal implementation after the project is completed. Thanks!
@sfc-gh-truwase However, I can provide some information. The issue occurred during the training (more precisely, during the backpropagation of the losses) process of my custom GRPO implementation on Simlingo(a driving VLA based on InternVL2); I was training the model using 8 H20 GPUs, and it was observed that only the tensor shape on rank 0 differed from the others (e.g., 127634432 for rank 0 vs. 128226432 for the remaining ranks).
@gaoyinfeng thanks for the extra information. And I understand that you are busy with other work. Can you answer two questions.
- Do you see the problem using zero stage 1?
- Can you share a stack trace of the failure?
@sfc-gh-truwase Thanks for your reply!
- Yes, I encountered the same issue when using stage 1 (this is from my recollection, as I currently don't have the computing resources to reproduce the stage 1 error on demand).
- Yes, the stack trace is provided below, with rank 0 as an example:
[2026-02-22 23:55:59] worker-0 >> Error executing job with overrides: ['experiment=simlingo_takeover_ft_55', 'data_module.base_dataset.bucket_path=database/buckets/bucketsv2_simlingo_with_takeover_0210_0211_0212_0213_8p8w', 'data_module.batch_size=4', 'data_module.train_partitions.takeover=0.50', 'model.lr=3e-6', 'gpus=8', 'name=GRPO_train_debug', 'val_every_n_epochs=15', 'max_epochs=8', 'data_module.num_samples=-1', 'data_module.rl=True', 'model.grpo=True', 'data_module.num_workers=8'] [2026-02-22 23:55:59] worker-0 >> [rank0]: Traceback (most recent call last): [2026-02-22 23:55:59] worker-0 >> [rank0]: File "simlingo_training/train.py", line 202, in
[2026-02-22 23:55:59] worker-0 >> [rank0]: main() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/main.py", line 94, in decorated_main [2026-02-22 23:55:59] worker-0 >> [rank0]: _run_hydra( [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra [2026-02-22 23:55:59] worker-0 >> [rank0]: _run_app( [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/_internal/utils.py", line 457, in _run_app [2026-02-22 23:55:59] worker-0 >> [rank0]: run_and_report( [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/_internal/utils.py", line 223, in run_and_report [2026-02-22 23:55:59] worker-0 >> [rank0]: raise ex [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/_internal/utils.py", line 220, in run_and_report [2026-02-22 23:55:59] worker-0 >> [rank0]: return func() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/_internal/utils.py", line 458, in [2026-02-22 23:55:59] worker-0 >> [rank0]: lambda: hydra.run( [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/_internal/hydra.py", line 132, in run [2026-02-22 23:55:59] worker-0 >> [rank0]: _ = ret.return_value [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/core/utils.py", line 260, in return_value [2026-02-22 23:55:59] worker-0 >> [rank0]: raise self._return_value [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/hydra/core/utils.py", line 186, in run_job [2026-02-22 23:55:59] worker-0 >> [rank0]: ret.return_value = task_function(task_cfg) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "simlingo_training/train.py", line 198, in main [2026-02-22 23:55:59] worker-0 >> [rank0]: trainer.fit(model, data_module, ckpt_path=resume_path) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 538, in fit [2026-02-22 23:55:59] worker-0 >> [rank0]: call._call_and_handle_interrupt( [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/trainer/call.py", line 46, in _call_and_handle_interrupt [2026-02-22 23:55:59] worker-0 >> [rank0]: return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/strategies/launchers/subprocess_script.py", line 105, in launch [2026-02-22 23:55:59] worker-0 >> [rank0]: return function(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 574, in _fit_impl [2026-02-22 23:55:59] worker-0 >> [rank0]: self._run(model, ckpt_path=ckpt_path) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 981, in _run [2026-02-22 23:55:59] worker-0 >> [rank0]: results = self._run_stage() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1025, in _run_stage [2026-02-22 23:55:59] worker-0 >> [rank0]: self.fit_loop.run() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/fit_loop.py", line 205, in run [2026-02-22 23:55:59] worker-0 >> [rank0]: self.advance() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/fit_loop.py", line 363, in advance [2026-02-22 23:55:59] worker-0 >> [rank0]: self.epoch_loop.run(self._data_fetcher) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/training_epoch_loop.py", line 140, in run [2026-02-22 23:55:59] worker-0 >> [rank0]: self.advance(data_fetcher) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/training_epoch_loop.py", line 250, in advance [2026-02-22 23:55:59] worker-0 >> [rank0]: batch_output = self.automatic_optimization.run(trainer.optimizers[0], batch_idx, kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 190, in run [2026-02-22 23:55:59] worker-0 >> [rank0]: self._optimizer_step(batch_idx, closure) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 268, in _optimizer_step [2026-02-22 23:55:59] worker-0 >> [rank0]: call._call_lightning_module_hook( [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/trainer/call.py", line 167, in _call_lightning_module_hook [2026-02-22 23:55:59] worker-0 >> [rank0]: output = fn(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/core/module.py", line 1306, in optimizer_step [2026-02-22 23:55:59] worker-0 >> [rank0]: optimizer.step(closure=optimizer_closure) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/core/optimizer.py", line 153, in step [2026-02-22 23:55:59] worker-0 >> [rank0]: step_output = self._strategy.optimizer_step(self._optimizer, closure, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/strategies/ddp.py", line 270, in optimizer_step [2026-02-22 23:55:59] worker-0 >> [rank0]: optimizer_output = super().optimizer_step(optimizer, closure, model, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/strategies/strategy.py", line 238, in optimizer_step [2026-02-22 23:55:59] worker-0 >> [rank0]: return self.precision_plugin.optimizer_step(optimizer, model=model, closure=closure, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/plugins/precision/deepspeed.py", line 129, in optimizer_step [2026-02-22 23:55:59] worker-0 >> [rank0]: closure_result = closure() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 144, in call [2026-02-22 23:55:59] worker-0 >> [rank0]: self._result = self.closure(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context [2026-02-22 23:55:59] worker-0 >> [rank0]: return func(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 138, in closure [2026-02-22 23:55:59] worker-0 >> [rank0]: self._backward_fn(step_output.closure_loss) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 239, in backward_fn [2026-02-22 23:55:59] worker-0 >> [rank0]: call._call_strategy_hook(self.trainer, "backward", loss, optimizer) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/trainer/call.py", line 319, in _call_strategy_hook [2026-02-22 23:55:59] worker-0 >> [rank0]: output = fn(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/strategies/strategy.py", line 212, in backward [2026-02-22 23:55:59] worker-0 >> [rank0]: self.precision_plugin.backward(closure_loss, self.lightning_module, optimizer, *args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/pytorch_lightning/plugins/precision/deepspeed.py", line 117, in backward [2026-02-22 23:55:59] worker-0 >> [rank0]: deepspeed_engine.backward(tensor, *args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/utils/nvtx.py", line 18, in wrapped_fn [2026-02-22 23:55:59] worker-0 >> [rank0]: ret_val = func(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/engine.py", line 2079, in backward [2026-02-22 23:55:59] worker-0 >> [rank0]: self.allreduce_gradients() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/utils/nvtx.py", line 18, in wrapped_fn [2026-02-22 23:55:59] worker-0 >> [rank0]: ret_val = func(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/engine.py", line 1980, in allreduce_gradients [2026-02-22 23:55:59] worker-0 >> [rank0]: self.optimizer.overlapping_partition_gradients_reduce_epilogue() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 869, in overlapping_partition_gradients_reduce_epilogue [2026-02-22 23:55:59] worker-0 >> [rank0]: self.independent_gradient_partition_epilogue() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 760, in independent_gradient_partition_epilogue [2026-02-22 23:55:59] worker-0 >> [rank0]: self.reduce_ipg_grads() [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 1369, in reduce_ipg_grads [2026-02-22 23:55:59] worker-0 >> [rank0]: self.average_tensor(self.ipg_buffer[self.ipg_index].narrow(0, 0, self.elements_in_ipg_bucket)) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 1131, in average_tensor [2026-02-22 23:55:59] worker-0 >> [rank0]: self.allreduce_and_scatter(buckets[bucket_key], [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 1039, in allreduce_and_scatter [2026-02-22 23:55:59] worker-0 >> [rank0]: self.allreduce_and_copy_with_multiple_ranks(small_bucket, [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 1012, in allreduce_and_copy_with_multiple_ranks [2026-02-22 23:55:59] worker-0 >> [rank0]: allreduced = self.allreduce_bucket(small_bucket, log=log, divide=divide, process_group=process_group) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 1502, in allreduce_bucket [2026-02-22 23:55:59] worker-0 >> [rank0]: dist.all_reduce(tensor_to_allreduce, group=process_group) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/comm/comm.py", line 117, in log_wrapper [2026-02-22 23:55:59] worker-0 >> [rank0]: return func(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/comm/comm.py", line 496, in all_reduce [2026-02-22 23:55:59] worker-0 >> [rank0]: return cdb.all_reduce(tensor, op, group, async_op) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/torch/_dynamo/eval_frame.py", line 451, in _fn [2026-02-22 23:55:59] worker-0 >> [rank0]: return fn(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/deepspeed/comm/torch.py", line 152, in all_reduce [2026-02-22 23:55:59] worker-0 >> [rank0]: return torch.distributed.all_reduce(tensor=tensor, op=op, group=group, async_op=async_op) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/torch/distributed/c10d_logger.py", line 75, in wrapper [2026-02-22 23:55:59] worker-0 >> [rank0]: return func(*args, **kwargs) [2026-02-22 23:55:59] worker-0 >> [rank0]: File "/home/conda_env/simlingo1/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 2219, in all_reduce [2026-02-22 23:55:59] worker-0 >> [rank0]: work = group.allreduce([tensor], opts) [2026-02-22 23:55:59] worker-0 >> [rank0]: RuntimeError: Detected mismatch between collectives on ranks. Rank 0 is running collective: CollectiveFingerPrint(SequenceNumber=990, OpType=ALLREDUCE, TensorShape=[127634432], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))), but Rank 1 is running collective: CollectiveFingerPrint(SequenceNumber=990, OpType=ALLREDUCE, TensorShape=[128226432], TensorDtypes=Half, TensorDeviceTypes=TensorOptions(dtype=float (default), device=cuda, layout=Strided (default), requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))).Collectives differ in the following aspects: Tensor Tensor shapes: 127634432vs 128226432