Why turn 2 of a VLM token-capture rollout now returns HTTP 500

NVIDIA-NeMo/RL #4818, one line in vllm_worker_async.py. Permalinks pin head f0d9860e; the old line is linked at base f0639c60.

Before
A captured call that added no new image passed None as its image tensors, and the call staged normally.
This PR
Wraps those tensors in dict(...) so top-K columns can be added to the same mapping. dict(None) raises.
Status
Open โ€” introduced by this PR, not fixed yet. Hits every VLM run with token capture, with score centering on or off. The one-line fix is in the review.

Six pages on this PR, one question each โ€” this one: the image-capture regression.

Background. When the model has an image processor and token capture is on, setup turns on media capture automatically (setup.py:1282). Then every captured call gets a CapturedMedia(items, tensors) (_capture_request_media). tensors holds only the images that are new in this call. Gym sends the whole conversation, so an earlier turn's image is in the prompt again, but that earlier call already staged it: it is only checked, not staged again (captured_media.py L380). So when a call adds no image, tensors is None (capture_processed_media, type dict | None).

Why a score-centering PR touched image capture. Score centering has to ship vLLM's top-K tensors from the vLLM worker to the data plane. The PR's first version did that with a second, separate write, and its own self-review flagged that a failure there was only logged. The fix, commit 0be78315e, moved the top-K tensors into the existing single write, through the attachments mapping. Until then, that mapping only ever held image tensors. To add two more keys, the code copies the image mapping with dict(...). That copy assumes the image tensors are always a mapping, but they are None whenever a call adds no new image. The crash is collateral damage from sharing that slot, and it fires with score centering off because the copy runs on every captured call.

Two turns of one rollout, before and after

before (base f0639c60) after (this PR, head f0d9860e) TURN 1 ยท user sends an image state.media = CapturedMedia(items=(img0,), tensors={"imgs": tensor(โ€ฆ), "imgs_sizes": tensor(โ€ฆ)}) attachments = state.media.tensors โ†’ {"imgs", "imgs_sizes"} ยท staged โœ“ attachments = dict(state.media.tensors) โ†’ {"imgs", "imgs_sizes"} ยท staged โœ“ TURN 2 ยท follow-up text; img0 is in the prompt but already staged state.media = CapturedMedia(items=(), tensors=None) attachments = state.media.tensors (L945) โ†’ None complete_call_from_response(..., attachments=None) staged โœ“ ยท reply sent to Gym attachments = dict(state.media.tensors) (L968) โ†’ TypeError: 'NoneType' object is not iterable raised inside to_thread(...) (L1655): HTTP 500 call already popped: never completed, never failed ALSO HIT any text-only prompt in a VLM run (no image at all โ†’ tensors=None) score centering on or off: the line runs for every captured call works fails (this PR)

Running the real _finish_request_capture from each commit with media=CapturedMedia((), None) and centering off: base stages with attachments=None; head raises TypeError and leaves no capture state behind. The existing VLM token-capture functional tests send one image per call, so they never build a call with tensors=None.

Which calls crash. Every captured call that adds no new image. Two patterns:

Images arrive on turnsCalls with no new image (crash)Rollout dies at
1, 5, 102, 3, 4, 6, 7, 8, 9 (earlier images are in the prompt but already staged)turn 2
6, 7, 8 (text before that)1, 2, 3, 4, 5 (no images at all yet)turn 1

The fix

Where the fix lands: RL only, one line plus a unit test. vllm_worker_async.py L968. No Gym change: Gym already accepts attachments=None, as the base code relied on.

@@ vllm_worker_async.py L968 ยท _finish_request_capture
             )
-        attachments = dict(state.media.tensors) if state.media is not None else {}
+        attachments = dict(state.media.tensors or {}) if state.media is not None else {}
         if sampler_topk is not None:
             attachments.update(

With the fix, turn 2 builds {}; with centering off it stays empty and attachments or None a few lines below (L978-L982) passes None, exactly as before the PR; with centering on it holds only the two top-K tensors. Proposed in the review; not yet applied by the author. A unit test should call _finish_request_capture with CapturedMedia((), None) and check that the call is staged.

So what. Without the fix, any multi-turn VLM rollout with token capture fails on its second model call, and any text-only prompt in a VLM run fails on its first. The failure is a bare HTTP 500 with the capture call left open, so Gym does not even get a capture_failed to recover from. It does not need score centering to be on, so it reaches users who never touch the new feature.

๐Ÿ”ด review comment C1 โ€” vllm_worker_async.py:968