bridge.models.qwen_vl.data.energon#
Module Contents#
Classes#
HF-style Qwen VLM sample produced from an Energon |
|
Batched Qwen VLM tensors produced by the shared HF collate function. |
|
Energon task encoder for Qwen VL samples. |
Functions#
Minimal vision preprocessing wrapper using the provided processor (e.g., HF AutoProcessor). |
|
Resolve HF tokenizer ids for |
|
Return merged visual token count for THW grid metadata. |
|
Split user input into format QwenVL tokenizer accepts. |
API#
- bridge.models.qwen_vl.data.energon.process_vision(
- processor,
- images,
- videos,
- fps=None,
- model_version: str = 'qwen-vl',
- min_pixels=None,
- max_pixels=None,
Minimal vision preprocessing wrapper using the provided processor (e.g., HF AutoProcessor).
- bridge.models.qwen_vl.data.energon._resolve_hf_mm_token_ids(hf_tokenizer)#
Resolve HF tokenizer ids for
and
- bridge.models.qwen_vl.data.energon._visual_token_count(grid_thw: Any, merge_size: int) int#
Return merged visual token count for THW grid metadata.
- class bridge.models.qwen_vl.data.energon.QwenVLTaskSample#
HF-style Qwen VLM sample produced from an Energon
ChatMLSample.Expected input format: Produced by
QwenVLTaskEncoder.encode_samplefrom an EnergonChatMLSample.examplefollows the HF VLM collate schema:{"conversation": [{"role": ..., "content": [...]}, ...]}with inline{"type": "image"|"video", ...}media parts.Output format: Consumed by
QwenVLTaskEncoder.batch, which passes theexampledictionaries to the same Qwen collate function used by HF-style VLM datasets.- __key__: str#
None
- __subflavors__: Dict#
None
- example: Dict[str, Any]#
None
- class bridge.models.qwen_vl.data.energon.QwenVLTaskBatch#
Bases:
megatron.energon.BatchBatched Qwen VLM tensors produced by the shared HF collate function.
- __keys__: List[str]#
None
- __subflavors__: List[Dict]#
None
- input_ids: torch.Tensor#
None
- position_ids: torch.Tensor#
None
- labels: torch.Tensor#
None
- loss_mask: torch.Tensor#
None
- visual_inputs: megatron.bridge.training.utils.visual_inputs.GenericVisualInputs | None#
None
- attention_mask: torch.Tensor | None#
None
- cu_seqlens_q: torch.Tensor | None#
None
- cu_seqlens_kv: torch.Tensor | None#
None
- cu_seqlens_q_padded: torch.Tensor | None#
None
- cu_seqlens_kv_padded: torch.Tensor | None#
None
- max_seqlen_q: torch.Tensor | None#
None
- max_seqlen_kv: torch.Tensor | None#
None
- bridge.models.qwen_vl.data.energon.convert_to_qwenvl_content(
- user_input: str,
- image_pattern: str = '<image>',
- video_pattern: str = '<video>',
Split user input into format QwenVL tokenizer accepts.
- class bridge.models.qwen_vl.data.energon.QwenVLTaskEncoder(
- tokenizer,
- image_processor,
- temporal_patch_size: int = 2,
- spatial_merge_size: int = 2,
- patch_size: int = 14,
- max_padding_length: int = 4096,
- min_pixels: int = 200704,
- max_pixels: int = 1003520,
- max_num_images: int | None = 10,
- max_num_frames: int | None = 60,
- max_visual_tokens: int | None = 16384,
- 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,
Bases:
megatron.energon.DefaultTaskEncoder[megatron.bridge.data.energon.task_encoder_utils.ChatMLSample,bridge.models.qwen_vl.data.energon.QwenVLTaskSample,bridge.models.qwen_vl.data.energon.QwenVLTaskBatch,dict]Energon task encoder for Qwen VL samples.
- Parameters:
tokenizer – HF tokenizer for resolving multimodal token ids.
image_processor – HF processor passed to the Qwen collate function.
temporal_patch_size – Temporal patch size used for video token accounting.
spatial_merge_size – Spatial merge size used for visual token accounting.
patch_size – Vision patch size.
max_padding_length – Maximum sequence length accepted after collation.
min_pixels – Minimum pixel constraint forwarded to Qwen vision processing.
max_pixels – Maximum pixel constraint forwarded to Qwen vision processing.
max_num_images – Optional per-sample image count limit.
max_num_frames – Optional per-video frame limit.
max_visual_tokens – Optional per-sample visual token budget.
pad_to_max_length – Whether collate-time padding should pad non-packed batches to
max_padding_length.pad_to_multiple_of – Non-packed collate-time padding multiple used when
pad_to_max_lengthis false.enable_in_batch_packing – Whether the Qwen collate should do in-batch sequence packing.
in_batch_packing_pad_to_multiple_of – Per-sample padding multiple used only by the in-batch packed path, typically to satisfy CP/SP divisibility.
Initialization
- encode_sample(
- sample: megatron.bridge.data.energon.task_encoder_utils.ChatMLSample,
Normalize one Energon sample into the HF-style Qwen collate schema.
Expected input format:
sampleis an EnergonChatMLSamplewith JSONconversationand optional decodedimgs/videosmedia payloads.Output format: Returns
QwenVLTaskSamplewhoseexampleis a HF-style VLM collate dictionary:{"conversation": [{"role": ..., "content": [{"type": ...}, ...]}]}. Tokenization, image/video preprocessing, labels, and loss masks are intentionally deferred toself.collate_fnso HF and Energon data paths share the same Qwen model processing.
- collate_fn(
- examples: List[Dict[str, Any]],
Collate Qwen HF-style examples with the shared HF dataset collator.
Expected input format:
examplesis a list of dictionaries in the same schema returned by HF-style VLM datasets: each item hasconversationmessages with multimodalcontentparts.Output format: Returns the exact dictionary produced by
qwen2_5_collate_fn:input_ids,labels,loss_mask,position_ids, optionalattention_mask, andvisual_inputs.
- batch(
- samples: List[bridge.models.qwen_vl.data.energon.QwenVLTaskSample],
Collate normalized Energon samples with the shared Qwen HF collator.
Expected input format:
samplesareQwenVLTaskSampleobjects whoseexamplefields follow the HF VLM collate schema.Output format: Returns
QwenVLTaskBatchcarrying the same tensors asqwen2_5_collate_fnplus Energon batch metadata.
- encode_batch( ) dict#
Encode batch in dict