Skip to content

[tests] Add DeepSeek V4 integration smoke - #4490

Merged
tianyu-l merged 6 commits into
pytorch:mainfrom
YeonwooSung:pr/v4-qwen38-integration-smoke
Sep 10, 2026
Merged

tianyu-l merged 6 commits into
pytorch:mainfrom
YeonwooSung:pr/v4-qwen38-integration-smoke

Conversation

@YeonwooSung

@YeonwooSung YeonwooSung commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Why

DeepSeek V4 (#3634) already has debug recipes and CPU unit tests, but it does not appear in tests/integration_tests/models.py. The models suite never exercises V4 sparse attention / mHC / hash routing end to end.

What

  • Add a 4-GPU Fake-PG V4 case: FSDP2 + TP2 + EP2, no CP (V4 update_from_config rejects CP). Matches the smoke command in the V4 README. Skip ROCm; no golden.
  • Register the name in test_models_select_fake_and_real_pg_cases and document it in tests/README.md.

An earlier revision also added a Qwen3.8 twin of the existing Qwen3.5 FSDP4+TP2+EP4 case. That is dropped: Qwen3.8 shares the Qwen3.5 architecture, so the extra job did not add coverage.

Test plan

  • AST-parse the edited Python files
  • CPU: pytest tests/unit_tests/cpu/test_integration_test_definitions.py -k fake_and_real
  • GPU CI models suite Fake-PG: deepseek_v4_fsdp+tp+ep

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 5, 2026
Comment thread tests/integration_tests/models.py Resolved
@YeonwooSung YeonwooSung changed the title [tests] Add DeepSeek V4 and Qwen3.8 integration smoke [tests] Add DeepSeek V4 integration smoke Sep 5, 2026
@tianyu-l

tianyu-l commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

could you take a look at the CI failure

@YeonwooSung

Copy link
Copy Markdown
Contributor Author

The Fake-PG failure is only deepseek_v4_fsdp+tp+ep. It dies in verify_module_protocol() because V4 always attaches mtp_layers as torch.nn.ModuleList — even when n_mtp_layers=0, so the empty list is still a submodule. I don’t think we should copy V3’s mtp_layers = None path. I’ll keep V4’s always-a-list shape and switch the container to torchtitan.protocols.module.ModuleList.

@tianyu-l

tianyu-l commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

now a different error

@YeonwooSung

Copy link
Copy Markdown
Contributor Author

verify_module_protocol is past. The new Fake-PG failure is the first MoE hash layer: scores is [256, 4] but hash ids are [512, 3]. With TP2 and default sequence parallel, hidden is sharded on T, while tid2eid[input_ids_T] still sees the full sequence. I’d rather not shrink the smoke topology and hide this. I can take a follow-up to align V4 hash-routing shard of input_ids_T with x — okay to do that here, or as a separate PR?

@tianyu-l

tianyu-l commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

@YeonwooSung thanks for investigation, please do it in this PR

@YeonwooSung

Copy link
Copy Markdown
Contributor Author

Have fixed the issues in the previous CI. WIll wait for the next CI run :)

@tianyu-l

tianyu-l commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

see results

Cover the debug models that already have CPU tests but no models-suite
entry. V4 uses the README 4-GPU FSDP2+TP2+EP2 layout without CP. Qwen3.8
reuses the Qwen3.5 MoE FSDP4+TP2+EP4 topology and keeps PP off so the
case stays Fake-PG compatible.
Qwen3.8 shares the Qwen3.5 architecture and the same FSDP4+TP2+EP4
Fake-PG job. Remove that extra case and the topology unit test. Leave
the V4 FSDP2+TP2+EP2 smoke, which is a different model.
Keep V4's always-a-list shape. torch.nn.ModuleList fails
verify_module_protocol even when empty.
Hash layers index tid2eid with input_ids_T. Under default TP+SP+EP the
MoE activation is already sharded on T, but token IDs stayed TP-replicated,
so Fake-PG smoke failed with scores[256, 4] vs hash ids[512, 3].

Give 1D token IDs a sequence-parallel placement and redistribute to it
only on the SP+EP path, where x is not all-gathered. Other combinations
keep the full TP-replicated ids to match x.
@YeonwooSung
YeonwooSung force-pushed the pr/v4-qwen38-integration-smoke branch from de14af6 to 14c711d Compare September 8, 2026 05:52
@YeonwooSung

Copy link
Copy Markdown
Contributor Author

Looked at the latest Fake-PG failure. This one is past both earlier issues: verify_module_protocol passes, the model builds, and the MoE hash routing no longer mismatches (Training starts at step 1 is reached). It now dies at the step-1 finite check with a non-finite loss/grad_norm.

The No valid triton configs ... triton_flex_attention Required: 163840 Hardware limit:101376 lines are autotuning noise, not the cause: with V4's head_dim=256, the large-block FlexAttention configs exceed the A10G's ~100KB shared memory and get ignored, but the autotuner still finds valid small-block kernels (fwd triton_flex_attention_6, bwd triton_flex_attention_backward_15) and attention runs. The real failure is a genuine non-finite grad_norm from the backward.

This branch was based on an older main (390e298), predating a few relevant fixes, most notably #4484 ([router] Fp32 for backward), which keeps the MoE router gate in fp32 through backward instead of only fp32 forward autocast. Since the failure is specifically a non-finite grad_norm (backward), that is the most likely fix. I rebased onto current main (also picks up #4513, #4498, #4497; goldens were bumped in #4484 so the old base was numerically stale) and re-ran CI. The smoke topology (FSDP2+TP2+EP2, seq 512) is unchanged.

If the non-finite persists after the rebase, it points to a V4-specific training-numerics issue this smoke is the first to exercise end-to-end (V3 debug trains fine on the same runner), and I would rather report/track that than shrink the topology to hide it. Will watch the run.

The deepseek_v4_fsdp+tp+ep smoke fails under Fake PG: its
sequence-parallel collectives return activations that alias their
inputs, corrupting a saved-for-backward tensor and exploding grad_norm
to non-finite at step 1. The same FSDP2+TP2+EP2 config trains cleanly
on a real 4-GPU PG (loss 8.0 -> 3.7, grad_norm ~2-4 over 10 steps).

Mark the case use_real_pg=True so it runs in the 8-GPU real-PG suite
and is skipped by the 1-GPU Fake PG job, mirroring the existing
varlen_attn+per_op_sac workaround (pytorch#4149). Keep it coverage-only (no
numerical golden). Update the Fake-PG compatibility guard, the
selection unit test, and the test README accordingly.
@YeonwooSung

Copy link
Copy Markdown
Contributor Author

Reproduced the failure on a single L4 and debugged it down to root cause, then moved the case to a real PG. The path:

  1. Reproduced deepseek_v4_fsdp+tp+ep under Fake PG on one L4 (torch nightly cu130): same rc=134, Loss or gradient norm is not finite at step 1.
  2. Not a NaN, a grad explosion. Forward is fine (loss ~7.4); grads are all finite but reach ~1e19, so the fp32 grad-norm overflows to inf. The No valid triton configs FlexAttention lines are just A10G/L4 smem autotuning noise (it still compiles on smaller blocks).
  3. Bisected the parallelism: no-parallel / FSDP-only / EP-only / TP-with-SP-off all train fine (grad_norm ~2.8-4.2); only TP + SP explodes. This also rules out the hash-routing input_ids_T change here, since that path only runs under SP+EP while the blow-up happens at TP+SP with ep=1.
  4. Confirmed it is Fake-PG-specific. Ran the exact same FSDP2+TP2+EP2 config on a real 4-GPU PG (torchrun, 4x L4): it trains cleanly for 10 steps (loss 8.0 -> 3.7, grad_norm ~2-4). So the model/sharding is correct; under Fake PG the sequence-parallel collectives return activations that alias their inputs, which corrupts a saved-for-backward tensor and drives the explosion.

Given that, I marked the case use_real_pg=True so it runs in the 8-GPU real-PG suite and is skipped by the 1-GPU Fake PG job — the same treatment as varlen_attn+per_op_sac (#4149), which is kept on a real PG for an analogous Fake-PG/spmd_types incompatibility. Verified on 4x L4: the real-PG harness case passes and the Fake-PG selection now skips it; the selection unit test and README are updated to match.

Comment thread tests/integration_tests/models.py Resolved
Comment thread tests/integration_tests/__init__.py Resolved
@Serendipity-matong

Copy link
Copy Markdown
Contributor

I prepared the MTP SPMD layout fix as a follow-up to this PR.
The baseline failed all four MTP layout checks on both ranks:

@YeonwooSung

Copy link
Copy Markdown
Contributor Author

Thanks for the fix! I looked at both commits. They target the MTP SPMD layouts, which apply to deepseek_v4_mtp_debugmodel (n_mtp_layers=1). This PR's smoke (deepseek_v4_fsdp+tp+ep) uses deepseek_v4_debugmodel with n_mtp_layers=0, so config.mtp_layers is None and that sharding block is skipped; the non-MTP changes only touch the non-SP branch while the smoke runs TP+SP. So these don't affect this PR's CI failure. I'd keep them in their own PR (#4521) rather than cherry-picking into #4490 -- happy to review there.

V4 does build and run under Fake PG (grad_norm just explodes to
non-finite), unlike the genuinely non-runnable checkpoint/PP/varlen
cases. use_real_pg=True already routes it to the real-PG suite, so the
extra incompatibility entry was redundant and semantically wrong.
@tianyu-l
tianyu-l merged commit f279747 into pytorch:main Sep 10, 2026
14 checks passed
@YeonwooSung
YeonwooSung deleted the pr/v4-qwen38-integration-smoke branch September 10, 2026 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants