[attention] Add Ulysses Anything backward - #14834
Draft
NancyFyong wants to merge 3 commits into
Draft
NancyFyong wants to merge 3 commits into
NancyFyong wants to merge 3 commits into
Conversation
Enable output gradients for uneven sequences and supported padded-head layouts using the existing attention backward and all-to-all helpers. Trim each gathered mask shard before concatenation to preserve token order. AI assistance (pi coding agent) was used for this change. Co-authored-by: pi coding agent Signed-off-by: NancyFyong <88076188+NancyFyong@users.noreply.github.com>
The attention dispatcher is shared, so H3-only coverage misses other model layouts. Reuse a parity worker and tiny configs for all nine models with a built-in context-parallel plan, retaining H3's multimodal cases. Keep serial fixture checks separate from pending accelerator parity tests. AI assistance (pi coding agent) was used for this change. Co-authored-by: pi coding agent Signed-off-by: NancyFyong <88076188+NancyFyong@users.noreply.github.com>
Helios gathers activations inside every block, so its replicated residual stream receives gradients that no reduction across context-parallel ranks can correct. Raise on backward instead of producing wrong gradients; inference is unaffected. Ulysses Anything scatters heads but not a per-head mask dimension, which LTX and LTX2 produce. Raise a clear error before communication instead of a shape mismatch inside the attention backend. Drop the LTX2 parity suite, whose context-parallel plan is fixed separately in huggingface#14317, and run LTX without its per-head mask. Document that replicated parameter gradients must be summed across context-parallel ranks. AI assistance (pi coding agent) was used for this change. Co-authored-by: pi coding agent Signed-off-by: NancyFyong <88076188+NancyFyong@users.noreply.github.com>
NancyFyong
added a commit
to NancyFyong/verl-omni
that referenced
this pull request
Sep 24, 2026
…lper Rename run_h3_transformer to h3_ulysses_forward and the private masked forward to _h3_masked_forward so the helper names describe the Actor Ulysses SP padding path. Document that variable-length Ulysses Anything training still awaits Diffusers backward support (huggingface/diffusers#14834). AI assistance (pi coding agent) was used for this change. Co-authored-by: pi coding agent Signed-off-by: NancyFyong <2742092809@qq.com>
This branch has not been deployed
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.
What does this PR do?
Adds output backward to
TemplatedUlyssesAnythingAttention, which currently raisesNotImplementedError.This follows the inference support in #12996. Searches for open Ulysses/backward and Ulysses-Anything work found no direct duplicate. Related #14341 and #14349 address backend layout and cuDNN mask handling rather than this missing backward path.
Draft: GPU validation remains pending. This does not implement Ring-Anything backward or extend causal attention, GQA, or hybrid Ring + Ulysses-Anything support.
Unsupported cases
Both cases below fail identically with the existing ordinary Ulysses backward and on
main, so they predate this change. This PR only makes the failures explicit.Helios training. Its plan gathers activations after attention and FFN inside every block. The residual stream, norms and modulation between them run replicated on each rank. The split backward only pads the local shard's gradient, so each rank combines the full residual gradient with a partial attention/FFN gradient. On two CPU/Gloo ranks:
Making the split backward all-gather recovered every parameter, but only with region-specific reductions. Supporting that would require changing the hook semantics, so Helios now raises on backward instead.
This check only triggers on backward. Inference and grad-enabled forward passes are unchanged.
Per-head masks (LTX, LTX2). Their processors expand the text mask to
(B, heads, 1, S). Ulysses Anything scatters heads but not the mask's head dimension. Previously this crashed inside the attention backend with a shape mismatch; it now raises a clearValueErrorbefore any communication. Head-broadcast masks are unaffected._cp_planappears copied from LTX-1 and fails underenable_parallelism()(crash + one silent-correctness hazard) #14316.Model test coverage
Each model uses its existing real class and tiny tester configuration, with model-specific inputs for uneven sequences. H3 retains T2VA/FL2VA/Ref2VA-style packed layouts.
The shared worker compares every output, loss, and parameter gradient against an identically initialized serial model. Parameter gradients are SUM-reduced across CP ranks before comparison. On two CPU/Gloo ranks with even-length fixtures, Flux, Flux2, Qwen-Image, Wan, ChronoEdit and LTX matched exactly under SUM, and failed on every parameter under MEAN.
Models without a built-in CP plan are outside this matrix; their SP support is not claimed.
Validation
Python 3.11.13, PyTorch 2.13.0+cu129, CPU-only. The source checkout and isolated Hugging Face Hub 1.31.0 dependency were selected through
PYTHONPATH.Results:
Through the real
enable_parallelismpath on two CPU/Gloo ranks:The original attention regression reproduced the missing-backward exception. After adding backward, the four-rank masked case exposed the mask-assembly defect and passed after trimming individual shards.
All passed. No new runtime dependency is introduced.
Final self-review notes
AI assistance (pi coding agent) was used. The complete diff was reviewed against the repository rubric. The human submitter reviewed every changed line and approved the public wording.
Verdict: NEEDS CHANGES before merge.
Before submitting
Who can review?
Feedback on the Ulysses-Anything backward contract and distributed test coverage is welcome. Accelerator validation is required before marking this PR ready.