xtuner
xtuner copied to clipboard
Chunk linear loss
@claude
Claude: ## Review Summary
This PR adds a chunked linear loss computation mode for PPO/GRPO (memory-efficient log-prob and entropy computation) and introduces the GSPO loss function. The approach of computing logprobs/entropy in chunks to reduce peak memory is sound.
Issues
Warning
- Mutable default argument
num_tokens: list[int] = []inBaseRLLossConfig.build()andBaseRLLossKwargs— classic Python bug where all callers share the same list. UseNonedefault instead. - Unused
enable_chunk_linearparameter added toCELossContext.loss_fnandOrealLossContext.loss_fnbut never referenced in their bodies. - Inconsistent default for
enable_chunk_linearingspo_loss_fn(True) vspg_loss_fn(False). - Missing docstrings on
FusedLinearForPPOFunction(public class) and its public methods. - Test quality:
print()statements in tests, missing type hints on test helpers.
Nit
- Use
X | Noneinstead ofOptional[X]inchunk_linear.py(CLAUDE.md: Python >= 3.10). - Chinese comments in
grpo/loss.py— translate to English for consistency. - Commented-out code
# num_tokens = seq_ctx_list[i].seq_lens_qinworker.py— remove dead code. - Debug
logger.info(f"WorkerConfig: ...")inworker.py— considerlogger.debug. - No PR description provided — consider adding root cause/motivation and test plan.
Verdict
REQUEST_CHANGES