Instructions to use moondream/moondream3-preview with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use moondream/moondream3-preview with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="moondream/moondream3-preview", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("moondream/moondream3-preview", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use moondream/moondream3-preview with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "moondream/moondream3-preview" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moondream/moondream3-preview", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/moondream/moondream3-preview
- SGLang
How to use moondream/moondream3-preview with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "moondream/moondream3-preview" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moondream/moondream3-preview", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "moondream/moondream3-preview" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moondream/moondream3-preview", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use moondream/moondream3-preview with Docker Model Runner:
docker model run hf.co/moondream/moondream3-preview
Always output inaccurate results
Example code from model card
import torch
from transformers import AutoModelForCausalLM
moondream = AutoModelForCausalLM.from_pretrained(
"moondream/moondream3-preview",
trust_remote_code=True,
dtype=torch.bfloat16,
device_map={"": "cuda"},
token="hugging face token"
)
moondream.compile()
image = Image.open("street_scene.jpg")
result = moondream.detect(image, "car")
print(result)
This example code result is
{'objects': [
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902},
{'x_min': 0.3129466772079468, 'y_min': 0.01665535569190979, 'x_max': 1.3061939477920532, 'y_max': 0.9833446443080902},
{'x_min': 0.3129466772079468, 'y_min': 0.01665535569190979, 'x_max': 1.3061939477920532, 'y_max': 0.9833446443080902},
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902},
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902},
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902},
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902},
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902},
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902},
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902},
{'x_min': 0.0033763647079467773, 'y_min': 0.01665535569190979, 'x_max': 0.9966236352920532, 'y_max': 0.9833446443080902}
]}
This is the same output in the reference of the moondream-station.
The document itself on moondream.ai and the hugging face may be incorrect or outdated.
The only way it's worked out is using https://github.com/m87-labs/kestrel
Weirdly this happens with transformers>=5, but works well with transformers<5.
Yep, it has to do with how the new transformers treats buffers. It should work on pre and post 4.51.0 transformers. https://huggingface.co/moondream/moondream3-preview/discussions/37