Skip to content

feat(models): port Moondream2 VLM (Moondream3 ViT + dense Phi text) - #599

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-522-port-moondream2
Jul 1, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-522-port-moondream2

Conversation

@inureyes

@inureyes inureyes commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Ports Moondream2 (vikhyatk/moondream2, config model_type: moondream1) as a vision-language model so its checkpoints load instead of erroring "Unsupported model type". Moondream2 is architecturally Moondream3 minus the sparse-MoE decoder, so it reuses Moondream3's vision tower and crop preprocessor and adds a dense Phi-1.5-style text decoder.

What changed

New modules:

  • src/models/moondream2.rs (+ tests): dense Phi-style text decoder (fused QKV, partial rotary over half the head, parallel attention/MLP on one shared LayerNorm, tanh-approximate GELU, untied lm_head with bias, RoPE base 10000) over the unified text.blocks.* / text.wte / text.post_ln / text.lm_head key space.
  • src/vision/moondream2_vl.rs (+ tests): VL wrapper reusing the Moondream3 Moondream3VisionModel and Moondream3Processor, prepending BOS plus 729 projected image tokens as a bidirectional prefix ahead of the causal prompt.
  • src/multimodal/moondream2_prompt.rs (+ tests): question/answer prompt shaping for the query and caption paths.
  • tests/moondream2_parity.rs: checkpoint-free detection, config, and processor parity tests plus ignore-gated real-model forward smoke tests.

Registration and wiring:

  • ModelType::Moondream2VLM plus the moondream2 / moondream1 detection.rs arm; arch, metadata, and capability tables updated.
  • load_moondream2_vlm in vlm_special.rs with a model.-prefix-stripping weight remap that drops the region head and adds .weight to the tied text.wte.
  • LoadedModel / VlmRuntimeRef / vlm_runtime dispatch, plus the CLI and server text-only prompt paths.
  • docs/supported-models.md gains a Moondream2 entry.

Test plan

  • cargo test --lib moondream2 (13 unit tests pass)
  • cargo check --lib --tests
  • cargo clippy --lib --tests -- -D warnings
  • cargo fmt

Real-model forward parity is #[ignore]-gated and deferred to orchestrator validation.

Closes #522

Add Moondream2 (config model_type moondream1) as a vision-language model. A Moondream2 checkpoint previously errored "Unsupported model type" because detection only carried a moondream3 arm.

Moondream2 is architecturally Moondream3 minus the sparse-MoE decoder: it reuses Moondream3's linear-patch ViT vision tower and overlap-crop preprocessor, and pairs them with a dense Phi-1.5-style text decoder (fused QKV, partial rotary over half the head, parallel attention/MLP on one shared LayerNorm, tanh-approximate GELU, untied lm_head with bias, RoPE base 10000).

New modules:

- src/models/moondream2.rs: dense Phi-style text decoder over the unified text.blocks.* / text.wte / text.post_ln / text.lm_head key space.
- src/vision/moondream2_vl.rs: VL wrapper reusing the Moondream3 vision tower and processor, prepending BOS plus 729 projected image tokens as a bidirectional prefix ahead of the causal prompt.
- src/multimodal/moondream2_prompt.rs: question/answer prompt shaping for the query and caption paths.
- tests/moondream2_parity.rs: checkpoint-free detection, config, and processor parity tests plus ignore-gated real-model forward smoke tests.

Registration: ModelType::Moondream2VLM, the moondream2/moondream1 detection arm, load_moondream2_vlm with the model-prefix-stripping weight remap, and the LoadedModel, VlmRuntimeRef, metadata, and arch tables. docs/supported-models.md gains a Moondream2 entry.

Validated with cargo test --lib moondream2 (13 unit tests), cargo check --lib --tests, and cargo clippy --lib --tests -- -D warnings. Real-model forward parity is deferred to orchestrator validation.
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata status:done Completed labels Jul 1, 2026
@inureyes
inureyes merged commit d9285c1 into main Jul 1, 2026
4 checks passed
@inureyes
inureyes deleted the feature/issue-522-port-moondream2 branch July 2, 2026 13:49
@inureyes inureyes self-assigned this Aug 31, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…ablup#599)

Add Moondream2 (config model_type moondream1) as a vision-language model. A Moondream2 checkpoint previously errored "Unsupported model type" because detection only carried a moondream3 arm.

Moondream2 is architecturally Moondream3 minus the sparse-MoE decoder: it reuses Moondream3's linear-patch ViT vision tower and overlap-crop preprocessor, and pairs them with a dense Phi-1.5-style text decoder (fused QKV, partial rotary over half the head, parallel attention/MLP on one shared LayerNorm, tanh-approximate GELU, untied lm_head with bias, RoPE base 10000).

New modules:

- src/models/moondream2.rs: dense Phi-style text decoder over the unified text.blocks.* / text.wte / text.post_ln / text.lm_head key space.
- src/vision/moondream2_vl.rs: VL wrapper reusing the Moondream3 vision tower and processor, prepending BOS plus 729 projected image tokens as a bidirectional prefix ahead of the causal prompt.
- src/multimodal/moondream2_prompt.rs: question/answer prompt shaping for the query and caption paths.
- tests/moondream2_parity.rs: checkpoint-free detection, config, and processor parity tests plus ignore-gated real-model forward smoke tests.

Registration: ModelType::Moondream2VLM, the moondream2/moondream1 detection arm, load_moondream2_vlm with the model-prefix-stripping weight remap, and the LoadedModel, VlmRuntimeRef, metadata, and arch tables. docs/supported-models.md gains a Moondream2 entry.

Validated with cargo test --lib moondream2 (13 unit tests), cargo check --lib --tests, and cargo clippy --lib --tests -- -D warnings. Real-model forward parity is deferred to orchestrator validation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): port Moondream2 (SigLIP vision + Phi text + crop tiling)

1 participant