Skip to content

feat(attention): add CP backward drift validation - #284

Merged
maxiaosong1124 merged 10 commits into
testfrom
codex/ws2-pr8-cp-attention-backward
Aug 24, 2026
Merged

feat(attention): add CP backward drift validation#284
maxiaosong1124 merged 10 commits into
testfrom
codex/ws2-pr8-cp-attention-backward

Conversation

@inaniloquentee

@inaniloquentee inaniloquentee commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Scope

PR8 fixes the strict backward schedule for CP prefill and chunked-prefill.

Contract

Area Enforced behavior
Gradient order Canonical batch, query, and global-KV traversal
Reduction FP32 accumulation with fixed logical merge order
Outputs Covers dQ, dK, and dV, including CP ownership
Split-KV Disabled in strict backward mode

Validation

Check Result
Strict backward suite 57 passed
Integrated 8xH100 backward gate Passed: dQ/dK/dV max abs 0.0 across 2/4/8 ranks

Boundary

This PR owns backward arithmetic order and gradient coverage. PR285 and #294 record the production H100 evidence.

Commit: 9e5c400

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 766feba7-af96-4f96-98c0-98aee768c941

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@inaniloquentee
inaniloquentee changed the base branch from feat/ws2-cp-attention-reference-pr3 to test August 12, 2026 16:13

@Flink-ddd Flink-ddd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@maxiaosong1124
maxiaosong1124 merged commit 4270add into test Aug 24, 2026
4 of 6 checks passed
zhangj1an added a commit that referenced this pull request Aug 24, 2026
Also makes the strict path TP-degree bitwise invariant.

Merge resolution (12 conflicted files):
- registry.py: test grew its own get_attention_op / _attention_policy_mismatch
  / _platform / _get_or_create_backend, keyed off a `ws2_attention` priority
  list and a flat _attention_capabilities dict. Dropped our parallel
  implementation and rebuilt on test's, keeping only the register_attention_
  backend seam (a vendor-conditional backend cannot be declared in a static
  list) and the auto-under-CP guard. Corrects an error on our side:
  requested_backend="deterministic" was rejected by copying a logprob-dispatch
  rule, but AttentionBackendCapability admits "deterministic" and it is test's
  default.
- csrc/ops.cpp: test registers the CUDA-IPC collectives unguarded, but their
  declarations stay ROCm-guarded, so taking that side fails to compile on ROCm.
  Kept our guard, which is the version this ROCm build actually succeeded with.
- flashinfer_paged_attention.py (9 hunks), ws2_p2p_nccl_*.py (3): test reverted
  to CUDA-only expressions (hardcoded cuda_ag_rs, direct StrictFlashAttention4
  Core). Ours is the platform-aware superset.
- cp_attention.py: took test's new saved-forward-state validation (#284).
- test_flashinfer_pr7_attention.py: the two sides were different tests at the
  same position (ROCm core accepted vs reference core rejected). Kept both.
- setup.py and pyproject.toml are EMPTY on test (0 bytes, from 3e04a63) and
  pyproject.toml auto-merged to empty with no conflict. Restored both; test
  cannot build a native extension in its current state.

TP-degree invariance: every launch is now pinned to one batch row and one KV
group. AITER's reduction order is launch-shape dependent, so a head shard
computed under TP=4 was not bit-identical to the same shard under TP=8 (up to
7.8125e-03 at some shapes). Pinning removes it: out/lse/dQ/dK/dV are bitwise
equal at TP=2/4/8 across S=512..4096, at roughly 3x forward time. The
cross-config contract therefore no longer binds the TP degree -- doing so would
reject comparisons that are in fact identical -- and checks only what changes
the arithmetic.

ROCm test skips: CUDA reports through the same device API on ROCm, so
device_count guards do not exclude it and CUDA-exclusive tests failed instead
of skipping. Added a `cuda_only` marker plus a conftest hook, applied to the
CUDA-IPC collectives, the CUDA det_gemm K-tree cases, and the FA4-selection
test (ROCm correctly resolves to the AITER core there, so its monkeypatch is
never consulted).

Attention suites: 323 passed, 42 skipped.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QfN3b2ep5DvxVDir7J36j3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants