bridge.training.vlm_step#
Module Contents#
Functions#
Return the innermost wrapped module used for forward signature checks. |
|
Drop visual kwargs that the target model forward cannot consume. |
|
Drop visual payload tensors from PP stages that only need visual metadata. |
|
Get a batch of data from the iterator. |
|
Generate a batch. |
|
Forward training step. |
Data#
API#
- bridge.training.vlm_step._VISUAL_PAYLOAD_FIELDS#
‘frozenset(…)’
- bridge.training.vlm_step._PACKED_SEQ_DEVICE_KEYS#
(‘cu_seqlens_q’, ‘cu_seqlens_kv’, ‘cu_seqlens_q_padded’, ‘cu_seqlens_kv_padded’)
- bridge.training.vlm_step._PACKED_SEQ_HOST_KEYS#
(‘max_seqlen_q’, ‘max_seqlen_kv’)
- bridge.training.vlm_step._PACKED_SEQ_PARAM_KEYS#
()
- bridge.training.vlm_step._unwrap_forward_module(model: Any) Any#
Return the innermost wrapped module used for forward signature checks.
- bridge.training.vlm_step._filter_visual_kwargs_for_model(
- model: Any,
- visual_kwargs: collections.abc.Mapping[str, torch.Tensor],
Drop visual kwargs that the target model forward cannot consume.
Shared VLM processors may return model-specific fields such as
mm_token_type_ids. Keep those fields for models that accept them, but avoid passing them through wrappers into models with stricter signatures.
- bridge.training.vlm_step._project_visual_inputs_for_pp_stage(
- visual_inputs: Any,
- *,
- is_first_pp_stage: bool,
Drop visual payload tensors from PP stages that only need visual metadata.
- bridge.training.vlm_step.get_batch_from_iterator(
- data_iterator: Iterable,
- use_mtp: bool = False,
- skip_getting_attention_mask_from_dataset: bool = True,
- *,
- is_first_pp_stage: bool,
- is_last_pp_stage: bool,
Get a batch of data from the iterator.
- Parameters:
data_iterator – The data iterator to get the batch from.
use_mtp – Whether Multi-Token Prediction layers are enabled.
skip_getting_attention_mask_from_dataset – If set, the dataset will pass a None attention mask.
- Returns:
A dictionary containing the batch data.
- Return type:
dict[str, torch.Tensor]
- bridge.training.vlm_step.get_batch(
- data_iterator: Iterable,
- cfg: megatron.bridge.training.config.ConfigContainer,
- use_mtp: bool = False,
- *,
- pg_collection,
Generate a batch.
- Parameters:
data_iterator – Input data iterator
cfg – Configuration container
use_mtp – Whether Multi-Token Prediction layers are enabled
- Returns:
tuple of tensors containing tokens, labels, loss_mask, attention_mask, position_ids, packed sequence metadata, and visual_inputs.
- bridge.training.vlm_step.forward_step(
- state: megatron.bridge.training.state.GlobalState,
- data_iterator: Iterable,
- model: megatron.core.models.gpt.GPTModel,
- return_schedule_plan: bool = False,
Forward training step.
- Parameters:
state – Global state for the run
data_iterator – Input data iterator
model – The GPT Model
return_schedule_plan (bool) – Whether to return the schedule plan instead of the output tensor
- Returns:
tuple containing the output tensor and the loss function