Skip to content

[CP] Support Qwen3.5 GDN CP - #5184

Merged
acisseJZhong merged 6 commits into
mainfrom
add_gdn_cp_restacked
Oct 9, 2026
Merged

acisseJZhong merged 6 commits into
mainfrom
add_gdn_cp_restacked

Conversation

@acisseJZhong

Copy link
Copy Markdown
Contributor

Summary

Enable context parallelism for Qwen3.5's hybrid GatedDeltaNet/full-attention
decoder and multimodal input path.

  • GatedDeltaNet layers use Attention Gym's native context-parallel convolution
    history exchange and recurrent-state composition.
  • Full-attention layers use K/V all-gather CP with contiguous or head-tail
    partitioning, or Ulysses CP with contiguous partitioning.
  • Multimodal preprocessing shards vision-bank indices with token IDs so each
    rank can select the correct rows from replicated vision-encoder outputs.

GatedDeltaNet and full-attention layers share one TorchTitan CP mesh and token
partition.

Implementation

The integration follows Attention Gym's
delta-rule context-parallel example.

The local GatedDeltaNet implementation exposes shared convolution and recurrent
stages. The CP adapter replaces only the distributed pieces:

  • context_parallel_conv_history supplies each local Q/K/V convolution with
    the preceding tokens it needs; and
  • context_parallel_gdn composes recurrent state across sequence fragments and
    runs the local GDN computation.

GatedDeltaNetMetadata carries packed-sequence offsets and per-batch CP routing.
TorchTitan's load balancers expose their token fragments, and
ContextParallelRouting.from_fragments()
builds routing that matches the partition used to shard model inputs. Kimi K3
KDA now reuses the same routing path instead of duplicating partition logic.

Limitations

  • GatedDeltaNet CP supports contiguous and head-tail partitions; PTRR does not
    expose the contiguous token fragments required by the stateful kernel.
  • Consequently, the Qwen3.5 hybrid model supports contiguous or head-tail
    K/V all-gather CP. Ulysses requires contiguous partitioning.
  • Current TorchTitan partitioning requires equal-sized fragments, where T is
    the token count and C is the CP degree:
    • contiguous: T % C == 0
    • head-tail: T % (2 * C) == 0

Tests

Tested on NVIDIA H100 GPUs with Attention Gym commit f6d636e5 (merged
attention-gym#576).

  • Targeted unit tests: 80 passed, 2 subtests passed.
  • Two-GPU, 10-step integration tests passed for both K/V all-gather and
    Ulysses CP.

Deterministic BF16 runs compared CP=1 with CP=2 at commit 1b100f404, using
the same seed checkpoint (seed=42), 2,048 tokens per step, and 10 training
steps. CP=2 used Attention Gym CP for GatedDeltaNet and either head-tail K/V
all-gather or contiguous Ulysses for full attention. CUDA graphs were disabled
for all runs. Values come from full-precision TensorBoard metrics; diffs are
absolute percentages relative to CP=1. Collective reduction ordering changes,
so the trajectories are not expected to be bitwise identical.

Step CP=1 loss All-gather loss Diff Ulysses loss Diff
1 12.821151 12.821152 0.0000% 12.821152 0.0000%
5 6.671889 6.669287 0.0390% 6.669199 0.0403%
10 4.187472 4.187410 0.0015% 4.183589 0.0927%
Step CP=1 grad norm All-gather grad norm Diff Ulysses grad norm Diff
1 2.444962 2.445154 0.0079% 2.445154 0.0079%
5 4.393072 4.392580 0.0112% 4.393742 0.0153%
10 2.794782 2.791070 0.1328% 2.784653 0.3624%

@pytorch-bot pytorch-bot Bot added the ciflow/rl label Oct 8, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 8, 2026
@acisseJZhong
acisseJZhong added this pull request to stack #5185 October 8, 2026 23:12
@acisseJZhong
acisseJZhong marked this pull request as ready for review October 8, 2026 23:18
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 8, 2026

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume nothing changed from the other one that I stamped -- let me know if you need a new review

@acisseJZhong

Copy link
Copy Markdown
Contributor Author

nothing changed, I will wait until CI pass and land

@acisseJZhong
acisseJZhong marked this pull request as draft October 8, 2026 23:29
@pytorch-bot pytorch-bot Bot removed the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 8, 2026
@acisseJZhong acisseJZhong added ciflow/8gpu ciflow/h100.8 Trigger H100.8 CI ciflow/graph-trainer Run GraphTrainer CI ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/real-pg Run the full 8-GPU Real PG integration suite labels Oct 8, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/8gpu.
Currently recognized labels are

  • ciflow/b200
  • ciflow/docker
  • ciflow/fake-pg
  • ciflow/h100.8
  • ciflow/real-pg
  • ciflow/rl
  • ciflow/rocm

Please add the new label to .github/pytorch-probot.yml

@pytorch-bot

pytorch-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/graph-trainer.
Currently recognized labels are

  • ciflow/b200
  • ciflow/docker
  • ciflow/fake-pg
  • ciflow/h100.8
  • ciflow/real-pg
  • ciflow/rl
  • ciflow/rocm

Please add the new label to .github/pytorch-probot.yml

@acisseJZhong
acisseJZhong force-pushed the add_gdn_cp_restacked branch 3 times, most recently from 531d973 to 9407ba6 Compare October 9, 2026 02:37
@acisseJZhong

acisseJZhong commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

failure seems unrelated to this PR. Codex root caused to #5111

@acisseJZhong
acisseJZhong marked this pull request as ready for review October 9, 2026 07:13
@acisseJZhong
acisseJZhong merged commit 01b1b69 into main Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/graph-trainer Run GraphTrainer CI ciflow/h100.8 Trigger H100.8 CI ciflow/real-pg Run the full 8-GPU Real PG integration suite ciflow/rl ciflow/8gpu 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.

2 participants