feat: add standard PPO training with GAE and value critic (Transformers/FSDP) - #256
Open
xxyyrr598 wants to merge 5 commits into
Open
feat: add standard PPO training with GAE and value critic (Transformers/FSDP)#256xxyyrr598 wants to merge 5 commits into
xxyyrr598 wants to merge 5 commits into
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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.
PR type
PR information
Summary
This PR adds the first standard PPO + GAE training pipeline to Twinkle, on top of the existing GRPO/DPO RL stack. It introduces the missing PPO components — a token-level GAE advantage estimator, a full-parameter value critic, and a clipped value loss — and provides an end-to-end GSM8K cookbook with LoRA policy + full-parameter critic + vLLM sampler.
What's included
New components
cookbook/rl/ppo/— end-to-end GSM8K PPO training script & shell launcher:forward_only(disable_lora=True)(no extra ref GPUs)ppo_epochsmini-batch updates over fixed rolloutssrc/twinkle/advantage/gae.py—GAEAdvantage, token-level GAE with:logp_old - logp_ref) withkl_coefsrc/twinkle/loss/value.py—PPOValueLoss, clipped value objectivemax((v-r)², (clip(v,v_old)-r)²)src/twinkle/model/transformers/value_model.py—TransformersValueModel, causal-LM backbone with ahidden_size -> 1value head replacing the LM headsrc/twinkle/metric/ppo.py—PPOValueMetric(value/return mean, value clip ratio, explained variance)PPOLoss(GRPOLoss)/PPOMetric(GRPOMetric)— semantic aliases reusing the existing clipped policy objective & ratio/clip statisticsFramework generalization (backward-compatible)
ModelOutputgains avaluesfield; forward/forward_only can emitvalueswhen the loss declaresrequire_valuesprocessorpacking,nccl_safewrapper, andloss/basehandle the newvaluestensor--critic-model-gpus,--ppo-epochs,--gamma,--gae-lambda,--kl-coef,--normalize-advantages,--critic-learning-rate,--value-clipTests
tests/advantage/test_gae.py— single/multi-step GAE, terminal bootstrap, padding mask, normalization, sparse reward + KL shapingtests/loss/test_ppo.py—PPOLossparity withGRPOLoss, clipped/unclipped value loss, ragged token alignmenttests/model/test_value_model.py— value-head forward/backward, save/loadtests/cli/test_cli.py— new PPO CLI argsDocs
Usage