Repository navigation
fix: stop relying on megatron-core echoing prompt tokens back - #3363
Closed
shanmugamr1992 wants to merge 1 commit into
Closed
shanmugamr1992 wants to merge 1 commit into
shanmugamr1992 wants to merge 1 commit into
Conversation
megatron-core now drops `prompt_tokens` from a finished inference request before serializing it unless `SamplingParams.return_prompt_tokens` is set (NVIDIA/Megatron-LM#5918), so the reply the inference client hands back carries `prompt_tokens=None` and packing the result raised `AttributeError: 'NoneType' object has no attribute 'tolist'`. Take the prompt from the batch that was submitted instead of from the engine's reply. NeMo-RL already holds those tokens, so this avoids shipping the prompt back over ZMQ purely to echo it, and it works against both the old and new megatron-core behaviour without a version branch. Three L1 Megatron generation tests failed outright on this; two async ones exited 0 because the rollout loop catches per-sample generation errors, so they were silently generating nothing. Signed-off-by: shanmugamr1992 <shanmugamr1992@gmail.com>
This was referenced Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found by the nemo-rl-testing-agent while validating NVIDIA/Megatron-LM#5700
against the NeMo-RL Megatron L1 functional suite. The break is not caused by
that PR — it reproduces on megatron-core
main.Failure
Every synchronous Megatron generation path raises:
In the L1 Megatron suite that failed
grpo_megatron_generation,grpo_megatron_generation_non_colocated, andgrpo_megatron_generation_multiturn.Worse,
grpo_megatron_generation_asyncandgrpo_megatron_generation_colocated_asyncexited 0 while every singlegeneration raised the same error:
rollouts.pycatches per-sample generationexceptions (
except Exception: print(...); break), so a completely brokenbackend still produces a rollout and a green test. Those two runs trained on
empty generations and reported success.
Root cause
megatron-core #5918 made the
engine drop
prompt_tokensfrom a finished request before serializing it unlessthe caller sets the new
SamplingParams.return_prompt_tokens. The intent is tokeep large prompt tensors off the engine → coordinator → client path. NeMo-RL was
reading the prompt back out of that reply, so it now gets
None.Fix
Take the prompt from the batch that was submitted rather than from the engine's
reply. NeMo-RL already holds those tokens in
data["input_ids"]/data["input_lengths"]— the same tensors it used to build the request — so thisis the cheaper option as well as the correct one, and it needs no version branch:
it behaves identically against megatron-core revisions that still echo the prompt.
Setting
return_prompt_tokens=Truewould also make the error go away, but itwould pay the transmission cost that #5918 exists to avoid, purely to be told
something we already know.
Validation
main+Megatron-LM#5700: 5 of 6 pass, zero swallowed generation errors (previously 3
hard failures and 2 silently-degraded passes).
grpo_megatron_generation_multiturn, now runs tocompletion and fails a numerics check
(
median(train/token_mult_prob_error)1.99 vs threshold 1.1) with a 100%truncation rate. That is a separate pre-existing problem this crash was hiding;
it is being attributed against a
mainbaseline and is not addressed here.test_megatron_generation_parse.py, covers areply with
prompt_tokens=None, a reply that does echo them (must beidentical), and an empty generation. The end-to-end megatron tests need GPUs and
minutes, which is why a wire-format change like this slipped through.
Draft: raised by an agent, needs a human review before merge.