[BUG] HybridEngineRollout under AutoTP returns wrong tokens for tied-embedding models and diverges across ranks when sampling
Describe the bug
Three problems when HybridEngineRollout generates with a model trained under AutoTP, reproduced on master at ccdc60d5c (the rollout code is unchanged through 039bfc9f3).
1. Tokens are picked from each rank's vocabulary shard. When a model ties its output head to its input embedding and tensor_parallel.vocab_parallel_lm_head is unset, AutoTP replaces the head with a VocabParallelLinear (and the embedding with a VocabParallelEmbedding) with gather_output=False, so that the vocabulary-parallel training loss can use rank-local logits. The rollout calls the module directly, so every decode path (static with generate(), static graph, continuous, continuous graph) receives [batch, vocab / tp_size] logits on each rank and picks an index into that rank's shard:
- Rank 0's shard starts at id 0, so its local index is a real token id, but it only chooses among the first
vocab / tp_sizeids. - Every other rank returns a shard-local index, which is not the id of the token it chose.
- The next forward embeds each rank's token in the vocabulary-parallel embedding and sums the shards, so the model keeps decoding rank 0's choice while the other ranks' records hold unrelated ids.
Affected models include Qwen3-0.6B, Qwen3-4B and Qwen3-4B-Instruct-2507, which tie their embeddings. This is R-1 in RFC #8790.
2. Ranks of a tensor-parallel group can sample different tokens. With temperature > 0, each rank draws from its own accelerator random state. If the ranks of a tensor-parallel group are seeded differently, as is common when seeds are offset per rank for data parallelism, or if anything draws from the random state on one rank only, the group samples different tokens. The next forward then runs different inputs on each rank of the group, and its all-reduced activations mix them.
3. DeepSpeedStaticCache fails AutoTP's input consistency check. On the first forward after deepspeed.initialize, the engine broadcasts the forward's arguments across the tensor-parallel group and compares them with compare_tensors_in_structures (deepspeed/runtime/utils.py). That function skips Hugging Face Cache objects, but DeepSpeedStaticCache is not a Cache subclass and defines no equality, so the comparison falls back to identity and fails on every rank but the source. Since #9124, the static graph path and the continuous prefill pass a DeepSpeedStaticCache for full-attention models, so a rollout that runs before the first training step raises.
To Reproduce
Qwen3-0.6B (tied embeddings), fp32, launched with torchrun --nproc_per_node=2:
config = {"train_micro_batch_size_per_gpu": 1, "zero_optimization": {"stage": 0},
"hybrid_engine": {"max_out_tokens": 512}, "tensor_parallel": {"autotp_size": 2}}
engine, *_ = deepspeed.initialize(model=AutoModelForCausalLM.from_pretrained(name, dtype=torch.float32), config=config)
rollout = HybridEngineRollout(engine, tokenizer, HybridEngineRolloutConfig(use_graph_capture=False))
batch = rollout.generate(RolloutRequest(prompt_ids, prompt_attention_mask),
SamplingConfig(max_new_tokens=24, temperature=0.0))
# Compare batch.input_ids across ranks (all_gather_object) and with the same prompts on one GPU.
Results with 4 prompts and 24 new tokens:
| Check | Result |
|---|---|
1. Greedy rollout on each path: static, static graph (use_graph_capture=True), continuous (continuous_batch_size=4) and continuous graph |
The output head is VocabParallelLinear. On every path, rank 0 matches one GPU and rank 1 differs. For "The capital of France is", rank 0 continues " Paris. The capital of Italy is Rome. The capital of Spain is Madrid…" and rank 1 reports "kinHT Response TX TX_numService influService Response TX…" |
2. Sampled rollout (temperature=1.0) with vocab_parallel_lm_head: false, to isolate it from 1 |
With torch.manual_seed(1234) on both ranks, they agree. With torch.manual_seed(1234 + rank), they sample different tokens |
3. Static graph capture (use_graph_capture=True) as the first forward after deepspeed.initialize |
Both ranks raise AssertionError: Data inconsistency within the TP group. Please check the Dataloader implementation to ensure consistency. from check_dataloader_inputs_same_across_ranks |
For 1 and 2, a static eager rollout runs first, so the one-time input check passes before the graph and continuous paths run.
Expected behavior
- During
generate(), vocabulary-parallel output heads gather their logits, so every rank selects from the full vocabulary and every rank's records match the one-GPU result; training keeps rank-local logits for the vocabulary-parallel loss. - Each tensor-parallel group shares one random state for the call, so its ranks sample the same tokens whatever their seeds.
- The input check treats
DeepSpeedStaticCachelike a Hugging Face cache.
Related
RFC #8790 proposes R-1 (gather the logits), R-2 (select tokens on the shards) and R-3 (select inside the captured decode graph); this issue covers R-1, which needs no new kernels.
Environment
2× NVIDIA A100-SXM4-40GB (driver 595.71.05), PyTorch 2.14.1+cu130, CUDA 13.0, Python 3.12.15, Transformers 5.19.0.