feat(recipes): Decouple training algorithms from UniRL Core#210
Open
YSunLIN wants to merge 3 commits into
Open
feat(recipes): Decouple training algorithms from UniRL Core#210YSunLIN wants to merge 3 commits into
YSunLIN wants to merge 3 commits into
Conversation
- Remove trainer-side config validation and simplify mean calculation with np.mean. - Remove unused fit=train handling from trainer. - Rename REFL recipe namespace from refl_wan to refl. - Rename base_role.py to role.py for the REFL role implementation. - Move max_grad_norm handling out of the base role and let reward backends own it. - Add a generic reward role under unirl/reward that directly extends the reward service. - Remove reward package pip installation from pyproject configuration. - Remove hardcoded local paths from recipe configs and shell scripts. - Add requirements.txt files for face and videoalign reward backends.
Collaborator
|
The tiled VAE decode path hardcodes the output buffer batch dimension to 1, while hidden_states may have B > 1. The decoded tile therefore has batch size B and cannot be accumulated in-place into values when B > 1. Since decode() now defaults to tiled=True, this can break existing WAN recipes such as wan21_t2v.yaml, which uses forward_batch_size: 4. Please allocate these buffers using the actual input batch size, apply the same fix to tiled_parallel_decode, and add a regression test covering batch size greater than one. |
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.
feat(recipes): Decouple Training Algorithms from UniRL Core
Summary
The core motivation of this PR is to decouple training algorithms from UniRL core, and organize algorithms, configs, rewards, and launch logic in the form of recipes. This reduces framework intrusiveness and allows users to customize model, pipeline, sampling, reward, loss and trainer without modifying the core components.
Introduce the
Trainer + Roleabstraction:unirl.trainer.Trainer/unirl.trainer.Role, supporting creation, initialization, and scheduling of remote roles from therolesconfig.RewardRole, used to host reward backends in recipes through configuration, and support the differentiable reward path.share_withworker sharing, and role-aware checkpoint save/load.Refactor the recipe config structure:
rolesas the config root to uniformly describe actor, reward, backend, pipeline, algorithm, placement, and other configurations.Add training configuration capabilities:
MultimodalRLDataSourcesupportsrun.shuffle.LoraConfigaddsmodule_prefix, supporting LoRA injection only into modules with specific prefixes; the Wan 2.2 I2V recipe applies LoRA only to thelow_noisemodule.linear_warmuptype.Supporting adjustment:
_target_config errors under recipes cannot be detected by the existing check flow.scripts/check_recipe_targets.pysupports scanning_target_configs underrecipes.At the same time, this PR completes the differentiable generation path and memory optimization capabilities required for WAN ReFL training.
Add the
recipes/reflrecipe package:REFLTrainerandReflActorRoleon the recipe side, keeping ReFL algorithm orchestration inside the recipe.wan21_t2v_videoalign_reflconfig, corresponding torecipes/refl/configs/wan21_t2v_videoalign_refl.yaml, for Wan 2.1 T2V + VideoAlign reward.wan22_i2v_face_reflconfig, corresponding torecipes/refl/configs/wan22_i2v_face_refl.yaml, for Wan 2.2 I2V + Face reward.Add the ReFL/WAN differentiable training path:
DiffusionStagewith thediffuse_with_gradresult type and invocation path.Introduce a memory-optimized WAN video VAE:
WanVideoVAE.Add recipe-local reward dependency declarations:
recipes/refl/rewards/face/requirements.txt.recipes/refl/rewards/videoalign/requirements.txt.Test Plan
1. Wan 2.1 T2V ReFL + VideoAlign reward
2. Wan 2.2 I2V ReFL + Face reward
Verification Status
wan21_t2v_videoalign_reflnum_rollouts=835;batch_size=8;num_inference_steps=25; final-step differentiable pathwan22_i2v_face_reflnum_rollouts=690;batch_size=8;module_prefix=low_noise;num_inference_steps=8Wan 2.1 T2V ReFL training reward curve
Wan 2.2 I2V ReFL training reward curve
Compatibility / Risk
Trainer + Role,RewardRole, andrecipes/reflare new capabilities that mainly affect the new recipe path; existing non-recipe training entrypoints do not need to be migrated.MultimodalRLDataSource.run.shuffleistrue, preserving the previous default shuffle behavior; shuffle is disabled only when a recipe explicitly setsshuffle: false.module_prefixis a new optional parameter for LoRA injection. When not configured, the originaltarget_modulessuffix matching logic is still used and remains backward compatible. Incorrect configuration may cause LoRA to miss specific modules, so the actual trainable params should be confirmed through startup logs.requirements.txtfiles and no longer forcibly pollute the core environment. The corresponding requirements need to be manually installed before running each reward.