Repository navigation
refactor(loss): move loss-input preparation into loss_input.py - #4232
Conversation
|
/ok to test 16dd107 |
yuki-97
left a comment
There was a problem hiding this comment.
No action needed — LGTM. The pure-code-move claim was verified mechanically; no inline comments.
TL;DR — an AST comparison of base utils.py against head utils.py + loss_input.py shows all 8 top-level functions identical; the only differing node in ~550 lines is the _prepare_opd_full_loss_input rename and its one call site.
Context — no action.
1. The move is AST-clean. base \ (head_utils | head_loss_input) is empty. The single differing node is the call at loss_input.py:285. Module-level statements partition exactly: base's 8 imports plus the TYPE_CHECKING block split with no constant, logger, __all__, decorator or try/except left behind or duplicated. Zero unresolved free names and zero unused imports in either file.
2. No stale string patch targets — the usual silent breakage in a code move. Five monkeypatch.setattr string targets pointed into the moved module and all five were updated (test_loss_functions.py:2742, :2746, :2789, :2793, test_sequence_packing_fusion.py:71). All seven surviving loss.utils importers resolve to names that genuinely stayed. No dynamic reference to the old paths anywhere: no _target_, registry, entry point, getattr, or dotted path in any yaml/toml/json/sh/md.
3. No import cycle. loss_input.py imports the submodules loss.utils and loss.interfaces, never the package. utils.py's transitive nemo_rl closure is {distributed.model_utils, algorithms.logits_sampling_utils} — it never reaches algorithms.loss, in either direction.
4. The cut line is right. _pack_input_ids correctly stayed in utils.py: besides loss_input.py:498 it has an in-module caller at utils.py:99 and a cross-package one at nemo_rl/models/megatron/train.py:397 — moving it would have made utils.py import from loss_input.py. Three of the four remaining public helpers are consumed by wrapper.py.
5. The privatization changes no public surface. prepare_opd_full_loss_input was never in __all__ and had exactly one production caller — the dispatcher itself. tests/unit/algorithms/test_opd_full.py:762 was rewritten to reach the branch through the public prepare_loss_input rather than keeping a private back door; every assertion is unchanged, and the OPD_FULL branch forwards all arguments verbatim.
6. pyrefly.toml:62 adds the new module to project-includes, so the moved code stays type-checked.
Reviewed by a five-agent team (RL expert, bug finder, test reviewer, design reviewer, devil's advocate). One candidate finding — an unexplained deferred import at wrapper.py:313 — was dropped as out-of-diff and pre-existing (introduced in #3463); worth a separate one-line cleanup, not this PR.
Generated by Claude Code
Signed-off-by: Yuki Huang <[email protected]>
Signed-off-by: Yuki Huang <[email protected]>
16dd107 to
cdc1daa
Compare
|
/ok to test cdc1daa |
Signed-off-by: Yuki Huang <[email protected]>
|
/ok to test 39f6624 |
Brings #4198 (remove the DTensor v1 policy worker), #4207, #4196, #4143 (MiniMax-M3 GRPO support), #4233, #4232 and #3408 (flow_grpo research). Conflicts and resolution: - pyproject.toml: main removed the `fsdp` extra together with the v1 worker; this branch had given that extra its own torch 2.13 pin. The extra is dropped here as well (with its `[tool.uv] conflicts` entries), and the per-extra torch comment no longer lists it. - uv.lock: regenerated from this branch's lock; the only change is the addition of #3408's flow-grpo research dependencies (albumentations, paddleocr, scikit-image, ...). No existing package moved, and nothing resolves below main except the deliberate numpy / llguidance / flash-attn pins. Also removed, not conflicting: `_patch_vllm_minimax_m3_topk_buffer_layout` (#4143) and its tests. It backported vllm-project/vllm@d1a8ba63 (token-major vs head-major `topk_indices_buffer`) onto vLLM 0.26.0 and its docstring asks for removal at vLLM >= 0.27; vLLM 0.29.0's `minimax_m3/common/indexer.py` already carries the head-major `buf_htk` layout, so on this branch the patch could only ever log "source shape not found" and its installed-vLLM anchor tests would fail. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
What does this PR do ?
The three
prepare_*_loss_inputentry points are the main way logits get turned intoloss input, but living in a file called
utils.pymakes them hard to find.Pure code move, no behavior change: extracts
prepare_opd_full_loss_input,prepare_loss_inputandprepare_packed_loss_inputout ofnemo_rl/algorithms/loss/utils.pyinto a newnemo_rl/algorithms/loss/loss_input.py.utils.pykeeps the five helpers that have consumers outside these three functions.The
nemo_rl.algorithms.lossre-exports are unchanged, sofrom nemo_rl.algorithms.loss import prepare_loss_inputkeeps working.🤖 Generated with Claude Code