Skip to content

feat(algorithms): add AR PPO with GAE and value loss - #2

Open
yhl48 wants to merge 12 commits into
feat/ar-value-headfrom
feat/ar-ppo-gae
Open

feat(algorithms): add AR PPO with GAE and value loss#2
yhl48 wants to merge 12 commits into
feat/ar-value-headfrom
feat/ar-ppo-gae

Conversation

@yhl48

@yhl48 yhl48 commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the PPO algorithm path for autoregressive training (issue Tencent-Hunyuan#86, part 3/3), stacked on feat/ar-value-head (Tencent-Hunyuan#256 upstream).

  • New PPO / PPOConfig with worker-side prepare_rollout_track (no-grad critic replay + GAE) and train-step policy clip + clipped value loss.
  • _ppo_clipped_value_loss in algorithms/base.py.
  • TrainStack calls optional algorithm.prepare_rollout_track() before micro-batch prep.
  • advantage_mode: grpo | gae on AR trainers.
  • Example recipe examples/ar/qwen3_ppo_4b_base_dapo_sglang.yaml.
  • CPU unit tests for clipped value loss.

Related Issue

Part of Tencent-Hunyuan#86 (PPO value critic + GAE for AR models).

Test Plan

  • python3 -m ruff check unirl/algorithms/ppo.py unirl/algorithms/base.py unirl/algorithms/__init__.py unirl/train/stack/base.py unirl/train_ar.py unirl/trainer/ar.py unirl/trainer/async_ar.py tests/algorithms/test_ppo_value_loss.py
  • pytest tests/algorithms/test_ppo_value_loss.py (Python 3.12+ project env)
  • End-to-end training not run in this PR.

Compatibility / Risk

  • Opt-in: default advantage_mode=grpo unchanged.
  • PPO recipes require use_value_head=True and advantage_mode: gae.
  • Rollout sync must exclude value_head.* for separate SGLang engine.

Reviewer Notes

Checklist

  • I reviewed the changed code and removed unrelated/generated artifacts.
  • I updated tests, docs, and configs where needed, or explained why not.

yhl48 added 6 commits July 25, 2026 17:55
Wire per-token critic values through Qwen3 replay and compute GAE
advantages on RolloutTrack for the PPO critic path (issue Tencent-Hunyuan#86, part 2/3).
Keep transformers imports inside from_config / _packed_replay_supported
as in upstream; only UniRL imports (ValueHead, ARReplayOutput) stay top-level.
Call _require_value_head_for_replay at the start of _replay_aware_forward
so return_values=True fails fast before the transformer forward, not only
from Qwen3ARStage.replay().
Extend ReplayResult with optional per-token values for PPO/GAE and
replace ARReplayOutput in Qwen3 replay with the shared type.
Apply ruff-format changes and remove unused cu in _finalize_replay_output.
Derive last-token positions from packed offsets (end - 1) instead of
passing redundant lengths, with a guard for empty samples.
@leviking98z-rgb
leviking98z-rgb force-pushed the feat/ar-ppo-gae branch 2 times, most recently from 7acd52d to cda2582 Compare August 1, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants