|
| 1 | +# Physion-aligned MJ-VIDEO reward implementation plan |
| 2 | + |
| 3 | +## Objective |
| 4 | + |
| 5 | +Add a second, selectable reward profile on top of the existing paper-faithful |
| 6 | +FastH3 RVM implementation: |
| 7 | + |
| 8 | +```text |
| 9 | +R_physion = |
| 10 | + 0.30 * z(VideoAlign text alignment) |
| 11 | + + 0.40 * z(MJ-VIDEO Coherence & Consistency) |
| 12 | + + 0.25 * z(MJ-VIDEO Fineness) |
| 13 | + + 0.05 * z(RAFT Dynamic Tracking) |
| 14 | +``` |
| 15 | + |
| 16 | +The RVM optimization algorithm must remain unchanged: |
| 17 | + |
| 18 | +1. Generate `K` endpoints with the released four-forward FastH3 VSA policy. |
| 19 | +2. Combine reward components into one scalar for each endpoint. |
| 20 | +3. Center the scalar reward inside each prompt group. |
| 21 | +4. Divide by one population standard deviation over the whole rollout |
| 22 | + collection, including all DP replicas. |
| 23 | +5. Apply scale `0.1` and the existing signed clipping. |
| 24 | +6. Sample the analytic RVM regression time with `t ~ Uniform(0, 1)`. |
| 25 | +7. Regress the native velocity target `epsilon - x0` through the existing |
| 26 | + detached-target surrogate. |
| 27 | + |
| 28 | +This change is therefore a **reward-profile addition**, not a new RL loss. |
| 29 | +The original RVM reward profile remains available and must be switchable by |
| 30 | +choosing a YAML config. |
| 31 | + |
| 32 | +## Non-goals |
| 33 | + |
| 34 | +- Do not modify the four-step FastH3 rollout, CFG policy, VSA sparsity, model |
| 35 | + geometry, LoRA targets, velocity target, advantage equation, or optimizer |
| 36 | + semantics. |
| 37 | +- Do not add PhyJudge, VideoScore2, VisionReward, or a new model-generated |
| 38 | + reward in this change. They remain checkpoint-evaluation candidates. |
| 39 | +- Do not normalize each prompt group to unit variance. |
| 40 | +- Do not estimate calibration statistics from the live policy during training. |
| 41 | + That would make reward semantics drift over time. |
| 42 | +- Do not hide MJ-VIDEO load or compatibility failures by silently falling back |
| 43 | + to another reward model. |
| 44 | + |
| 45 | +## Source inventory and pinned references |
| 46 | + |
| 47 | +### 1. Reward-based Velocity Matching |
| 48 | + |
| 49 | +- Paper: `Scaling Reinforcement Learning for Diffusion Models via Velocity |
| 50 | + Matching`, arXiv:2608.23664. |
| 51 | +- Existing implementation source of truth: |
| 52 | + `fastvideo/train/methods/rl/rvm_faithful.py`. |
| 53 | +- Required invariants: |
| 54 | + - endpoint-only on-policy sampling; |
| 55 | + - prompt-relative reward centering; |
| 56 | + - rollout-global reward standard deviation; |
| 57 | + - signed scale `0.1`; |
| 58 | + - continuous analytic regression time; |
| 59 | + - native flow target `epsilon - x0`. |
| 60 | + |
| 61 | +No RVM loss code should be forked for the new reward profile. |
| 62 | + |
| 63 | +### 2. MJ-VIDEO paper and official code |
| 64 | + |
| 65 | +- Paper: `MJ-VIDEO: Fine-Grained Benchmarking and Rewarding Video Preferences |
| 66 | + in Video Generation`, arXiv:2502.01719, NeurIPS 2025 Spotlight. |
| 67 | +- Official repository: `aiming-lab/MJ-Video`. |
| 68 | +- Pinned source commit: |
| 69 | + `cc1d2c9587a620e9ebd3599ae4cdd21b5fd7c87a`. |
| 70 | +- Official checkpoint: `MJ-Bench/MJ-VIDEO-2B`. |
| 71 | +- Pinned checkpoint revision: |
| 72 | + `5d32c2416bf5ffb9331a175890744e73defb54c4`. |
| 73 | +- Primary implementation references: |
| 74 | + - `scripts/model/moe_reward.py`; |
| 75 | + - `scripts/model/internvl2/`; |
| 76 | + - `scripts/data_processor/data.py`; |
| 77 | + - `scripts/eval/eval_genai_mjvideo.py`. |
| 78 | + |
| 79 | +Exact official inference settings to preserve: |
| 80 | + |
| 81 | +```text |
| 82 | +base model: OpenGVLab/InternVL2-2B |
| 83 | +video frames: 8 uniformly spaced segments |
| 84 | +input size: 448 |
| 85 | +max_num image tiles: 1 |
| 86 | +num_objectives: 28 |
| 87 | +num_aspects: 5 |
| 88 | +aspect2criteria: |
| 89 | + 0: [0, 1, 2, 3, 4] |
| 90 | + 1: [5, 6, 7, 8, 9, 10] |
| 91 | + 2: [11, 12, 13, 14, 15] |
| 92 | + 3: [16, 17, 18, 19, 20, 21, 22] |
| 93 | + 4: [23, 24, 25, 26, 27] |
| 94 | +gating_temperature: 1.0 |
| 95 | +gating_hidden_dim: 1024 |
| 96 | +gating_n_hidden: 3 |
| 97 | +inference dtype: BF16 |
| 98 | +``` |
| 99 | + |
| 100 | +Aspect mapping from the paper/code: |
| 101 | + |
| 102 | +```text |
| 103 | +0 Alignment |
| 104 | +1 Safety |
| 105 | +2 Fineness |
| 106 | +3 Coherence & Consistency |
| 107 | +4 Bias & Fairness |
| 108 | +``` |
| 109 | + |
| 110 | +The requested reward components are therefore: |
| 111 | + |
| 112 | +```text |
| 113 | +mjvideo_fineness = output.aspect_scores[:, 2] |
| 114 | +mjvideo_cc = output.aspect_scores[:, 3] |
| 115 | +``` |
| 116 | + |
| 117 | +### 3. VideoAlign and RAFT |
| 118 | + |
| 119 | +Reuse the already-pinned implementations and checkpoints in this branch: |
| 120 | + |
| 121 | +- VideoAlign TA: unchanged preprocessing and reward semantics. |
| 122 | +- Dynamic Tracking: unchanged clipped RVM reward; retain raw-flow and |
| 123 | + saturation diagnostics. |
| 124 | + |
| 125 | +The Physion profile lowers DT to `0.05`; it remains an anti-static guardrail, |
| 126 | +not the primary quality signal. |
| 127 | + |
| 128 | +### 4. Fixed robust reward calibration |
| 129 | + |
| 130 | +The four reward models have unrelated numeric scales. Implement a fixed |
| 131 | +baseline calibration rather than using arbitrary raw units: |
| 132 | + |
| 133 | +```text |
| 134 | +z_j(r) = (r - center_j) / max(scale_j, eps) |
| 135 | +center_j = median_j |
| 136 | +scale_j = 1.4826 * MAD_j |
| 137 | +``` |
| 138 | + |
| 139 | +If MAD is degenerate, use the baseline population standard deviation. Fail if |
| 140 | +both scales are degenerate unless the user explicitly overrides the component. |
| 141 | +Optionally clip calibrated component values using a fixed config value. |
| 142 | + |
| 143 | +Calibration must be computed once from a fixed bank of released FastH3 outputs |
| 144 | +and saved as a versioned JSON artifact. It is separate from RVM advantage |
| 145 | +normalization: |
| 146 | + |
| 147 | +```text |
| 148 | +raw component -> fixed z calibration -> weighted reward scalar |
| 149 | + -> per-prompt center / rollout-global std -> RVM coefficient |
| 150 | +``` |
| 151 | + |
| 152 | +## Implementation tasks and commit sequence |
| 153 | + |
| 154 | +### Phase 0 — plan and provenance |
| 155 | + |
| 156 | +- [x] Inspect the current RVM reward builder, aggregation path, validation |
| 157 | + artifacts, data scripts, and tests. |
| 158 | +- [x] Inspect the MJ-VIDEO paper, official checkpoint, model architecture, |
| 159 | + aspect mapping, frame preprocessing, and evaluation script. |
| 160 | +- [x] Record exact pinned source/checkpoint revisions and implementation plan. |
| 161 | +- [ ] Create an implementation progress report updated after every phase. |
| 162 | + |
| 163 | +Acceptance: this plan and the initial progress report are committed before code |
| 164 | +changes. |
| 165 | + |
| 166 | +### Phase 1 — fixed calibration infrastructure |
| 167 | + |
| 168 | +Implement: |
| 169 | + |
| 170 | +- `RewardCalibrationEntry` and calibration-artifact parser; |
| 171 | +- `CalibratedRewardScorer`, preserving raw values as diagnostics; |
| 172 | +- top-level `reward_fn.calibration` support in the reward builder; |
| 173 | +- deterministic reward-output-key discovery so distributed RVM broadcasts all |
| 174 | + scorer diagnostics without hard-coded reward names. |
| 175 | + |
| 176 | +Tests: |
| 177 | + |
| 178 | +- exact z-score application; |
| 179 | +- MAD fallback and invalid-scale failure; |
| 180 | +- required/missing calibration behavior; |
| 181 | +- diagnostics do not enter the weighted aggregate; |
| 182 | +- output-key discovery is identical on all ranks. |
| 183 | + |
| 184 | +Acceptance: existing reward profiles produce identical aggregate values when no |
| 185 | +calibration block is configured. |
| 186 | + |
| 187 | +### Phase 2 — MJ-VIDEO runtime adapter |
| 188 | + |
| 189 | +Implement `fastvideo/train/methods/rl/rewards/mj_video.py`: |
| 190 | + |
| 191 | +- load the pinned official source tree dynamically from a configured/local path; |
| 192 | +- verify its Git commit unless an explicit development override is enabled; |
| 193 | +- load the pinned `MJ-Bench/MJ-VIDEO-2B` checkpoint strictly; |
| 194 | +- reproduce official 8-frame, 448-pixel, ImageNet-normalized preprocessing in |
| 195 | + memory; |
| 196 | +- reproduce the official InternVL prompt construction; |
| 197 | +- expose `mjvideo_fineness` and `mjvideo_cc` scorers; |
| 198 | +- share one model/runtime and one forward result between both aspects; |
| 199 | +- support bounded inference chunks and SP-leader-only loading; |
| 200 | +- fail loudly on Transformers/runtime incompatibility. |
| 201 | + |
| 202 | +Tests use a fake runtime/model and verify: |
| 203 | + |
| 204 | +- exact frame indices; |
| 205 | +- aspect indices 2 and 3; |
| 206 | +- shared forward cache; |
| 207 | +- output shapes and finite checks; |
| 208 | +- source/checkpoint revision validation. |
| 209 | + |
| 210 | +Acceptance: a dedicated GPU preflight loads the real checkpoint and returns two |
| 211 | +finite, non-identical aspect tensors for deterministic videos. |
| 212 | + |
| 213 | +### Phase 3 — assets and calibration workflow |
| 214 | + |
| 215 | +Extend provider-independent scripts: |
| 216 | + |
| 217 | +- add MJ-VIDEO runtime/model/calibration paths to `common.sh`; |
| 218 | +- pin and download the official code/checkpoint in `01_download_models.sh`; |
| 219 | +- save a complete validation JSONL manifest containing prompt, video path, and |
| 220 | + raw reward components; |
| 221 | +- add a calibration CLI that scores a fixed released-FastH3 video bank and |
| 222 | + writes robust median/MAD statistics plus provenance; |
| 223 | +- add `04_calibrate_physion_mj_rewards.sh`. |
| 224 | + |
| 225 | +Acceptance: |
| 226 | + |
| 227 | +- calibration generation is deterministic for fixed videos/prompts; |
| 228 | +- artifact records model/source revisions, sample count, component statistics, |
| 229 | + and input-manifest digest; |
| 230 | +- training refuses to use the Physion profile when the required calibration is |
| 231 | + absent or incomplete. |
| 232 | + |
| 233 | +### Phase 4 — selectable reward profile |
| 234 | + |
| 235 | +Add a config that changes only the reward profile: |
| 236 | + |
| 237 | +```text |
| 238 | +0.30 VideoAlign TA (calibrated) |
| 239 | +0.40 MJ-VIDEO C&C (calibrated) |
| 240 | +0.25 MJ-VIDEO Fineness (calibrated) |
| 241 | +0.05 Dynamic Tracking (calibrated) |
| 242 | +``` |
| 243 | + |
| 244 | +Keep identical: |
| 245 | + |
| 246 | +- `RVMFaithfulMethod` / `RVMWithLocalMetricsMethod`; |
| 247 | +- four-step behavior rollout; |
| 248 | +- continuous RVM regression time; |
| 249 | +- LoRA rank/targets; |
| 250 | +- geometry and VSA settings; |
| 251 | +- optimizer and advantage semantics. |
| 252 | + |
| 253 | +Add a matched reward-profile sweep script comparing: |
| 254 | + |
| 255 | +1. the original published RVM reward profile; |
| 256 | +2. the Physion/MJ-VIDEO profile. |
| 257 | + |
| 258 | +Acceptance: tests prove the two configs differ only in reward configuration, |
| 259 | +artifact paths, and run/output names. |
| 260 | + |
| 261 | +### Phase 5 — preflight, docs, and final audit |
| 262 | + |
| 263 | +- extend static preflight to cover the MJ adapter and calibration code; |
| 264 | +- add a real-MJ reward preflight mode; |
| 265 | +- document installation, calibration, profile switching, memory expectations, |
| 266 | + failure modes, and custom-node launch commands; |
| 267 | +- update this progress report with exact commands and honest validation status; |
| 268 | +- run formatting, focused tests, config parsing, shell syntax, and diff checks; |
| 269 | +- run GPU preflight separately before any long training claim. |
| 270 | + |
| 271 | +Acceptance: all CPU/static tests pass; GPU status is reported explicitly rather |
| 272 | +than inferred from code completion. |
| 273 | + |
| 274 | +## Experiment switch |
| 275 | + |
| 276 | +Original RVM reward profile: |
| 277 | + |
| 278 | +```bash |
| 279 | +RVM_SCALEUP_CONFIG=examples/train/configs/rl/minimax_h3/rvm_h3_8gpu_exact.yaml \ |
| 280 | + bash examples/train/rvm_h3/07_run_8gpu_scaleup_pilot.sh |
| 281 | +``` |
| 282 | + |
| 283 | +Physion/MJ-VIDEO reward profile after calibration: |
| 284 | + |
| 285 | +```bash |
| 286 | +RVM_SCALEUP_CONFIG=examples/train/configs/rl/minimax_h3/rvm_h3_8gpu_physion_mj.yaml \ |
| 287 | + bash examples/train/rvm_h3/07_run_8gpu_scaleup_pilot.sh |
| 288 | +``` |
| 289 | + |
| 290 | +The matched profile-sweep script will set the corresponding output directories |
| 291 | +and run names while preserving the same prompt split, seeds, LR, topology, and |
| 292 | +RVM loss. |
| 293 | + |
| 294 | +## Go/no-go criteria |
| 295 | + |
| 296 | +Do not run the long Physion profile campaign until: |
| 297 | + |
| 298 | +1. the real MJ-VIDEO checkpoint loads under the FastVideo environment; |
| 299 | +2. exact aspect mapping and fixed calibration are verified; |
| 300 | +3. baseline and trained validation use the same prompts and seeds; |
| 301 | +4. no reward component is constant or non-finite; |
| 302 | +5. MJ C&C/Fineness correlate in the expected direction on a small manually |
| 303 | + inspected pair bank; |
| 304 | +6. the 1/4-GPU integration test and 8-GPU topology test complete; |
| 305 | +7. full-video quality, prompt adherence, motion, and audio are inspected rather |
| 306 | + than selecting solely by the optimized scalar. |
0 commit comments