Repository navigation
feat(models): port Moondream2 VLM (Moondream3 ViT + dense Phi text) - #599
Merged
Merged
Conversation
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.
…t-moondream2 # Conflicts: # src/lib.rs
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports Moondream2 (
vikhyatk/moondream2, configmodel_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, untiedlm_headwith bias, RoPE base 10000) over the unifiedtext.blocks.*/text.wte/text.post_ln/text.lm_headkey space.src/vision/moondream2_vl.rs(+ tests): VL wrapper reusing the Moondream3Moondream3VisionModelandMoondream3Processor, 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::Moondream2VLMplus themoondream2/moondream1detection.rsarm; arch, metadata, and capability tables updated.load_moondream2_vlminvlm_special.rswith amodel.-prefix-stripping weight remap that drops the region head and adds.weightto the tiedtext.wte.LoadedModel/VlmRuntimeRef/vlm_runtimedispatch, plus the CLI and server text-only prompt paths.docs/supported-models.mdgains a Moondream2 entry.Test plan
cargo test --lib moondream2(13 unit tests pass)cargo check --lib --testscargo clippy --lib --tests -- -D warningscargo fmtReal-model forward parity is
#[ignore]-gated and deferred to orchestrator validation.Closes #522