PR #5097 (part 6 of 6) · permalinks at head e6beabe5, Megatron-LM pin e0a4bfed, ai-dynamo 1.8.0.dev20261117
except ValueError and answers every catch with a 400 refusal.Four pages for this PR, one question each: this one shows one bug.
A refusal tells Gym "your request was wrong". The comment on the catch says it is meant for one thing: Megatron-LM refusing the request, which its own endpoint answers with 400. But Python's ValueError is wider than that. Two server faults raise a plain ValueError inside the same block. One is Dynamo's check that a decode leg got its prefill result (called here), which fails when a decode leg arrives without one. The other is a validation error while staging the capture, after the tokens already exist.
Where the fix lands: RL only, one source file and one test. adapter.py catches only Megatron-LM's own refusal type. test_dynamo_megatron_adapter.py raises that type instead of a plain ValueError. No Megatron-LM or Dynamo change.
Decode leg, today
# decode engine, rank zero, one task per Gym call try: chunk = await serve_gym_call() # generate (a, b), then stage (c) except ValueError: # catches (a), (b) and (c) chunk = refusal(400) # Gym: "your request was bad"
The fix, as pseudocode (proposed, not run)
# decode engine, rank zero, one task per Gym call try: chunk = await serve_gym_call() # generate (a, b), then stage (c) except ValueError: except InferenceRequestRejected: # only (a): Megatron-LM refused it chunk = refusal(400) # (b), (c) raise → chat engine answers 500
Megatron-LM's other plain ValueErrors (sampling checks) cannot be reached from a Gym call, because gym_sampling_request always sends n=1 and log probs 0 or none.
InferenceRequestRejected keeps Megatron-LM's own 400 and sends everything else down the chat engine's 500 path.