Repository navigation
[Backend 9] refactor(objectives): pass the attention backend and SP groups at construction - #1212
Draft
maocheng23 wants to merge 5 commits into
Draft
maocheng23 wants to merge 5 commits into
maocheng23 wants to merge 5 commits into
Conversation
…struction build_bundle built the objective model and then set attributes on it: attention_backend, and under USP ring_group, ulysses_group and reduce_sequence_statistics, the last three read from process-global getters by configure_sequence_parallel. The EAGLE3 protocol read all four with getattr defaults, so a model built another way silently trained without them. - build_objective_model and ObjectiveModel take attention_backend= and sequence_parallel=; both are fixed for the model's lifetime. - training/sequence_parallel.py: SequenceParallel is the value that carries the axis's process groups; sequence_parallel_groups() reads them once. configure_sequence_parallel is removed. - The EAGLE3 protocol reads runtime.attention_backend and runtime.sequence_parallel. Recorded training trajectories are bit-identical to main (90 cases); the USP path needs flash_attn and GPUs and is not covered by them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…-09-construction # Conflicts: # specforge/algorithms/objectives/base.py # specforge/algorithms/objectives/registry.py # specforge/training/canonical.py
Review findings on the construction change: - build_objective_model checks attention_backend= against the protocol's attention_backends and sequence_parallel= against supports_sequence_parallel. P-EAGLE accepted a USP request it ignored; the CLI already refused it. - sequence_parallel_groups() refuses a process without the three groups: a statistic reduced over no group is pooled over the world. - Tests: the handoff in build_bundle is checked on a USP configuration up to the objective model's construction (it failed to be covered before); each getter is asserted to be read once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Second review round on the construction change: - SequenceParallel carries the product group (the ranks that share one sequence) in place of a caller-built reducer, refuses a missing group however it is constructed, and reduces loss statistics over that group itself. A callable no longer crosses into the objective model. - build_objective_model refuses what the CLI refuses: D-PACE weighting with sequence parallelism (chain weights are normalized within a shard), and the USP backend without its groups, which used to fail at the first cached attention step. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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.
Motivation
Next step of the training-backend design (#1177), stacked on the declarations PR.
build_bundleconstructed the objective model and then assigned to it:runtime.attention_backend, and under USPring_group,ulysses_groupandreduce_sequence_statistics, whichconfigure_sequence_parallel(runtime)read from the getters ofspecforge.distributed. The EAGLE3 protocol read all four withgetattr(runtime, name, None). So the same model class trained with or without its sequence-parallel groups depending on who built it, and nothing failed when they were missing. The design passes the one handle that may cross into a program, the process groups of a declared model-parallel axis, at construction.Change
build_objective_model,ObjectiveModelattention_backend=andsequence_parallel=; both are fixed for the model's lifetimetraining/sequence_parallel.pyconfigure_sequence_parallel(runtime)assigned three attributesSequenceParallel(ring_group, ulysses_group, sequence_group)is the value: three process groups, none of which may be missing, and it reduces loss statistics over the third itself;sequence_parallel_groups()reads the process's groups oncebuild_bundlegetattr(runtime, ..., None)runtime.attention_backend,runtime.sequence_parallelThe getters themselves (
specforge.distributed) are still process-global; replacing them with aTopologyvalue is the design's step 4 and is not part of this PR.Behaviour-change ledger
build_bundlebuildsruntime.attention_backend = ...after constructionconfigure_sequence_parallelbuild_objective_model(attention_backend=..., sequence_parallel=...)with a backend or an axis the protocol does not declareValueErrorSequenceParallelwithout one of its three groups, however it is builtValueErrorbuild_objective_modelwith the USP backend and no groups, or with groups and D-PACE weightingValueErrorat constructionruntime.reduce_sequence_statisticsafter constructionsequence_parallel=Evidence
main. They cover EAGLE3 and P-EAGLE with the default attention backend; they do not reach the cached rollout or USP.main's.test_eagle_backends.py): the rollout receives the groups the model was built with, and none by default;sequence_parallel_groups()binds the draft's sequence group into the reduction. The existing tests of Flex routing through the cached rollout and of trimming under a cross-rank reduction now pass their backend and reducer at construction.Not verified
flash_attnand GPUs.tests/test_algorithms/helpers/check_eagle_usp.py(a multi-GPU helper) andload_eagle3in the runtime fixtures are updated and compile; they were not run. The change on that path is three assignments becoming three constructor arguments.After Codex review
One read-only Codex round (
maocheng/backend-08-declarations...HEAD): no P0 or P1; it traced all six backend selections with and without groups to the same values atnew_rollout,cached.stepandreduce_statistics. Fixed in a follow-up commit:sequence_parallel_groups()refuses missing groups (row 5).build_bundlewas not covered: removing it left the tests green. A test now builds a USP configuration up to the objective model's construction and checks what arrives; it fails with the handoff removed.Second Codex round
A second read-only round on the fixes above: the four first-round findings confirmed fixed and no CLI configuration newly refused. Fixed in a further commit:
SequenceParallelcarried a reducer the caller had bound to a group; it now carries the group and binds the reduction itself, so no callable crosses into the objective model and a missing group is refused however the value is built (row 5). The USP backend without groups is refused at construction (row 6).Not changed: groups together with a local attention backend are still accepted. No data path builds sequence shards without the USP backend, and that combination is how the rule "trimming is skipped when statistics cross ranks" is tested on CPU.
🤖 Generated with Claude Code