#338·moondream

Bug: Missing Hugging Face Integration Files and Broken `from_pretrained()` Support

Author: Muhammad-Ikhwan-FathullohCreated Jun 23, 2026Updated Jun 23, 2026

Description

Several components required for Hugging Face integration appear to be missing or incomplete, causing import failures and preventing the model from being loaded through standard Hugging Face APIs.

The following issues were identified:

1. Missing Hugging Face Module Files

The moondream/hf/ package is incomplete and missing essential files:

  • moondream/hf/util.py
  • moondream/hf/moondream.py
  • moondream/hf/__init__.py

Additionally, the root package is missing:

  • moondream/__init__.py

As a result, imports such as:

python
from moondream.hf import Moondream

fail because the Hugging Face integration layer is unavailable.


2. Broken generate() Implementation

The current implementation of HfMoondream.generate() does not correctly forward generation parameters to the underlying _generate_answer() function.

This causes generation calls to fail or behave unexpectedly because required arguments such as pos and generation settings are not properly passed through.


3. Missing from_pretrained() Support

HfMoondream does not provide a functional from_pretrained() implementation compatible with Hugging Face workflows.

Expected behavior:

  • Download model files from Hugging Face Hub.
  • Locate model weights (.safetensors or .pt).
  • Load weights into the model automatically.
  • Support standard usage patterns.

Current behavior:

python
from moondream.hf import Moondream

model = Moondream.from_pretrained("vikhyatk/moondream2")

fails because the loading mechanism is not implemented.


4. Missing Backward Compatibility

Several legacy interfaces appear to be unsupported:

caption()

Expected to accept:

python
model.caption([image], tokenizer=tokenizer)

encode_image()

Expected to accept:

python
model.encode_image([image])

Current implementations are incompatible with previous usage patterns.


Expected Behavior

The library should support both native and Hugging Face loading workflows:

python
from moondream.hf import Moondream

model = Moondream.from_pretrained("vikhyatk/moondream2")

and

python
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(
    "vikhyatk/moondream2",
    trust_remote_code=True
)

without import errors or additional manual setup.


Proposed Fix

  • Restore moondream/hf/util.py

    • Add detect_device()
    • Add LATEST_REVISION
  • Restore moondream/hf/moondream.py

    • Re-export HfMoondream
    • Re-export HfConfig
    • Register Hugging Face Auto classes
  • Restore:

    • moondream/hf/__init__.py
    • moondream/__init__.py
  • Fix HfMoondream.generate() to correctly call _generate_answer() with required parameters.

  • Implement HfMoondream.from_pretrained() using:

    • huggingface_hub.snapshot_download
    • automatic checkpoint discovery
    • load_weights_into_model
  • Restore backward compatibility for:

    • caption()
    • encode_image()
  • Add dependency:

txt
huggingface_hub>=0.20.0

Impact

These issues currently prevent users from:

  • Importing Hugging Face integration modules.
  • Loading Moondream models from Hugging Face Hub.
  • Using AutoModelForCausalLM.
  • Running legacy code that depends on previous APIs.

Restoring these components would re-enable standard Hugging Face compatibility and improve backward compatibility for existing users.