draft(engine): preserve explicit loss reduction prototype - #4
Closed
EazyReal wants to merge 4 commits into
Closed
Conversation
Represent actor policy-gradient loss aggregation as an explicit distributed loss-reduction contract so token, sequence, prompt, and constant modes share the same engine boundary. Key changes: - Add LossReduction/LossTerm and migrate train/eval engine call sites - Add token_mean, seq_mean, prompt_mean, and constant actor reductions - Preserve variable prompt groups without rollout filtering changes - Reject unsupported teacher distillation with non-token aggregation - Fail fast on non-positive global loss normalizers
Centralize policy-gradient aggregation and route engine loss contracts through one validated reduction. Adapt the original callback-based engine API at the boundary while removing the PR-only helper signatures. Reuse rejection masks for distillation and fail fast for unsupported packed reductions. Key changes:\n- Move generic loss contracts into a dedicated API module\n- Replace duplicated actor aggregation helpers with PolicyGradientReduction\n- Preserve original callback calls across FSDP, Megatron, and Archon\n- Restore the original v2 RPC callback boundary
Keep the pre-PR TrainEngine callback contract as the stable extension boundary while exposing advanced reductions through explicit methods. Key changes: - Restore original trainer and abstract engine callback signatures - Harden distributed normalizers and policy reduction invariants - Keep KD rejection normalization partition invariant - Reject impossible M2PO configurations before training - Add compatibility and regression coverage across all backends Refs: areal-project#1443
Keep function documentation focused on behavior and contract rather than refactor history or compatibility rationale.
This was referenced Jul 18, 2026
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
15 tasks
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.
Purpose
This draft PR is an archival design surface for the broader engine-level
LossReduction/LossTermprototype that was removed from the publicloss-aggregation contribution.
The public, review-ready feature implementation is
areal-project#1546. It deliberately uses AReaL's existing
train_batch(loss_fn, loss_weight_fn)contract and does not change FSDP,Megatron, Archon, or the public engine API.
This PR preserves the exact former aggressive head (
2496822a) over its exactbase (
aea57eb6) so the design and tests remain inspectable if AReaL laterneeds independently normalized multi-term losses.
Prototype captured here
LossReductionand namedLossTermcontracts;train_batch_with_reduction/eval_batch_with_reductionadapters;Status
This is reference code, not merge-ready code. Before reuse, the abstraction
needs a production consumer and a fresh design pass. Known issues include:
active, even if
torch.wheremasks the forward scalar;value Megatron-Core may rescale in place;
non-negative values; and
for sum or multi-term reductions.
Keeping this as a separate draft prevents speculative engine surface from
obscuring the focused public feature while retaining the implementation and its
design history for future work.