Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fec2744
feature(math_prm): keep minimal upstream stage3 path
HansBug Mar 20, 2026
d8590af
fix(math_prm): sync stage3 rollout updates from working branch
HansBug Mar 20, 2026
3ff0caf
fix(wandb): remove live heartbeat logging
HansBug Mar 22, 2026
6ae4d56
fix(math_prm): sync runtime eval updates from working branch
HansBug Mar 26, 2026
3f5470a
style(math_prm): remove trailing whitespace from stage3 files
HansBug Mar 26, 2026
a81a817
fix(strategy): reload keep-on-gpu rollout actor after sync
HansBug Mar 31, 2026
902050a
fix(math_prm): sync stage3 training path from working branch
HansBug Apr 27, 2026
a36c860
fix(math_prm): bring stage3 doc/training/runtime updates from working…
HansBug Apr 27, 2026
d25d64e
Merge remote-tracking branch 'main/main' into dev/math_prm_train
HansBug Apr 27, 2026
34e97b1
fix(math_prm): address PR #53 review comments
HansBug Apr 27, 2026
ceb4441
fix(profile): restore profile_recorder.py and re-export StepProfileRe…
HansBug Apr 27, 2026
b905c23
fix(math_prm): K1 KL estimator + freeze fix + ratio diagnostics
HansBug Apr 29, 2026
67c1d31
fix(math_prm): align URSA log_probs with VLM forward and revert KL hacks
HansBug Apr 30, 2026
cce5ae5
fix(math_prm): protect PRM from actor-leaked image tokens + add resum…
HansBug May 5, 2026
3c54da8
fix(math_prm): align rollout/eval with bare HF generate; gate EOS pat…
HansBug May 7, 2026
f23e687
feat(math_prm): add per-step PRM reward path (URSA paper variant 2)
HansBug May 8, 2026
95ee722
fix(math_prm): URSA-native step-boundary alignment for per-step PRM r…
HansBug May 8, 2026
2220049
feat(math_prm): add --per_step_reward_mode {raw,group_norm} for varia…
HansBug May 8, 2026
f6987cf
chore(math_prm): wire .env auto-source + PER_STEP_REWARD_MODE into of…
HansBug May 8, 2026
4eda088
chore(math_prm): map LIGHTRFT_WANDB_API_KEY -> WANDB_API_KEY in launc…
HansBug May 8, 2026
9e5cbd5
fix(math_prm): protect actor.forward from actor-leaked <|image|> tokens
HansBug May 11, 2026
0fca7c1
fix(math_prm): cap eval DataLoader bs by local_hf_generate_max_batch_…
HansBug May 11, 2026
3b45ea9
chore: route math prm outputs to configured root
HansBug May 18, 2026
f901761
fix(math_prm): keep URSA logprob forward cache-free
HansBug May 18, 2026
db4df06
feat(math_prm): strict URSA paper Eq.9 advantage estimator + diagnostics
HansBug May 25, 2026
e7513e0
fix(math_prm): broaden ursa_variant2 monkey-patch + smoke-test plumbing
HansBug May 25, 2026
2663a5e
feat(math_prm): forward step_rewards through multi-RM aggregator + ch…
HansBug May 25, 2026
1a7cabc
chore(math_prm): variant2 launch — tee training log so it shows live …
HansBug May 25, 2026
230977b
Merge upstream/main into dev/math_prm_train
HansBug Jun 3, 2026
956a850
math_prm: address Agent Review #1 — clean debug artifacts + README re…
HansBug Jun 3, 2026
215ba1a
math_prm: address Agent Review #2 — clean stale docs + explicit register
HansBug Jun 3, 2026
4b7ab05
math_prm: drop inert --per_step_reward_mode CLI arg from variant 2 la…
HansBug Jun 3, 2026
95cb755
style(lightrft): yapf reformat 7 files flagged by format-check
HansBug Jun 3, 2026
11c3b4e
fix(lightrft): drop merge leftovers that broke flake8
HansBug Jun 3, 2026
bbfdaa8
fix(lightrft): restore generate_fn def + suppress zero general_model_…
HansBug Jun 3, 2026
a6202bb
fix(lightrft): narrow abs-zero skip set to general_model_reward only
HansBug Jun 3, 2026
ca33772
docs(math_prm): R5 polish — drop unused deps, fix README step labels,…
HansBug Jun 3, 2026
0b219aa
fix(math-prm): address review compatibility issues
HansBug Jul 1, 2026
b5be0ce
fix(math-prm): penalize post-answer continuation
HansBug Jul 2, 2026
f085791
style: apply CI formatting fixes
HansBug Jul 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
229 changes: 229 additions & 0 deletions examples/math_prm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
<div align="center">

# Math PRM Training in LightRFT

URSA-MATH Stage 3 reproduction workspace for LightRFT.

</div>

## Scope

This directory is no longer a generic multimodal reward example. It now only keeps the files that are still relevant to the URSA-MATH Stage 3 migration and reproduction path.

Current target:

- actor: `URSA-8B`
- reward model: `URSA-RM-8B`
- reward labels: `math_prm`, `math_psgrpo`, `math_prm_combined`, `math_rule`
- training loop: LightRFT PPO/GRPO stack with local `hf` rollout
- raw dataset: `MMathCoT-1M`

## Runtime Baseline

The runtime baseline is frozen by `/data/LightRFT/Dockerfile`.

- Do not treat package-version changes as the first-line fix.
- Prefer fixing code, schema conversion, prompt formatting, rollout configuration, and reward wiring first.
- The active Stage 3 path in this branch is the local `hf` rollout path; `vllm` / `sglang` experiments are optional and go through the engine-wrapper helper only.

## Directory Map

```text
examples/math_prm/
├── README.md # English guide for the current URSA-MATH Stage 3 layout
├── README_zh.md # Chinese guide
├── train_colocate.py # Main LightRFT training entry
├── math_prm_trainer.py # Example-local trainer wrapper for reduced W&B keys and runtime eval
├── run_grpo_math_prm_ursa_8b.sh # Main Stage 3 launcher
├── ursa_actor.py # URSA-specific actor wrapper
├── reward_models.py # Math-only URSA-RM reward implementation
├── reward_models_utils.py # Math-only reward loading, recipe, and reward aggregation
├── sitecustomize.py # Local runtime compatibility hook for this example stack
├── tools/ # Support scripts kept in the slim PR branch
│ ├── __init__.py
│ ├── prepare_ursa_stage3_manifest.py
│ └── prepare_ursa_engine_checkpoint.py
└── ursa_model/ # Self-contained URSA model code used by actor and PRM loading
```

## What Each Top-Level File Does

### Core training path

- `run_grpo_math_prm_ursa_8b.sh`
- Main launcher for Stage 3 reproduction.
- Wires actor path, reward path, dataset path, FSDP setup, rollout settings, and optional W&B.
- `train_colocate.py`
- Real `torchrun` entry.
- Builds actor, reference model, reward model, dataset, trainer, and rollout engine.
- `math_prm_trainer.py`
- Example-local trainer wrapper for math PRM runs.
- Keeps rollout/train/eval W&B metrics compact and applies runtime eval generation defaults.
- `ursa_actor.py`
- URSA-specific actor wrapper used to load `UrsaForConditionalGeneration`.

### Reward path

- `reward_models.py`
- Contains the active `MathPRMReward` implementation only.
- This file has been trimmed to the URSA-MATH Stage 3 path and no longer carries the old Qwen/SafeWork reward classes.
- `reward_models_utils.py`
- Contains the active math-only reward loader and recipe logic.
- Handles `math_prm`, `math_psgrpo`, `math_prm_combined`, and `math_rule`.
- `sitecustomize.py`
- Local import/runtime compatibility shim for the frozen example environment.

### Self-contained URSA runtime

- `ursa_model/`
- Local URSA config, processor, image processor, projector, vision towers, and model definitions.
- This is what lets the current LightRFT path run without importing runtime code directly from the external URSA-MATH repo.

## What Lives Under `tools/`

Everything under `tools/` is support infrastructure, not the main training entry.

- `tools/prepare_ursa_stage3_manifest.py`
- Converts raw `MMathCoT-1M` Stage 3 jsonl into the LightRFT manifest schema.
- `tools/prepare_ursa_engine_checkpoint.py`
- Builds a wrapper checkpoint for engine experiments when testing `vllm` / `sglang` loading.

## Active Entry Points

If you only want the current Stage 3 reproduction path, the usual files are:

- `run_grpo_math_prm_ursa_8b.sh`
- `train_colocate.py`
- `math_prm_trainer.py`
- `reward_models.py`
- `reward_models_utils.py`
- `tools/prepare_ursa_stage3_manifest.py`
- `tools/prepare_ursa_engine_checkpoint.py`

## Local Resources

Current machine layout:

```bash
URSA actor: /home/ubuntu/URSA-MATH/checkpoints/URSA-8B
URSA reward: /home/ubuntu/URSA-MATH/checkpoints/URSA-RM-8B
MMathCoT-1M raw: /home/ubuntu/URSA-MATH/datasets/URSA-MATH/MMathCoT-1M/train.jsonl
Image root: /home/ubuntu/URSA-MATH/datasets/URSA-MATH/images
```

Current converted manifest:

```bash
/data/LightRFT/tmp/ursa_stage3/mmathcot_stage3_math_psgrpo.jsonl
```

Current converted manifest summary:

```bash
/data/LightRFT/tmp/ursa_stage3/mmathcot_stage3_math_psgrpo.summary.json
```

## Dataset Preparation

The raw Stage 3 data is not directly consumable by `PromptDatasetVL`.

Raw schema:

```json
{
"image_url": "...",
"instruction": "...",
"output": "..."
}
```

Converted LightRFT schema:

```json
{
"prompt": "...",
"images": ["/abs/path/to/image.png"],
"reference": "...",
"label": "math_psgrpo"
}
```

Run a smoke conversion:

```bash
python examples/math_prm/tools/prepare_ursa_stage3_manifest.py \
--max-samples 32 \
--output-path /data/LightRFT/tmp/ursa_stage3/smoke_manifest.jsonl \
--summary-path /data/LightRFT/tmp/ursa_stage3/smoke_manifest.summary.json
```

Run the default conversion:

```bash
python examples/math_prm/tools/prepare_ursa_stage3_manifest.py
```

## Training

Expected current-machine values in `examples/math_prm/run_grpo_math_prm_ursa_8b.sh`:

```bash
PATH_TO_YOUR_BASE_MODEL="/home/ubuntu/URSA-MATH/checkpoints/URSA-8B"
PATH_TO_URSA_RM="/home/ubuntu/URSA-MATH/checkpoints/URSA-RM-8B"
PATH_TO_YOUR_MATH_DATASET="/data/LightRFT/tmp/ursa_stage3/mmathcot_stage3_math_psgrpo.jsonl"
EXPECTED_REWARD_LABEL="math_psgrpo"
```

Run training:

```bash
bash examples/math_prm/run_grpo_math_prm_ursa_8b.sh
```

Current default launcher values now follow the explicit Stage 3 settings documented in the local `URSA-MATH` repo where available:

```bash
EPISODE=10
N_SAMPLES=8
RBS=128
TBS=128
MICRO_TRAIN_BATCH_SIZE=4
MICRO_ROLLOUT_BATCH_SIZE=4
LR=1e-6
KL=0.001
PROMPT_MAX_LEN=1024
GENERATE_MAX_LEN=3072
MAX_SAMPLES=15360
```

Notes:

- The paper reports a one-time filtered `20K -> ~15K+` RL set. The exact filtered subset is not present locally, so the launcher keeps the converted manifest path and uses `MAX_SAMPLES=15360` as a scale proxy.
- The paper's default hardware is `32 x H100`; the current machine default remains `1 node x 8 A100`.

## Reward Labels

- `math_prm`
- Pure PRM reward using `min(step_scores)`.
- `math_psgrpo`
- PS-GRPO reward computed inside `MathPRMReward`.
- `math_prm_combined`
- PRM plus explicit rule baseline.
- `math_rule`
- Rule-only ablation baseline.

## Troubleshooting Shortcuts

- Rebuild the manifest:

```bash
python examples/math_prm/tools/prepare_ursa_stage3_manifest.py
```

- Build the engine-wrapper checkpoint for non-`hf` experiments:

```bash
python examples/math_prm/tools/prepare_ursa_engine_checkpoint.py \
--source-model-path /path/to/URSA-8B \
--output-path /path/to/URSA-8B-engine-ready
```
Loading
Loading