Should the logits-memory change move out of PR #4776 into its own PR?

NVIDIA-NeMo/RL #4776 · the question: review thread on model_utils.py:1110 · all links pinned to head 96ec8a36

Asked
A reviewer asked the author to split commit 4a8997dba into its own PR and add a warning to its docstring, then asked a maintainer for their view.
This PR
Still has the commit; the docstring is not updated yet.
Status
Open: waiting on the maintainer's answer. Suggested answer: yes, split it, and add the docstring (staged reply C1).

Three pages on this PR, one question each. This one: should one commit leave the PR.

What the commit does, in short. During training, the loss needs the logprobs of each token. Their backward pass needs a gradient buffer exactly as big as the logits. Before, it made a new buffer. The commit writes the gradient into the logits' own memory instead, which the PR estimates saves about 12 GiB on its GB200 run. The catch: after backward, the logits tensor holds gradient numbers, not logits. Any code that reads it afterwards gets wrong values, and in some cases no error is raised. The third page draws how this works.
PR #4776 today: four changesSuggested: its own PRThink-tag penalty on token capturecommits 97e23867f, c3977d53d · touches: token capture onlyKeep Gym rollout metrics on capturecommits 7dcb8a2e5, 3e4558ff1 · touches: token capture onlyClear Megatron caches after critic trainingcommits b78f6dec2 · touches: critic onlyWrite the logprob grad into the logits' memorycommits 4a8997dba · touches: shared training lossmove outWhat the new PR should add:1. docstring: logits hold grad after backward2. use_chunking instead of True3. a test at TP/CP > 1 with chunking4. measured peak memory, on vs offonly new code (capture, critic): a bug stays in that featureshared loss code: a bug could hit any run that turns the flags on

What was asked

The reviewer pointed out that the docstring does not warn that the logits get overwritten, and listed ways a later reader could silently get the gradient instead (reading the logits after backward, or keeping a reference some other way). Then two asks:

1. Update the docstring. 2. Move this change (4a8997dba2) into its own PR to derisk merging this PR, since it carries this risk. The other three changes can stay here.

Then the reviewer tagged the maintainer: "wdyt 4a8997dba?" That is the open question: do you agree with the split?

↪ the reviewer's comment — model_utils.py:1110

Suggested answer: yes, split it

The reply is staged as C1 in your pending review: it agrees with the reviewer and lists asks 2–4 from the figure for the new PR.

↪ C1 · staged reply — model_utils.py:1110

So what. Answer "agree, split it". The memory saving is real and the code looks right, but it changes code every packed run with an fp32 LM head and chunked logprobs would use, and nothing tests it yet. On its own PR it gets a test at real tensor- and context-parallel sizes and a measured memory number, and the rest of #4776 can merge now.