Skip to content

feat(models): add NVIDIA Cosmos 3 Edge text reasoner backbone - #448

Open
justinchuby wants to merge 1 commit into
mainfrom
feat/cosmos3-edge
Open

feat(models): add NVIDIA Cosmos 3 Edge text reasoner backbone#448
justinchuby wants to merge 1 commit into
mainfrom
feat/cosmos3-edge

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

Adds mobius support for the text reasoner backbone of NVIDIA's cosmos3_edge vision-language checkpoint (nvidia/Cosmos3-Edge, Cosmos3EdgeForConditionalGeneration).

The Cosmos3 series splits into two very different families:

Family Repos What it is This PR
cosmos3_edge nvidia/Cosmos3-Edge Standard-transformers VLM: GQA text reasoner + SigLIP vision + projector text reasoner added
cosmos3_omni Cosmos3-Nano / -Super Two-tower Mixture-of-Transformers diffusion world model (video/audio/action), shipped as a diffusers pipeline ❌ out of scope (diffusion world model)

The text tower

A grouped-query-attention decoder (28 layers, 16 q / 8 kv heads, head_dim 128) with two Cosmos-specific traits:

  • Non-gated squared-ReLU FFNdown_proj(relu2(up_proj(x))) (hidden_act="relu2"), mapped onto the existing FCMLP component (Nemotron precedent) instead of the GLU-style gated MLP.
  • 3D multimodal RoPEmrope_section=[24, 20, 20]; for text-only inference the three sections are identical, reducing to standard 1D RoPE (same simplification as the Qwen-VL text decoders).

preprocess_weights:

  • renames self_attn.to_{q,k,v,out}q/k/v/o_proj,
  • nests the top-level text tower (layers.*, embed_tokens, norm) under model., keeps lm_head at the top level,
  • drops the vision encoder (model.visual.*), the projector (model.projector.*), and the per-layer k_norm_und_for_gen key-norm.

On k_norm_und_for_gen

This per-layer key-norm is a two-tower (MoT) artifact: it normalizes the understanding tower's keys for consumption by the generator (diffusion) tower (hence ..._for_gen). It is not applied in the reasoner's own causal self-attention, so it is dropped for the standalone text decoder. Flagging for reviewer confirmation, since NVIDIA's custom edge modeling code is not yet in transformers.

Testing

  • L1 graph-build: added cosmos3_edge to the parametrized CAUSAL_LM_CONFIGS matrix (relu2 + mrope). pytest tests/build_graph_test.py -k cosmos3_edge → 8 passed.
  • End-to-end config build: build("nvidia/Cosmos3-Edge", load_weights=False) produces a 28-layer GQA decoder (236 initializers) with the non-gated relu2 FFN (mlp.up_proj present, mlp.gate_proj absent). A weight-mapping check confirms every checkpoint tensor lands on a real ONNX initializer with no orphans; vision/projector/k_norm_und_for_gen correctly dropped.
  • tests/model_coverage_test.py → passes (both types recorded in _COVERAGE_SKIP with a reason).

Scope / follow-ups

  • L4/L5 numerical parity is deferred until NVIDIA's cosmos3_edge modeling code lands in transformers (only cosmos3_omni ships today) — needed to verify the k_norm_und_for_gen interpretation and generate golden data.
  • Full VLM (SigLIP vision encoder + spatial-merge projector + 3-model VL task) is a natural follow-up; mobius already has SigLIPVisionModel to build on.
  • Note: mobius build --model nvidia/Cosmos3-Edge routes to the diffusers autodetect (the repo ships a model_index.json); the text reasoner is reachable via the Python build() API / registry.

🤖 Generated with GitHub Copilot CLI

Add support for the text reasoner (language tower) of the cosmos3_edge
vision-language checkpoint (nvidia/Cosmos3-Edge,
Cosmos3EdgeForConditionalGeneration).

The language tower is a standard grouped-query-attention decoder with two
Cosmos-specific traits handled here:

- Non-gated squared-ReLU FFN (hidden_act="relu2",
  down_proj(relu2(up_proj(x)))), mapped onto the existing FCMLP component
  (Nemotron precedent) instead of the GLU-style gated MLP.
- 3D multimodal RoPE (mrope_section=[24, 20, 20]); for text-only inference
  the three sections are identical, reducing to standard 1D RoPE.

preprocess_weights renames the self_attn.to_{q,k,v,out} projections to the
q/k/v/o_proj component names, nests the top-level text tower (layers.*,
embed_tokens, norm) under model., keeps lm_head at the top level, and drops
the vision encoder (model.visual.*), the multimodal projector
(model.projector.*), and the per-layer k_norm_und_for_gen key-norm — the
latter being a two-tower (Mixture-of-Transformers) artifact that normalizes
the understanding tower's keys for the generator (diffusion) tower and is
not applied in the reasoner's own causal self-attention.

Registered as cosmos3_edge / cosmos3_edge_text and exported from
models/__init__.py. L1 graph-build verified via the parametrized
CAUSAL_LM_CONFIGS matrix; end-to-end build from the real config.json
produces a 28-layer GQA decoder with the expected non-gated relu2 FFN.
L4/L5 numerical parity is deferred (NVIDIA's custom edge modeling code is
not in transformers), recorded in _COVERAGE_SKIP. The cosmos3_omni
diffusion world-model variants (Cosmos3-Nano/-Super) are out of scope for
this decoder-only path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: justinchuby <justinchuby@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing 13491cd390852b

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 60 60 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 68 68 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 107 107 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 54 54 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 62 62 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 58 58 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 98 98 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 60 60 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 56 56 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 62 62 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 58 58 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 413 413 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 166 166 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 13491cd390852b

Model Sub-model Changes Status

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support in mobius for NVIDIA Cosmos3-Edge’s decoder-only text reasoner backbone by introducing a dedicated model class that reuses the existing CausalLMModel stack while swapping in a non-gated squared-ReLU FFN and applying Cosmos-specific weight-key remapping.

Changes:

  • Added Cosmos3EdgeTextModel with FCMLP (non-gated relu2) and a preprocess_weights() mapping to rename attention projections, nest the text tower under model., and drop vision/projector + k_norm_und_for_gen weights.
  • Registered cosmos3_edge / cosmos3_edge_text in the model registry and exported the model from mobius.models.
  • Added L1 graph-build coverage via tests/_test_configs.py, and recorded L4/L5 waiver rationale in tests/model_coverage_test.py; documented in CHANGELOG.md.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/model_coverage_test.py Records Cosmos3-Edge as L1-only coverage with explicit L4/L5 parity rationale.
tests/_test_configs.py Adds cosmos3_edge to the causal LM config matrix (relu2 + mRoPE section) for L1 graph-build.
src/mobius/models/cosmos.py Implements the Cosmos3-Edge text reasoner backbone model + weight preprocessing rules.
src/mobius/models/init.py Exports Cosmos3EdgeTextModel.
src/mobius/_registry.py Registers cosmos3_edge / cosmos3_edge_text to the new model and adds default IDs.
CHANGELOG.md Documents the new model support and scope limitations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants