[feat] Support training callbacks in SkyRL#1696
Draft
SumanthRH wants to merge 11 commits into
Draft
Conversation
Introduces an HF/Lightning-style callback API so users can hook training events without subclassing the trainer. Surfaces ten events (train, epoch, step, eval × start/end, plus on_save, on_log), passes a unified CallbackInput with always-populated counters + per-event optional fields (batch / metrics / logs / ckpt_path), and exposes a mutable TrainingControl for early-stop / force-save / force-eval requests. Wired into both SFTTrainer and RayPPOTrainer. Callbacks register via the callbacks= constructor arg or add_callback() post-construction. fully_async_trainer.save_checkpoints() forwards the base path so on_save receives a non-None ckpt_path. The baseline eval_before_train pass fires on_eval_start / on_eval_end / on_log on both trainers, and RL aligns post-loop global_step before firing on_save / on_train_end. Ships an example at examples/train/callbacks/ with an EarlyStopping callback, a custom Ray entrypoint, and a launcher script. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: SumanthRH <[email protected]>
Signed-off-by: SumanthRH <[email protected]>
Signed-off-by: SumanthRH <[email protected]>
Signed-off-by: SumanthRH <[email protected]>
Signed-off-by: SumanthRH <[email protected]>
Signed-off-by: SumanthRH <[email protected]>
Signed-off-by: SumanthRH <[email protected]>
Mirrors the structure of test_rl_callbacks.py: mocks dispatch + tokenizer, skips trainer.setup(), and exercises only the orchestration in SFTTrainer.train(). Same event-sequence + payload assertions as before, but no real FSDP / model load -> runs without GPUs. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: SumanthRH <[email protected]>
Signed-off-by: SumanthRH <[email protected]> # Conflicts: # skyrl/train/sft_trainer.py
Signed-off-by: SumanthRH <[email protected]>
…d more tests Signed-off-by: SumanthRH <[email protected]>
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 training callbacks in SkyRL for the SFT and RL training.
Training callbacks are a standard pattern to handle different training events as well as inject custom training behaviour (ex: early stopping). Historically, SkyRL has not prioritized such customization behaviours and users would instead subclass the trainer for this.
Design
The design for training callbacks is heavily inspired by HuggingFace's Trainer.
Core Types
CallbackInputdataclassTrainingControldataclass with mutable flags that callbacks can set to influence the trainer.TrainingCallbackclass, allowing users to define callbacks on training eventsFields populated per event
callback_input.batchcallback_input.metricscallback_input.logscallback_input.ckpt_pathon_train_starton_train_endon_epoch_starton_epoch_endon_step_starton_step_endon_eval_starton_eval_endon_saveon_logCallback Handler
This PR also defines a
CallbackHandlerfor handling a list of training callbacks. this is the primary interface for trainers to interact with callbacksRegistration
Constructor is the default path for adding callbacks, and add_callback is a convenient helper for adding callbacks post-init.
Example Usage
An example is provided in
examples/train/callbacks, adding the common early stopping callback:Test Plan
tests/backends/skyrl_train/gpu/gpu_ci/test_sft_callbacks.pywhich starts a dummy SFT run and sanity checks that the relevant callbacks have been triggeredLimitations
We do not add support for callbacks to the fully async trainer in this PR, and this will be done as a follow-up.
TODO: