radixark / radixark/miles_diffusion
Krea2TrainPipelineConfig.cfg_combine ignores true_cfg_scale
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 96
- Forks
- 17
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 35
Description
Bug
Krea2TrainPipelineConfig.cfg_combine (miles/backends/fsdp_utils/configs/krea2.py:79-86) takes a true_cfg_scale parameter but never reads it — it always blends with guidance_scale:
def cfg_combine(
self,
noise_pred_pos: torch.Tensor,
noise_pred_neg: torch.Tensor,
guidance_scale: float,
true_cfg_scale: float | None = None,
) -> torch.Tensor:
return noise_pred_neg + guidance_scale * (noise_pred_pos - noise_pred_neg)
Every other family's cfg_combine resolves the blend weight the same way:
scale = true_cfg_scale if true_cfg_scale is not None else guidance_scale
return noise_pred_neg + scale * (noise_pred_pos - noise_pred_neg)
sd3.py:64-71ltx.py:159-169cosmos3.py:157-165qwen_image.py:176-191wan2_2.py:68-76
Impact
prepare_flow_grpo_batch (miles/backends/fsdp_utils/loss_hub/flow_grpo.py:41-44) picks cfg_scale = true_cfg_scale if true_cfg_scale is not None else guidance_scale to decide use_cfg, and expects that same scale to be the one actually applied in the forward. For Krea2, if --diffusion-true-cfg-scale is set and differs from --diffusion-guidance-scale, the model forward silently combines with the wrong scale — decoupling the CFG strength used to compute the training log-prob/gradient from what use_cfg was decided on and from what the rollout engine used to generate the sample. This is a silent train/rollout mismatch that would corrupt the PPO ratio without raising any error.
This is currently unreachable in practice only because the one existing Krea2 script (scripts/run_diffusion_nft_krea2.py) uses the CFG-free NFT loss (prepare_nft_batch sets use_cfg=False, guidance_scale=0.0), but nothing guards Krea2TrainPipelineConfig against being used with flow-GRPO, and the class accepts true_cfg_scale as if it were honored.
Suggested fix
def cfg_combine(
self,
noise_pred_pos: torch.Tensor,
noise_pred_neg: torch.Tensor,
guidance_scale: float,
true_cfg_scale: float | None = None,
) -> torch.Tensor:
scale = true_cfg_scale if true_cfg_scale is not None else guidance_scale
return noise_pred_neg + scale * (noise_pred_pos - noise_pred_neg)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at miles/backends/fsdp_utils/configs/krea2.py:79-86 and compare Krea2 with the cfg_combine implementations in sd3.py, ltx.py, cosmos3.py, qwen_image.py, and wan2_2.py. Check the flow_grpo.py call path to confirm the selected CFG scale is applied consistently. Done means Krea2 honors true_cfg_scale when provided and otherwise retains guidance_scale behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 91/100