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)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("moondream/moondream3-preview", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- 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
Upload HfMoondream
Browse filesFiles changed (5)
123version https://git-lfs.github.com/spec/v1oid sha256:a9414434ab3afb560b37bbd5d3972ae944679e7773a60ece538e4231d2cf142fsize 4907406296123version https://git-lfs.github.com/spec/v1oid sha256:fd4b3d0d6daae9c4212056cd64f02f408ff083bbb0244114eecd05fcba30037esize 4907406296
123version https://git-lfs.github.com/spec/v1oid sha256:b0433bb359387b93502680ac120913f46e0d6d62940f74ef75759a085edcad86size 4736548872123version https://git-lfs.github.com/spec/v1oid sha256:7cf6d17391db58801b61173510ba629875679dbcbe4bfd3cb38ac0958b3c70a0size 4736548872
123version https://git-lfs.github.com/spec/v1oid sha256:82b15aaadff6efa4013788ccaa321d496993fe41240305c7b8dd8e8cfbc4fa69size 4502742464123version https://git-lfs.github.com/spec/v1oid sha256:f4391c6d6b46ed49aa00afddf1f7df9dd0845cbc681fdaf424e727b01ea2d3e4size 4502742464
123version https://git-lfs.github.com/spec/v1oid sha256:fde1839f3766d227b30cfa07521cc0126bfacac08e91f135defdc7624405977fsize 4390620392123version https://git-lfs.github.com/spec/v1oid sha256:6af14858bdd7cdea5d19d786726e48434b02a3c0c52a771a0f25b6a8ca640187size 4390620392
50 unmodified lines51525354555657532 unmodified lines59059159259359459559659759859920 unmodified lines62062162262362462562635 unmodified lines66266366466566666766866967067150 unmodified linesDEFAULT_MAX_TOKENS = 768DEFAULT_TEMPERATURE = 0.5DEFAULT_TOP_P = 0.9DEFAULT_MAX_OBJECTS = 50@dataclass(frozen=True)532 unmodified lineslogits_BV, _ = self._decode_one_tok(next_emb, mask, pos_ids, lora)logits_BV[:, self.config.tokenizer.answer_id] = float("-inf")# Suppress EOS for the first token to ensure at least one answer tokenif generated_tokens == 0:logits_BV[:, eos_id] = float("-inf")pos += 1if temperature == 0:20 unmodified linesself,image: Optional[Union[Image.Image, EncodedImage]] = None,question: str = None,reasoning: bool = False,spatial_refs: Optional[SpatialRefs] = None,stream: bool = False,settings: Optional[TextSamplingSettings] = None,35 unmodified linesspatial_toks.extend([coord_id, coord_id, size_id])prompt_tokens = [prompt_toks+ spatial_toks+ self.tokenizer.encode(question).ids+ self.config.tokenizer.templates["query"]["suffix"]]if reasoning:50 unmodified lines51525354555657532 unmodified lines59059159259359459520 unmodified lines61661761861962062162235 unmodified lines65865966066166266366450 unmodified linesDEFAULT_MAX_TOKENS = 768DEFAULT_TEMPERATURE = 0.5DEFAULT_TOP_P = 0.9DEFAULT_MAX_OBJECTS = 150@dataclass(frozen=True)532 unmodified lineslogits_BV, _ = self._decode_one_tok(next_emb, mask, pos_ids, lora)logits_BV[:, self.config.tokenizer.answer_id] = float("-inf")pos += 1if temperature == 0:20 unmodified linesself,image: Optional[Union[Image.Image, EncodedImage]] = None,question: str = None,reasoning: bool = True,spatial_refs: Optional[SpatialRefs] = None,stream: bool = False,settings: Optional[TextSamplingSettings] = None,35 unmodified linesspatial_toks.extend([coord_id, coord_id, size_id])prompt_tokens = [prompt_toks + spatial_toks + self.tokenizer.encode(question).ids]if reasoning:
model-00001-of-00004.safetensors+1-1
model-00002-of-00004.safetensors+1-1
model-00003-of-00004.safetensors+1-1
model-00004-of-00004.safetensors+1-1
moondream.py+3-10