Bug: Missing Hugging Face Integration Files and Broken `from_pretrained()` Support
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.pymoondream/hf/moondream.pymoondream/hf/__init__.py
Additionally, the root package is missing:
moondream/__init__.py
As a result, imports such as:
from moondream.hf import Moondreamfail 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 (
.safetensorsor.pt). - Load weights into the model automatically.
- Support standard usage patterns.
Current behavior:
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:
model.caption([image], tokenizer=tokenizer)encode_image()
Expected to accept:
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:
from moondream.hf import Moondream
model = Moondream.from_pretrained("vikhyatk/moondream2")and
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
- Add
Restore
moondream/hf/moondream.py- Re-export
HfMoondream - Re-export
HfConfig - Register Hugging Face Auto classes
- Re-export
Restore:
moondream/hf/__init__.pymoondream/__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:
huggingface_hub>=0.20.0Impact
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.
Source: m87-labs/moondream