nemo_rl.data.captured_media#
vLLM media extraction and placeholder remapping for shared token capture.
Pixels use the same packed imgs bundle as Megatron inference. Only the
small media_spans extras are vLLM-specific: they restore placeholder
positions when expanded-token history is spliced into a rendered prompt.
Module Contents#
Classes#
One new placeholder occurrence in the expanded token sequence. |
|
New placeholder metadata and owned tensors for the common staging sink. |
|
The geometry of the pixel column a media-capture run publishes. |
Functions#
Return the media capture family for a run’s HF processor. |
|
Fingerprint each media tensor by its dtype, shape, and raw bytes. |
|
Require reprocessed media to match what an interrupted call staged. |
|
Authenticate a vLLM call’s new occurrences before using their layout. |
|
Bind the validated tensor bundle to authenticated occurrence geometry. |
|
Losslessly match Bridge Omni’s dynamic-image patch layout. |
|
Pack one Pixtral image (vLLM’s Mistral3 processor) in Omni’s patch layout. |
|
Validate retained media and capture only newly appended occurrences. |
Data#
API#
- nemo_rl.data.captured_media._MEDIA_CAPTURE_FAMILY_BY_PROCESSOR: dict[str, str]#
None
- nemo_rl.data.captured_media.MEDIA_CAPTURE_FAMILIES#
‘frozenset(…)’
- nemo_rl.data.captured_media.media_capture_family(processor: Any) str | None#
Return the media capture family for a run’s HF processor.
- Parameters:
processor – The run’s HF processor.
- Returns:
"omni"or"pixtral", orNonewhen token capture cannot stage this processor’s media.
- exception nemo_rl.data.captured_media.MediaCaptureRejected(
- message: str,
- *,
- code: str = 'media_capture_rejected',
Bases:
ValueErrorA captured call’s media cannot be staged; the request is rejected before inference.
codeis a stable, machine-readable reason surfaced in the HTTP 400 body and the worker log.retained_media_changedmarks a retained image or video whose geometry, placeholder tokens, or processed pixels differ from the staged occurrence (e.g. vLLM re-tiled it under a tighter token budget); every other capture-time validation failure usesmedia_capture_rejected.Initialization
Initialize self. See help(type(self)) for accurate signature.
- nemo_rl.data.captured_media._token_digest(tokens: list[int]) str#
- class nemo_rl.data.captured_media.CapturedMediaItem#
One new placeholder occurrence in the expanded token sequence.
- modality: Literal[image, video]#
None
- placeholder_offset: int#
None
- placeholder_length: int#
None
- placeholder_digest: str#
None
- token_id: int#
None
- embedding_spans: tuple[tuple[int, int], ...]#
None
- imgs_sizes: tuple[tuple[int, int], ...]#
None
- __post_init__() None#
- property end: int#
- to_dict() dict[str, Any]#
- classmethod from_dict(
- value: dict[str, Any],
- verify_tokens(tokens: list[int], *, origin: int) None#
- class nemo_rl.data.captured_media.CapturedMedia#
New placeholder metadata and owned tensors for the common staging sink.
tensor_digestsfingerprintstensors(seemedia_tensor_digests) when generation-prefix cuts are on. A media bundle restored from a prefix row carries the staged digests and no tensors.- items: tuple[nemo_rl.data.captured_media.CapturedMediaItem, ...]#
None
- tensors: dict[str, torch.Tensor] | None#
None
- tensor_digests: dict[str, dict[str, Any]] | None#
None
- nemo_rl.data.captured_media.MEDIA_TENSOR_DIGESTS_FIELD#
‘media_tensor_digests’
- nemo_rl.data.captured_media.media_tensor_digests(
- tensors: collections.abc.Mapping[str, torch.Tensor] | None,
Fingerprint each media tensor by its dtype, shape, and raw bytes.
- nemo_rl.data.captured_media.verify_restored_media(
- captured: nemo_rl.data.captured_media.CapturedMedia,
- restored: nemo_rl.data.captured_media.CapturedMedia,
Require reprocessed media to match what an interrupted call staged.
- Parameters:
captured – The media just reprocessed from the resumed request.
restored – The items and tensor digests read from the call’s first generation-prefix row.
- Raises:
MediaCaptureRejected –
retained_media_changedwhen the items or any tensor’s dtype, shape, or bytes differ.
- nemo_rl.data.captured_media.verified_media_items( ) tuple[nemo_rl.data.captured_media.CapturedMediaItem, ...]#
Authenticate a vLLM call’s new occurrences before using their layout.
Token/lineage verification stays with the shared capture verifier. Extras have a separate commitment, including routes when present, which their media consumer must check even when route replay is disabled.
- nemo_rl.data.captured_media.verify_media_geometry(
- items: tuple[nemo_rl.data.captured_media.CapturedMediaItem, ...],
- media: nemo_rl.data_plane.tq_token_sink.StagedMediaTensors,
Bind the validated tensor bundle to authenticated occurrence geometry.
- class nemo_rl.data.captured_media.MediaColumnSpec#
The geometry of the pixel column a media-capture run publishes.
Reported by the serving worker that pins the staging column (it alone knows the vision encoder’s weight dtype and the model patch size) and handed to the reassembler, which needs it to mint zero-row media for a group in which no rollout carried media: those rows must land in the trainer partition with the same dtype and patch width as media rows, or TransferQueue sees a second dtype on the field.
- pixel_dtype: torch.dtype#
None
- patch_size: int#
None
- __post_init__() None#
- property pixel_feature_dim: int#
Width of one packed patch row:
3 * P * P(seepack_images).
- nemo_rl.data.captured_media._geometry_tensor(value: Any) torch.Tensor#
- nemo_rl.data.captured_media.pack_images(
- pixels: torch.Tensor,
- sizes: torch.Tensor,
- *,
- patch_size: int,
Losslessly match Bridge Omni’s dynamic-image patch layout.
This only rearranges processed pixels, preserving dtype and values. Frames remain in order and their temporal grouping travels separately in num_frames.
Mirrors
NemotronOmniModel._patchify_dynamic_imagesin Megatron-Bridge (the vLLM worker env has no Bridge);test_captured_media_pack_images_matches_bridge_patchify(mcore lane) guards the two against drift.
- nemo_rl.data.captured_media._processed_omni_tensors(
- data: dict[str, Any],
- modality: str,
- *,
- patch_size: int,
- nemo_rl.data.captured_media._processed_pixtral_tensors(
- data: dict[str, Any],
- modality: str,
- *,
- patch_size: int,
- pixel_dtype: torch.dtype | None,
Pack one Pixtral image (vLLM’s Mistral3 processor) in Omni’s patch layout.
vLLM’s Mistral3 processor keeps one
pixel_valuestensor per image, already cropped to the image’s processed size, so the geometry is the tensor’s own[H, W]. The processor emits float32 and the engine casts to the model dtype inside the vision tower, so the pixels are cast topixel_dtype(the staging column’s pinned dtype) here instead of being staged in a second dtype. The packed layout is the onenemo_rl.data.multimodal_utils._patchify_segmentsproduces.
- nemo_rl.data.captured_media.capture_processed_media(
- engine_prompt: dict[str, Any],
- *,
- prev_len: int,
- retained: tuple[nemo_rl.data.captured_media.CapturedMediaItem, ...] = (),
- splice: nemo_rl.models.generation.openai_server_utils.PrefixSplice | None = None,
- image_token_id: int | None = None,
- patch_size: int | None = None,
- retained_tensors: tuple[nemo_rl.data_plane.tq_token_sink.StagedMediaTensors, ...] | None = None,
- media_family: str = 'omni',
- cast_pixel_dtype: torch.dtype | None = None,
- spatial_merge_size: int | None = None,
Validate retained media and capture only newly appended occurrences.
Framework-owned continuations also compare processed tensors with their staged predecessors before reusing them in a shared training segment.
media_familyis"omni"(Nemotron Omni dynamic tiler) or"pixtral"(vLLM’s Mistral3 / Pixtral processor). Pixtral images are rows of image tokens, each row ended by a break token and the last by an end token, so an image has one embedding run per row;spatial_merge_sizelets the embedding count be checked against the image geometry.cast_pixel_dtype(Pixtral only) is the staging column’s pinned pixel dtype.