feat(attention): add CP backward drift validation - #284
Open
inaniloquentee wants to merge 1 commit into
Open
Conversation
Signed-off-by: inaniloquentee <3051000145@qq.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements PR8 of #235 on top of PR3 / #238.
This PR extends the deterministic CP attention reference with training-side backward validation for causal prefill and chunked-prefill. It does not add a production fused backward kernel; it adds a correctness/reporting path that future fused training backends must match before they claim WS2 alignment.
Changes
DeterministicCPAttentionReferenceOp.backward_reference(...)to materialize deterministic training backward over the same CP forward graph.compare_cp_attention_backward(...)to compare CP=1 backward against a CP/chunked-prefill candidate.dq,dk, anddv.outand attention-domainlsedrift in the same report.global_block_indexmerge order, fp32 accumulation, final-write downcast, dtype metadata, and unsupported decode backward.cp_attentionin the generic operator checker soscripts/check_operator.py --op cp_attention --check-gradcan run.RoPE / TE Boundary
te_backward_oracle=not_used.not_supported.Testing
Local validation:
PYTHONPATH=. PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest tests/test_cp_attention.py -q- passed,23 passed.PYTHONPATH=. PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest tests/test_cp_attention.py tests/test_cp_attention_transformer_engine.py tests/test_operator_inputs.py -q- passed,41 passed, 1 skipped.PYTHONPATH=. PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest tests/test_attention.py -q -k "not large and not gpu"- passed,24 passed, 2 deselected.PYTHONPATH=. pytest rl_engine/tests/test_dispatch.py tests/test_attention.py tests/test_kv_cache_attention.py tests/test_cp_attention.py tests/test_cp_attention_transformer_engine.py tests/test_operator_inputs.py -q -k "not large and not gpu"- passed,85 passed, 1 skipped, 2 deselected.PYTHONPATH=. PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest tests/test_attention_correctness.py -q -rs- passed/collected,45 passed, 82 skippedlocally because CUDA FlashAttention and ROCm are unavailable.PYTHONPATH=. mypy --ignore-missing-imports rl_engine/- passed.mkdocs build --strict -f mkdocs.yaml- passed.pre-commit run --all-files- passed.PYTHONPATH=. py -3.13 scripts/check_operator.py --op cp_attention --candidate pytorch --dtype fp32 --device cpu --batch 1 --seq 4 --check-grad- passed.Qwen3-8B TP=2 CP=2 synthetic Attention smoke:
DCO
Signed-off-by: inaniloquentee <3051000145@qq.com>.Stack
Base:
feat/ws2-cp-attention-reference-pr3/ #238.Related: #235, #236, #238.