bridge.models.nemotron_omni.data.collate_fn#
Shared Nemotron Omni collation for Direct-HF and Energon datasets.
Module Contents#
Functions#
Build assistant loss masks without treating batch padding as message boundaries. |
|
Validate the model-owned visual input contract retained for API compatibility. |
|
Reject raw text that collides with processor-owned media placeholders. |
|
Right-pad unbatched token rows without deriving padding from token values. |
|
Normalize one image/frame payload to a flat list of PIL images. |
|
Convert one CHW image tensor in either [0, 1] or [0, 255] range to uint8. |
|
Decode raw/path video payloads or flatten already-decoded frame payloads. |
|
Apply the public normalization kernel on MCore’s square temporal canvas. |
|
Return RADIO tokens after the model’s fixed 2x2 spatial pixel shuffle. |
|
Separate structured parts without duplicating source-owned newlines. |
|
Replace structured image parts with literal placeholders in source order. |
|
Build row-local temporal prompts and one packed all-frame vision tensor. |
|
Use the HF processor for text/images while preserving row ownership. |
|
Extract audio features and align each row’s sound placeholder count. |
|
Validate processor-owned media groups and return their placeholder positions. |
|
Split flattened per-media token counts back into their structured rows. |
|
Validate reserved placeholders and mark processor-owned media anchors. |
|
Return per-row lengths after MCore replaces compact image placeholders. |
|
Choose a compact width whose model-side merged width stays in bounds. |
|
Pack compact Omni rows using their lengths after model-side embedding merge. |
|
Build one model-ready Omni batch from either HF or Energon examples. |
|
Collate inputs for the deprecated LLaVA collapse/expand path. |
|
Collate processor-expanded inputs for the canonical Nemotron Omni model. |
Data#
API#
- bridge.models.nemotron_omni.data.collate_fn.CHATML_ASSISTANT_START#
‘<|im_start|>assistant\n’
- bridge.models.nemotron_omni.data.collate_fn.CHATML_ASSISTANT_END#
‘<|im_end|>\n’
- bridge.models.nemotron_omni.data.collate_fn.CHATML_OTHER_ROLE_STARTS#
None
- bridge.models.nemotron_omni.data.collate_fn.VISION_FRAME_SIZE#
512
- bridge.models.nemotron_omni.data.collate_fn.PIXEL_SHUFFLE_FACTOR#
2
- bridge.models.nemotron_omni.data.collate_fn._NEMOTRON_OMNI_VISUAL_KEYS#
(‘pixel_values’,)
- bridge.models.nemotron_omni.data.collate_fn._RESERVED_MEDIA_TEXT#
None
- bridge.models.nemotron_omni.data.collate_fn._build_padded_assistant_loss_masks(
- examples: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
- input_ids: torch.Tensor,
- attention_mask: torch.Tensor,
- processor: Any,
- skipped_tokens: torch.Tensor,
- *,
- boundary_config: megatron.bridge.data.conversation_processing.AssistantMaskBoundaryConfig,
Build assistant loss masks without treating batch padding as message boundaries.
- bridge.models.nemotron_omni.data.collate_fn._validate_nemotron_omni_visual_keys(
- visual_keys: object = None,
Validate the model-owned visual input contract retained for API compatibility.
- bridge.models.nemotron_omni.data.collate_fn._validate_reserved_media_text(
- examples: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
Reject raw text that collides with processor-owned media placeholders.
- bridge.models.nemotron_omni.data.collate_fn._pad_text_rows(
- rows: collections.abc.Sequence[torch.Tensor],
- *,
- pad_token_id: int,
Right-pad unbatched token rows without deriving padding from token values.
- bridge.models.nemotron_omni.data.collate_fn._pil_images(payload: Any) list[Any]#
Normalize one image/frame payload to a flat list of PIL images.
- bridge.models.nemotron_omni.data.collate_fn._tensor_image_to_uint8(image: torch.Tensor) numpy.ndarray#
Convert one CHW image tensor in either [0, 1] or [0, 255] range to uint8.
- bridge.models.nemotron_omni.data.collate_fn._decode_video_path(
- path: str,
- *,
- video_fps: float,
- video_nframes: int,
- bridge.models.nemotron_omni.data.collate_fn._video_frames(
- payload: Any,
- *,
- video_fps: float,
- video_nframes: int,
Decode raw/path video payloads or flatten already-decoded frame payloads.
- bridge.models.nemotron_omni.data.collate_fn._patchify_frame(
- frame: Any,
- *,
- height: int,
- width: int,
- patch_dim: int,
Apply the public normalization kernel on MCore’s square temporal canvas.
The public HF processor preserves video aspect ratio, but pinned MCore’s temporal path currently stacks tubelets and pixel-shuffles them as a common square grid. Until MCore supports ragged non-square tubelets, Bridge keeps the required 512-square compatibility canvas while matching HF’s antialiased bicubic interpolation and RADIO normalization.
- bridge.models.nemotron_omni.data.collate_fn._pixel_shuffled_token_count(
- *,
- height: int,
- width: int,
- patch_dim: int,
Return RADIO tokens after the model’s fixed 2x2 spatial pixel shuffle.
- bridge.models.nemotron_omni.data.collate_fn._join_content_parts(parts: collections.abc.Sequence[str]) str#
Separate structured parts without duplicating source-owned newlines.
- bridge.models.nemotron_omni.data.collate_fn._render_text_conversation(
- example: collections.abc.Mapping[str, Any],
Replace structured image parts with literal placeholders in source order.
- bridge.models.nemotron_omni.data.collate_fn._prepare_temporal_rows(
- examples: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
- processor: Any,
- *,
- temporal_patch_size: int,
- video_fps: float,
- video_nframes: int,
- patch_dim: int,
- temporal_video_resize_mode: Literal[fixed_512, bridge.models.nemotron_omni.data.collate_fn._prepare_temporal_rows.processor],
Build row-local temporal prompts and one packed all-frame vision tensor.
- bridge.models.nemotron_omni.data.collate_fn._prepare_standard_rows(
- examples: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
- processor: Any,
Use the HF processor for text/images while preserving row ownership.
- bridge.models.nemotron_omni.data.collate_fn._audio_waveform(
- example: collections.abc.Mapping[str, Any],
- *,
- target_sampling_rate: int = 16000,
- bridge.models.nemotron_omni.data.collate_fn._add_audio_inputs(
- batch: dict[str, Any],
- examples: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
- processor: Any,
- *,
- max_audio_duration: float,
- num_mel_bins: int,
Extract audio features and align each row’s sound placeholder count.
- bridge.models.nemotron_omni.data.collate_fn._adjust_image_placeholders(
- batch: dict[str, Any],
- loss_mask: torch.Tensor,
- processor: Any,
- num_tiles: torch.Tensor | None,
- bridge.models.nemotron_omni.data.collate_fn._owned_media_positions(
- token_row: torch.Tensor,
- *,
- start_token_id: int,
- end_token_id: int,
- placeholder_token_id: int,
- expected_token_counts: collections.abc.Sequence[int],
- modality: str,
Validate processor-owned media groups and return their placeholder positions.
- bridge.models.nemotron_omni.data.collate_fn._split_media_token_counts(
- token_counts: torch.Tensor | collections.abc.Sequence[int],
- groups_per_row: collections.abc.Sequence[int],
- *,
- modality: str,
Split flattened per-media token counts back into their structured rows.
- bridge.models.nemotron_omni.data.collate_fn._build_media_token_validity_mask(
- batch: collections.abc.Mapping[str, Any],
- processor: Any,
- *,
- image_token_counts: collections.abc.Sequence[collections.abc.Sequence[int]],
- sound_token_counts: collections.abc.Sequence[collections.abc.Sequence[int]],
Validate reserved placeholders and mark processor-owned media anchors.
- bridge.models.nemotron_omni.data.collate_fn._pack_dynamic_images(
- batch: dict[str, Any],
- *,
- patch_dim: int,
- bridge.models.nemotron_omni.data.collate_fn._model_merge_row_lengths(
- batch: collections.abc.Mapping[str, Any],
- processor: Any,
- *,
- use_per_image_token_counts: bool,
- patch_dim: int,
Return per-row lengths after MCore replaces compact image placeholders.
- bridge.models.nemotron_omni.data.collate_fn._nonpacked_multimodal_compact_width(
- batch: collections.abc.Mapping[str, Any],
- post_merge_row_lengths: torch.Tensor,
- *,
- sequence_length: int,
- pad_to_max_length: bool,
- pad_to_multiple_of: int,
Choose a compact width whose model-side merged width stays in bounds.
- bridge.models.nemotron_omni.data.collate_fn._pack_omni_rows_to_mcore_thd(
- batch: dict[str, Any],
- post_merge_row_lengths: torch.Tensor,
- *,
- sequence_length: int | None,
- pad_to_max_length: bool,
- pad_to_multiple_of: int,
- pad_token_id: int,
Pack compact Omni rows using their lengths after model-side embedding merge.
- bridge.models.nemotron_omni.data.collate_fn.nemotron_omni_collate_fn(
- examples: list[collections.abc.Mapping[str, Any]],
- processor: Any,
- start_of_response_token: Any = None,
- *,
- visual_keys: object = None,
- min_pixels: int | None = None,
- max_pixels: int | None = None,
- enable_in_batch_packing: bool = False,
- sequence_length: int | None = None,
- pad_to_max_length: bool = False,
- pad_to_multiple_of: int = 128,
- in_batch_packing_pad_to_multiple_of: int = 1,
- max_audio_duration: float = 30.0,
- num_mel_bins: int = 128,
- temporal_patch_size: int = 2,
- video_fps: float = 1.0,
- video_nframes: int = 8,
- use_temporal_video_embedder: bool = False,
- patch_dim: int = 16,
- temporal_video_resize_mode: Literal[fixed_512, bridge.models.nemotron_omni.data.collate_fn.nemotron_omni_collate_fn.processor] = 'fixed_512',
- collapse_image_tokens: bool = False,
Build one model-ready Omni batch from either HF or Energon examples.
The canonical :class:
NemotronOmniModelconsumes the processor-expanded token sequence, with one image placeholder for every projected feature.temporal_video_resize_mode="processor"uses the image processor’s aspect-preserving video grid and derives each tubelet’s placeholder count from its returned size metadata. Direct collator calls retain the"fixed_512"default; the Energon task encoder opts into processor mode by default. Video frame labels use source-frame timestamps and do not add an implicit prose prefix. Use :func:nemotron_omni_llava_collate_fnfor the legacy LLaVA collapse/expand contract.
- bridge.models.nemotron_omni.data.collate_fn.nemotron_omni_llava_collate_fn(
- *args,
- **kwargs,
Collate inputs for the deprecated LLaVA collapse/expand path.
- bridge.models.nemotron_omni.data.collate_fn.nemotron_omni_expanded_collate_fn(
- *args,
- **kwargs,
Collate processor-expanded inputs for the canonical Nemotron Omni model.