bridge.models.kimi_vl.data.collate_fn#
Kimi VL collator implementations.
Module Contents#
Functions#
Build Kimi assistant loss boundaries and trim only empty thinking blocks. |
|
Expand image placeholder tokens and any aligned per-token loss mask. |
|
Expand image placeholder tokens to the correct count based on grid_thws. |
|
Collate function for Kimi K2.5 VL processors with pre-expanded image tokens. |
Data#
API#
- bridge.models.kimi_vl.data.collate_fn.KIMI_ASSISTANT_START#
β<|im_assistant|>assistant<|im_middle|>β
- bridge.models.kimi_vl.data.collate_fn.KIMI_ASSISTANT_END#
β<|im_end|>β
- bridge.models.kimi_vl.data.collate_fn.KIMI_THINK_OPEN#
β
β
- bridge.models.kimi_vl.data.collate_fn.KIMI_THINK_CLOSE#
ββ
- bridge.models.kimi_vl.data.collate_fn._kimi_assistant_mask_boundary_config(
- processor: Any,
Build Kimi assistant loss boundaries and trim only empty thinking blocks.
- bridge.models.kimi_vl.data.collate_fn._expand_image_tokens_and_aligned_mask(
- input_ids: torch.Tensor,
- attention_mask: torch.Tensor,
- loss_mask: torch.Tensor | None,
- grid_thws: torch.Tensor,
- media_token_id: int,
- merge_kernel_size: tuple[int, int] = (2, 2),
Expand image placeholder tokens and any aligned per-token loss mask.
- bridge.models.kimi_vl.data.collate_fn._expand_image_tokens(
- input_ids: torch.Tensor,
- attention_mask: torch.Tensor,
- grid_thws: torch.Tensor,
- media_token_id: int,
- merge_kernel_size: tuple[int, int] = (2, 2),
Expand image placeholder tokens to the correct count based on grid_thws.
For PP, this ensures the sequence length is fixed BEFORE the model forward pass, eliminating dynamic sequence expansion inside the model.
- Parameters:
input_ids β (seq_len,) tensor with one placeholder per image
attention_mask β (seq_len,) tensor
grid_thws β (num_images, 3) tensor with [t, h, w] for each image
media_token_id β Token ID of the image placeholder
merge_kernel_size β Vision towerβs patch merge kernel, default (2, 2)
- Returns:
Input IDs with placeholder expanded to N tokens expanded_attention_mask: Attention mask expanded accordingly
- Return type:
expanded_input_ids
- bridge.models.kimi_vl.data.collate_fn.kimi_k25_vl_collate_fn(
- examples: list[dict[str, Any]],
- processor,
- max_length: int | None = None,
- *,
- visual_keys: object = None,
- min_pixels: int | None = None,
- max_pixels: int | None = None,
- sequence_length: int | None = None,
- pad_to_max_length: bool = False,
- pad_to_multiple_of: int = 128,
- enable_in_batch_packing: bool = False,
- in_batch_packing_pad_to_multiple_of: int = 1,
Collate function for Kimi K2.5 VL processors with pre-expanded image tokens.
For pipeline parallelism, this function:
Processes each sample to get input_ids with 1 placeholder per image
Pre-expands each placeholder to N tokens (N = t*(h//2)*(w//2) from grid_thws)
Pads all sequences to fixed max_length This ensures the model forward pass doesnβt change sequence length dynamically.