Skip to content

vllm.model_executor.models.moondream3

Inference-only Moondream3 model implementation.

Classes:

Functions:

Moondream3Attention

Bases: Module

Decoder attention with RoPE and tau scaling.

Moondream3 uses a tau attention mechanism that scales Q and V based on both token content and position.

Moondream3DecoderLayer

Bases: Module

Decoder layer with attention + MLP/MoE.

Moondream3DummyInputsBuilder

Bases: BaseDummyInputsBuilder[Moondream3ProcessingInfo]

Dummy inputs builder for profiling.

Moondream3ForCausalLM

Bases: Module, SupportsMultiModal, SupportsPP

Moondream3 multimodal model for causal language modeling.

vLLM supports the standard autoregressive Moondream3 query and caption prompt formats. The region-module point/detect skills require custom coordinate decoding and are intentionally not exposed here.

Methods:

  • embed_multimodal –

    Generate the HF image prefix: BOS embedding + 729 image embeddings.

  • load_weights –

    Load weights with remapping from HuggingFace format.

embed_multimodal(**kwargs)

Generate the HF image prefix: BOS embedding + 729 image embeddings.

load_weights(weights)

Load weights with remapping from HuggingFace format.

Moondream3ImageInput dataclass

Container holding per-image inputs for embedding.

Moondream3MultiModalProcessor

Bases: BaseMultiModalProcessor[Moondream3ProcessingInfo]

Multimodal processor for Moondream3.

Moondream3ProcessingInfo

Bases: BaseProcessingInfo

Processing info for Moondream3.

Moondream3TextMLP

Bases: Module

Standard MLP for non-MoE layers (layers 0-3).

Moondream3TextMoE

Bases: Module

Mixture of Experts layer for layers 4+ with expert parallelism.

Moondream3 uses a custom GeGLU activation: gelu(h) * (g + 1) where fc1 outputs [gate, up] and the activation is gelu(gate) * (up + 1).

Uses expert parallelism where each GPU stores num_experts/tp_size experts. Routing and communication handled via all-to-all or replicated computation.

Checkpoint format: - fc1.weight: [num_experts, expert_inner_dim * 2, hidden_size] (gate+up) - fc2.weight: [num_experts, hidden_size, expert_inner_dim] (down) - router.weight: [num_experts, hidden_size] - router.bias: [num_experts]

Methods:

  • forward –

    Forward pass with expert parallelism and custom GeGLU activation.

_expert_loop(x, topk_weights, topk_ids)

Fallback for environments where fused kernels are unavailable.

Returns this rank's partial output; the caller performs the all-reduce.

forward(x)

Forward pass with expert parallelism and custom GeGLU activation.

Moondream3TextModel

Bases: Module

Text decoder model.

Moondream3VisionAttention

Bases: Module

Self-attention for vision encoder (bidirectional).

Moondream3VisionBlock

Bases: Module

Transformer block for vision encoder.

Moondream3VisionEncoder

Bases: Module

Vision encoder (SigLIP-style ViT).

Methods:

create_patches(images)

Convert images to patch embeddings.

Parameters:

  • images

    (Tensor) –

    (batch, channels, height, width)

Returns:

  • patches ( Tensor ) –

    (batch, num_patches, patch_dim)

forward(pixel_values)

Encode images.

Parameters:

  • pixel_values

    (Tensor) –

    (batch, channels, height, width)

Returns:

  • features ( Tensor ) –

    (batch, num_patches, hidden_size)

Moondream3VisionMLP

Bases: Module

MLP for vision encoder blocks.

Moondream3VisionProjection

Bases: Module

Projects vision features to text embedding dimension.

reconstruct_from_crops(crops, tiling, overlap_margin, patch_size=14)

Reconstruct features from overlapping crops.