xtuner icon indicating copy to clipboard operation
xtuner copied to clipboard

Chunk linear loss

Open jayhenry opened this issue 10 months ago • 2 comments

jayhenry avatar Feb 03 '26 14:02 jayhenry

@claude

HAOCHENYE avatar Mar 05 '26 14:03 HAOCHENYE

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] = [] in BaseRLLossConfig.build() and BaseRLLossKwargs — classic Python bug where all callers share the same list. Use None default instead.
  • Unused enable_chunk_linear parameter added to CELossContext.loss_fn and OrealLossContext.loss_fn but never referenced in their bodies.
  • Inconsistent default for enable_chunk_linear in gspo_loss_fn (True) vs pg_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 | None instead of Optional[X] in chunk_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_q in worker.py — remove dead code.
  • Debug logger.info(f"WorkerConfig: ...") in worker.py — consider logger.debug.
  • No PR description provided — consider adding root cause/motivation and test plan.

Verdict

REQUEST_CHANGES

claude[bot] avatar Mar 05 '26 14:03 claude[bot]