[BUG] ZeRO-3 ids come from process-wide counters, so ranks that built different models fail the rank-agreement checks

Aperta
#9,098 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@Achyuthan-S ci sta già lavorando.

Dal 26/11/2026.

  • #9176 di @Achyuthan-S — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Read partition_parameters.py around Init.param_id and _convert_to_deepspeed_param, parameter_offload.py around _register_deepspeed_module, then inspect the rank agreement checks in partitioned_param_coordinator.py and stage3.py. The issue suggests mapping parameter and module ids to positions within the engine and comparing those positions. Add a CPU test based on the reproduction: after only one rank builds an extra ZeRO-3 model, both ranks should train the same engine successfully, while genuinely different parameter or module order still triggers the checks.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
ZeRO-3 numbers parameters and modules with two counters that live for the whole process: Init.param_id (partition_parameters.py, set in _convert_to_deepspeed_param) and the mutable default count=[0] of DeepSpeedZeRoOffload._register_deepspeed_module (parameter_offload.py). The checks that ranks agree compare these ids as they are: the coordinator's trace checks in reset_step (partitioned_param_coordinator.py), the bucket check in stage3.py under enable_sanity_checks, and all_gather_coalesced in safe mode. So if one rank has built more ZeRO-3 parameters or modules than another earlier in the process, the same model gets different ids on the two ranks, and the first check fails although both ranks hold the same model.

This comes up when ZeRO-3 runs on some ranks before an engine over all of them, for example a trainer on some ranks and a rollout or reference model on others. @LiRunGuo hit it in #9074 (see #9076), which avoids it by building the engine over all ranks first.

To Reproduce
Master at e35282bdb, CPU, gloo, torch 2.8.0. Rank 1 alone builds a model under zero.Init, then both ranks train one engine:

# DS_ACCELERATOR=cpu torchrun --nproc_per_node 2 repro.py
import torch
import deepspeed
import deepspeed.comm as dist


class Net(torch.nn.Module):

    def __init__(self):
        super().__init__()
        self.layers = torch.nn.Sequential(torch.nn.Linear(8, 8), torch.nn.Linear(8, 8))

    def forward(self, x):
        return self.layers(x).square().mean()


deepspeed.init_distributed(dist_backend="gloo")
rank = dist.get_rank()
own_groups = [dist.new_group([r]) for r in range(dist.get_world_size())]

# Rank 1 alone builds a model under ZeRO-3, on a group of its own.
if rank == 1:
    with deepspeed.zero.Init(data_parallel_group=own_groups[rank]):
        Net()

# Then both ranks train one model together.
config = {
    "train_micro_batch_size_per_gpu": 2,
    "zero_allow_untested_optimizer": True,
    "zero_optimization": {
        "stage": 3,
        "stage3_param_persistence_threshold": 0
    },
}
model = Net()
engine, _, _, _ = deepspeed.initialize(model=model,
                                       model_parameters=model.parameters(),
                                       optimizer=torch.optim.SGD(model.parameters(), lr=0.1),
                                       config=config)
print(f"rank {rank}: ds_ids {[p.ds_id for p in model.parameters()]}", flush=True)
for step in range(2):
    loss = engine(torch.randn(2, 8))
    engine.backward(loss)
    engine.step()
    print(f"rank {rank}: step {step} done", flush=True)
rank 1: ds_ids [4, 5, 6, 7]
rank 0: ds_ids [0, 1, 2, 3]
rank 1: step 0 done
rank 0: step 0 done
  File "deepspeed/runtime/zero/partitioned_param_coordinator.py", line 269, in reset_step
  File "deepspeed/runtime/zero/utils.py", line 125, in assert_ints_same_as_other_ranks
RuntimeError: Detected a disagreement on list contents between rank0 and rank1:
 list length: 8
 rank0: [0, 1, 2, 3, 2, 3, 0, 1]
 rank1: [4, 5, 6, 7, 6, 7, 4, 5]

The check runs when the second step starts, after the first step has recorded the trace. When both ranks build the extra model, both get ids [4, 5, 6, 7] and training runs.

The module counter fails the same way. On #9076 (29223f9d3), which runs these checks over the partition group so that ZeRO-3 can train on ranks 1 and 2 of three, training there first and then one engine over all three ranks fails the module check (partitioned_param_coordinator.py:266): rank 0 has [0, 2, 2, 2, 3, 4, ...], ranks 1 and 2 have [4, 6, 6, 6, 7, 8, ...]. On master the engine on ranks 1 and 2 never gets that far: while it is built, it waits for rank 0 at a barrier over the world (stage3.py, _create_fp16_partitions_with_defragmentation), which is what #9076 fixes. For this run the engine over all ranks needs an mpu of its own; without one, ranks 1 and 2 keep the first engine's groups.mpu and use a different data-parallel group than rank 0 (#9081).

Expected behavior
The checks pass for the same model on every rank, whatever else each process built before, and still fail for a different set or order.

Possible fix
The ids themselves should stay unique within a process: other code keys on them, for example the NVMe parameter swapper names its files {ds_id}_param.tensor.swp. The checks could instead compare each id's position among the engine's own ids, as @LiRunGuo suggested on #9076. The engine knows its modules and parameters, so it can map each id to its index among them once, at init, and the checks compare those indices. I'm happy to send this with a test (ZeRO-3 on some ranks, then an engine over all of them, on CPU) if the direction looks right.

Lingua principale
Python
Stelle
43.3k
Fork
5.1k
Merge medio
5g 10h
PR unite (30g)
85

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepspeedai/DeepSpeed

Tutte le issue di deepspeedai/DeepSpeed

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.