Skip to content

[GDN] Use native Attention Gym summaries for context parallelism - #6167

Draft
liangel-02 wants to merge 2 commits into
mainfrom
liangel/gdn-cp-native
Draft

liangel-02 wants to merge 2 commits into
mainfrom
liangel/gdn-cp-native

Conversation

@liangel-02

@liangel-02 liangel-02 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

changes torchtitan to use gdn cp summaries in attention gym using warpdrive

Why

GDN context parallelism currently calls Attention Gym without selecting a backend. On Blackwell this still uses fused CP summaries, expanding each scalar decay gate across the key dimension to reuse KDA kernels. Attention Gym now has native scalar-GDN summaries that avoid that allocation and compute chunk factors on chip (upstream PR).

For packed BF16 Qwen3.5 with CP=2 on B200:

                         main                         this PR
GDN CP backend           fused                        warpdrive
Gate input               [1, T, H]                    [1, T, H]
Gate expansion           [1, T, H, 128] in FP32        none
Cross-rank communication all-gather state summaries   all-gather state summaries

What changed

  • Pass the existing chunk_kernel_options policy to context_parallel_gdn. Eligible SM100/SM103 inputs select warpdrive; deterministic mode, batch-invariant mode, and other devices retain fused execution.
  • Pin Attention Gym to public main 4d0d7912ebbab5d5a71739c786af8f03fd1bbce3: the current 0.0.20 release does not expose the new CP backend.
  • Mechanical dependency migration: update the renamed GDN/KDA autograd imports and registrations, the backend name, installation hint, and RL installation documentation. KDA's CP adapter is unchanged.
  • Add a real-kernel regression that checks outputs and all input gradients against the token recurrence and fails if scalar gates are expanded. Reuse the existing Qwen3.5 CP=2 integration recipe in the B200 suite.

Keeping the selection at the CP helper call reuses the existing routing and backend policy. Hard-coding warpdrive would bypass deterministic/device selection; implementing summaries inside TorchTitan would duplicate the upstream implementation.

Numerics

Compared against public TorchTitan main aa90d4abd45e92866dc2da24b9590030d4adc7e5, using separate editable environments with their respective Attention Gym dependencies. Both use PyTorch 2.16.0.dev20261117+cu134, CuTeDSL 4.8.1, BF16, seed 42, CP=2 with head-tail balancing, and two B200 GPUs.

Check Main PR Result
C4, 20 steps, deterministic Fused CP Fused CP Loss and gradient norm are bitwise identical at every step
C4, 20 steps, normal backend selection Loss 12.94815254 -> 2.88487983 Loss 12.94814491 -> 2.88725233 Both decrease; all losses and gradient norms finite
Normal-mode differences across all 20 steps Fused CP Native GDN CP Max absolute loss difference 0.0081892; max absolute gradient-norm difference 0.0673137 (4.247% max relative)

The native backend changes floating-point evaluation order, so its results are compared numerically rather than bitwise. These are short debug-model training checks, not 10M-context or production-scale convergence/performance measurements. No existing golden-loss file is changed.

C4 comparison recipe and commands

Save as agent_space/cp_numerics.py in each checkout:

import os
from tests.integration_tests.h100 import qwen35_debugmodel_mm_allgather_kv_cp2
from torchtitan.components.data import ConcatThenSplitPackingConfig, GrainDataLoader
from torchtitan.components.data.text_datasets import DATASETS
from torchtitan.observability.metrics import TensorBoardLogger

def c4_cp2():
    config = qwen35_debugmodel_mm_allgather_kv_cp2()
    config.dataloader = GrainDataLoader.Config(
        dataset=ConcatThenSplitPackingConfig(dataset=DATASETS["c4_test"]),
        shuffle=False,
    )
    config.debug.seed = 42
    config.debug.deterministic = os.environ.get("GDN_CP_DETERMINISTIC", "0") == "1"
    config.training.steps = 20
    config.metrics.loggers.append(TensorBoardLogger.Config())
    return config
GDN_CP_DETERMINISTIC=1 NGPU=2 MODULE=agent_space.cp_numerics CONFIG=c4_cp2 \
  ./run_train.sh --output-dir agent_space/c4-deterministic
GDN_CP_DETERMINISTIC=0 NGPU=2 MODULE=agent_space.cp_numerics CONFIG=c4_cp2 \
  ./run_train.sh --output-dir agent_space/c4-native

Compare all 20 full-precision loss_metrics/global_avg_loss and grad_norm scalars using scripts.loss_compare.extract_metrics_from_tensorboard.

Testing

  • 109 CPU tests pass: optional Attention Gym imports, CP attention adapters, and CP config validation.
  • 19 GDN/KDA/model tests pass, including the new native CP regression, independent-document numerics, deterministic backward, and batch-invariant recurrence.
  • B200 integration: python -m tests.integration_tests.run_tests agent_space/native-cp-integration-ready --test_suite b200 --test_name qwen35_mm_native_gdn_cp --ngpu 2 --gpu_arch b200 --no-parallel passes all 10 training steps with SPMD type checking enabled.
  • pre-commit run --all-files: formatting, lint, and other hooks pass. Pyrefly reports FSDPModule.set_unshard_in_current_stream missing in torchtitan/distributed/fsdp.py:622 with this PyTorch nightly; the identical error reproduces on unchanged main.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 17, 2026
@liangel-02

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @liangel-02's task in 2m 17s —— View job


Request changes -- review posted: the new native-CP test never runs in CI, and the attn-gym bump also changes the non-CP Blackwell kernel without numbers.

@claude claude Bot 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.

Verdict: Request changes -- The one-line CP fix is the right change. But the test that guards it never runs in CI, and the dependency bump also swaps the kernel on the non-CP Blackwell path, which the PR shows no numbers for.

What this PR does. ContextParallelInnerGDN.gdn_core now passes the existing chunk_kernel_options(...) to context_parallel_gdn, so packed bf16 CP on SM100/SM103 uses Attention Gym's warpdrive backend. That backend has native scalar-gate CP summaries. The PR also moves the attn-gym pin from 0.0.20 to a main commit, renames the cuDNN kernel classes to the warpdrive ones, adds a B200 GPU unit test, and adds a B200 CP=2 integration entry.

Example.

Qwen3.5, CP=2, packed bf16, B200, non-deterministic
  main: context_parallel_gdn(..., kernel_options=None) -> fused CP; g_1TH expanded to [1,T,H,128] fp32
  PR:   context_parallel_gdn(..., kernel_options=KernelOptions("warpdrive")) -> native summaries, no expansion
Qwen3.5, CP=1, B200
  main: chunk_gdn(..., backend="cudnn")      (attn-gym 0.0.20, cudnn extra)
  PR:   chunk_gdn(..., backend="warpdrive")  (attn-gym 4d0d791, no cudnn extra)  <- not measured in the PR

Must fix

  1. tests/unit_tests/gpu/models/qwen3_5/test_qwen3_5_deltanet.py:181 -- The new native-CP test always skips in CI: GPU unit tests run on A10G, and it isn't in the B200 workflow's explicit pytest list. The integration entry can't catch a revert to fused. Add the test to integration_test_b200.yaml.
  2. torchtitan/models/common/attention/linear_attention.py:58-72 -- The pin bump changes which kernel runs on the non-CP Blackwell training and RL-generator paths (cuDNN -> warpdrive). The docstring's perf justification was also deleted. Add a B200 non-CP numerics and perf comparison to the description, or state with an upstream link that it is a pure rename.

Should consider

  • tests/integration_tests/b200.py:140 -- The new entry exercises warpdrive CP but doesn't confirm that warpdrive actually ran, so it duplicates the H100 entry with the same config. That's fine as a smoke test on SM100. Mention in the PR that the backend selection is guarded by the unit test from item 1, not by this entry.
Details
  • Gate: the problem is real on main. Before this PR, cp_gdn.py:278 called context_parallel_gdn without kernel_options, so CP fell back to fused even on Blackwell. The fix is at the right layer: it reuses the existing policy, and the summaries are implemented upstream in meta-pytorch/attention-gym#904. The git pin has a TODO with a link, and torch_remat sets the precedent for git pins.
  • KDA CP (cp_kda.py:255) still passes no kernel_options. The PR says this is intentional. Vector gates don't need expanding, so this isn't a one-sided design problem.
  • The deterministic C4 run (fused vs fused, bitwise identical) does show that the fused path is unchanged across the attn-gym bump.
  • The CPU optional-import test updates and the attn_gym.py / RL README edits are mechanical and correct. The root requirements.txt is a symlink to .ci/docker/requirements.txt, so the new install hint resolves to the pinned dependency.

Not verified: whether warpdrive's non-CP kernels match the 0.0.20 cuDNN kernels numerically or in speed (needs a B200 run). A maintainer still needs to review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl 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.

1 participant