fix: wire on_before_collect and on_rollout_complete callbacks through rollout_func#243
Merged
Conversation
Add a truncation check after both generation paths (Outlines constrained and HF unconstrained) in generate_fn. When the output length reaches max_new_tokens - 1, a warning is logged suggesting to increase max_new_tokens or enable constrained_decoding. This helps diagnose cases where the model generates excessively long reasoning that gets cut off before producing a parseable action. Also replaced the tautological truncation tests in test_trl_robustness.py (which reimplemented the check logic inline) with tests that exercise the actual generate_fn code path by calling it through the rollout function with mocked torch and model.generate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… rollout_func The GRPOTrainer wrapper accepted on_before_collect and on_rollout_complete callbacks but silently ignored them. HookBridge stored them but only implemented on_step_end (for on_step_complete). TRL has no pre-rollout callback event, so these must fire from within make_waa_rollout_func. Changes: - Add on_before_collect and on_rollout_complete params to make_waa_rollout_func - Fire on_before_collect(task_id, env) before each episode - Fire on_rollout_complete(rollout_dict, gen_idx) after each episode - Wrap both in try/except so broken callbacks cannot crash training - Pass callbacks from GRPOTrainer.train() to make_waa_rollout_func - Remove these two callbacks from HookBridge (keep only on_step_complete) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
on_before_collectandon_rollout_completecallbacks throughmake_waa_rollout_func()instead of silently storing them in HookBridge (which only implementedon_step_end)on_before_collect(task_id, env)before each episode andon_rollout_complete(rollout_dict, gen_idx)after each episode, with try/except wrapping so broken callbacks cannot crash trainingon_step_complete(the only callback that maps to a TRL TrainerCallback event)Test plan
test_on_before_collect_fires-- verify callback called with correct (task_id, env) argstest_on_rollout_complete_fires-- verify callback receives reward and gen_idxtest_callbacks_optional-- verify rollout_func works when callbacks are Nonetest_broken_callback_does_not_crash_training-- verify try/except wrappingtest_wrapper_passes_callbacks_to_rollout_func-- verify GRPOTrainer forwards callbacks to make_waa_rollout_func via source inspection🤖 Generated with Claude Code