Conversation
YanhuiDua
force-pushed
the
refactor/prepare-train-data-into-agent-loop
branch
from
September 20, 2026 12:09
7d6b5a9 to
4bb5b80
Compare
Collaborator
Author
|
@claude review |
Contributor
|
Claude: Summary本次重构将训练数据构造按归属拆分:per-sample 全序列 token 字段( 核心原理实现与单测
其他 Issues未发现 |
…troller - AgentLoop.canonicalize_train_fields (base + localhost/sandbox overrides) builds the unified full-sequence train fields (input_ids/labels/logprobs) at generation time; semantic holes are baked into labels by the loops. - RolloutState drops response_mask; labels become the only supervision carrier. agent_loop_type records the producing loop class name and AGENTIC_AGENT_LOOP_TYPES discriminates agentic full-sequence samples. - TrainingController.fit accepts list[list[RolloutState]] and absorbs validation, session-clustered advantages, shift/tensorization, seq_ctx, teacher fields and data_info; BaseRLTrainer._prepare_train_data is gone. - calculate_group_effective_response_masks now bakes token staleness into labels in place (monotone, convergent) and its agentic exclusion uses agent_loop_type instead of the input_ids/labels presence heuristic.
…ut conversion - response_ids now denotes the contiguous suffix of input_ids after the prompt (env/tool tokens included) in every loop; localhost/sandbox export input_ids[len(prompt_ids):] so response_model_steps stay aligned with the full response region. - Token staleness baking becomes branch-free: effective mask = semantic mask (labels != -100 on the suffix) * per-token staleness mask; the zero-prompt suffix state becomes eligible and agent_loop_type plus AGENTIC_AGENT_LOOP_TYPES are removed. - data_info stats: prompt_len reports the original prompt length and response_len the supervised (LLM-generated) token count; env/tool injected tokens count in neither. - _rollout_groups_to_colate_items is phase-split into session reward clustering, group advantage estimation, per-state ColateItem conversion and data_info summarization.
YanhuiDua
force-pushed
the
refactor/prepare-train-data-into-agent-loop
branch
from
September 21, 2026 12:13
7c29de9 to
066bd24
Compare
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
Training data construction is split by ownership: per-sample token fields are now built at generation time inside
AgentLoop, while step-level conversion (validation, advantage, shift, tensorization, seq_ctx/teacher fields,data_info) moves intoTrainingController.BaseRLTrainer._prepare_train_datais deleted.AgentLoop.canonicalize_train_fields(base + localhost/sandbox overrides) builds the unified full-sequenceinput_ids/labels/logprobsconvention; semantic holes (tool/env tokens) are baked intolabelsas-100by the loops themselves.RolloutStatedropsresponse_mask;labelsbecomes the only supervision carrier. Newagent_loop_typerecords the producing loop class name (type(self).__name__), andAGENTIC_AGENT_LOOP_TYPESdiscriminates agentic full-sequence samples (None/unregistered types fall back to prompt+response semantics).TrainingController.fitacceptslist[list[RolloutState]]and absorbs group validation, session-clustered advantages, the one-position shift, tensorization, seq_ctx/teacher fields anddata_infostatistics.calculate_group_effective_response_masksnow bakes token staleness intolabelsin place (clearing is monotone, so replay-buffer expiry checks and the train-batch bake converge to identical labels); the agentic exclusion condition now keys onagent_loop_typeinstead ofinput_ids/labelspresence, which would have silently disabled token staleness after canonicalization.Behavior changes
FAILEDat generation time (their group is skipped) instead of asserting at training time.task_adv_weight == 0trains with zero advantage; with weight > 0 it still raises (crash semantics preserved, location moved).prepare_datatiming key disappears; conversion cost is now inside thetrainingtimer.prompt_len/response_lenstats keep exact denominators for reasoning samples; only mixed-form edge cases may drift by +/-1 (log metrics only).ProduceBatchResult impact:
leftover_*/raw_rewards*/produced_*counts unchanged; generation-time canonicalize failures can flip individual samples toFAILED, which converts to group-level skips via validation (affectsrollout_statescontent, not the accounting).RoutedExperts impact: not affected;
routed_expertsis still attached toseq_ctxby the controller, ownership and release paths unchanged.Ray concurrency impact: not affected; no agent-loop actor methods, decorators, or concurrency groups changed.
Test plan
tests/rl/test_prepare_train_data.pyrewritten as contract tests forcanonicalize_train_fields(base + both agentic overrides) andTrainingController._convert_rollout_groups, including the packed-alignment regression (advantage used to be one position longer than input_ids).reset_rollout_responseclears canonical train fields, canonicalized prompt+response states remain staleness-eligible.pytest tests/rl).