bridge.models.minicpmo.media#

Per-sample multimodal insertion without modifying embedding views in place.

Module Contents#

Functions#

insert_media_embeddings

Insert media features into half-open token spans, preserving gradients.

API#

bridge.models.minicpmo.media.insert_media_embeddings(
embeddings: torch.Tensor,
features: collections.abc.Sequence[torch.Tensor | collections.abc.Sequence[torch.Tensor]],
bounds: collections.abc.Sequence[torch.Tensor],
*,
occupied: torch.Tensor | None = None,
) → tuple[torch.Tensor, torch.Tensor]#

Insert media features into half-open token spans, preserving gradients.

Parameters:
  • embeddings – Dense token embeddings of shape [batch, sequence, hidden].

  • features – Per-sample features, each a tensor or a sequence of tensors.

  • bounds – Per-sample integer [number_of_spans, 2] start/end positions.

  • occupied – Slots already used by another modality, if any.

Returns:

New embeddings and the combined occupied-slot mask.

Raises:

ValueError – If batch sizes, spans, feature counts or hidden sizes differ.