mstar.model.cosmos3.loader#
Weight loading for the Cosmos3 generator backbone and the Edge reasoner’s vision tower.
The published checkpoint is the diffusers transformer/ layout: flat
layers.N.* keys with unfused attention projections (to_q/to_k/to_v for
the understanding pathway, add_q_proj/add_k_proj/add_v_proj for the
generation pathway) and _moe_gen-suffixed GEN MLP/norms. Our backbone
module mirrors that layout one-to-one, so loading needs no key remapping and
no stacked-parameter fusion. The text lm_head is dropped for generators
that never decode text and loaded for checkpoints served as a reasoner.
Edge checkpoints add vision_encoder/model.safetensors (the SigLIP2-style
tower under model.visual.* and the patch-merger projector under
model.projector.*); load_vision_encoder_weights streams it into the
reasoner’s vision module, whose submodules are named visual and
projector so only the model. prefix is stripped.
Functions
|
Map a checkpoint key to a backbone parameter path, or |
|
Stream the |
|
Stream |
|
Return every tensor key declared by the |
|
Return |
|
|
|
- mstar.model.cosmos3.loader.cosmos3_name_remapper(name, with_lm_head=False)[source]#
Map a checkpoint key to a backbone parameter path, or
Noneto drop.Identity for every key the backbone owns;
Nonefor the intentional drop-list (lm_head.weightunless the backbone serves the reasoner). Kept explicit so an unexpected checkpoint key surfaces as a coverage failure rather than being silently ignored.
- mstar.model.cosmos3.loader.load_transformer_weights(model, checkpoint_dir, device='cpu')[source]#
Stream the
transformer/shards intomodeland return loaded keys.Mirrors the meta-device +
load_hf_weightspath the other model packages use, but resolves the shard list from the diffusersdiffusion_pytorch_modelindex (the generic iterator only knows themodel.safetensorsname). No stacked-parameter rules: the checkpoint’s projections are unfused and match the backbone parameter names directly. Raises if any backbone parameter is left unfilled — the completeness guarantee bagel’s loader also enforces.
- mstar.model.cosmos3.loader.load_vision_encoder_weights(model, checkpoint_dir, device='cpu')[source]#
Stream
vision_encoder/model.safetensorsinto the reasoner’s vision module (tower + projector) and return the loaded keys, raising if any parameter is left unfilled.
- mstar.model.cosmos3.loader.read_transformer_weight_keys(checkpoint_dir)[source]#
Return every tensor key declared by the
transformer/shard index.
- mstar.model.cosmos3.loader.read_transformer_weight_shapes(checkpoint_dir)[source]#
Return
{key: shape}for everytransformer/tensor by reading only the safetensors headers — no tensor data is materialized. Enables CPU-side shape verification of the meta-built backbone against the checkpoint.