mstar.model.cosmos3.components.vision#
The Cosmos3-Edge reasoner’s vision tower and projector.
A packed, variable-resolution SigLIP2-style encoder (visual): a linear
patch embedding over patch_size x patch_size RGB patches, a learned square
position grid bilinearly resized to every frame’s patch grid, N pre-LayerNorm
encoder blocks whose attention stays within one frame, and a post LayerNorm.
The projector (projector) merges each 2x2 block of patches into one token
(LayerNorm per patch -> concat -> Linear -> GELU -> Linear) in the text hidden
size, which the understanding tower consumes in place of the <|image_pad|>
/ <|video_pad|> tokens.
Parameter names follow vision_encoder/model.safetensors with its leading
model. stripped (see loader.vision_encoder_name_remapper), so the
checkpoint loads by name. Shapes and the packed patch order come from the
Hugging Face Cosmos3EdgeVisionModel / Cosmos3EdgePatchMerger.
Frames of one video share a grid, and an image is a single frame, so the attention runs one batched SDPA per distinct frame size instead of a block-diagonal mask over the whole pack.
Functions
|
Non-causal attention within each frame of a packed |
|
Resize the learned |
Classes
|
|
|
|
|
|
|
|
|
|
|
|
|
Vision tower + projector: packed pixel patches -> text-space tokens. |
|
|
- class mstar.model.cosmos3.components.vision.Cosmos3PatchMerger(config)[source]#
Bases:
Moduleprojector: per-patch LayerNorm, 2x2 merge into the channel dim, Linear -> GELU -> Linear into the text hidden size.- Parameters:
config (Cosmos3ReasonerConfig)
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.cosmos3.components.vision.Cosmos3VisionAttention(config)[source]#
Bases:
Module- Parameters:
config (Cosmos3VisionEncoderConfig)
- forward(x, frame_lens)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.cosmos3.components.vision.Cosmos3VisionEmbeddings(config)[source]#
Bases:
Module- Parameters:
config (Cosmos3VisionEncoderConfig)
- forward(pixel_values, grid_thw)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.cosmos3.components.vision.Cosmos3VisionEncoder(config)[source]#
Bases:
Module- Parameters:
config (Cosmos3VisionEncoderConfig)
- forward(x, frame_lens)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.cosmos3.components.vision.Cosmos3VisionEncoderLayer(config)[source]#
Bases:
Module- Parameters:
config (Cosmos3VisionEncoderConfig)
- forward(x, frame_lens)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.cosmos3.components.vision.Cosmos3VisionMLP(config)[source]#
Bases:
Module- Parameters:
config (Cosmos3VisionEncoderConfig)
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.cosmos3.components.vision.Cosmos3VisionModel(config)[source]#
Bases:
ModuleVision tower + projector: packed pixel patches -> text-space tokens.
pixel_valuesis[total_patches, 3 * patch_size**2]in the processor’s block-major order (seecomponents.reasoner),grid_thwone(t, h, w)patch grid per image/video. Returns[total_patches // merge_size**2, text_hidden]: one token per merged 2x2 block, in the order the<|image_pad|>/<|video_pad|>tokens appear in the prompt.- Parameters:
config (Cosmos3ReasonerConfig)
- forward(pixel_values, grid_thw)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.cosmos3.components.vision.Cosmos3VisionTransformer(config)[source]#
Bases:
Modulevisual: embeddings -> encoder -> post LayerNorm, over packed patches.- Parameters:
config (Cosmos3VisionEncoderConfig)
- forward(pixel_values, grid_thw)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- mstar.model.cosmos3.components.vision.frame_attention(q, k, v, frame_lens)[source]#
Non-causal attention within each frame of a packed
[N, H, D]batch.frame_lenslists the consecutive frame token counts. Frames of equal length are batched into one SDPA call; the outputs come back in pack order.
- mstar.model.cosmos3.components.vision.resize_position_grid(grid_embeds, grid_thw, merge_size)[source]#
Resize the learned
[S, S, hidden]position grid to every frame’s(h, w)patch grid and lay it out in the processor’s block-major (2x2-merge) patch order, repeated over the frame’st.Bilinear,
align_corners=False, antialiased — the reference’sF.interpolatecall; fp32 on CPU because antialias has no bf16 kernel there. Returns[total_patches, hidden]in pack order.