Instructions to use vikhyatk/moondream2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vikhyatk/moondream2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="vikhyatk/moondream2", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("vikhyatk/moondream2", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use vikhyatk/moondream2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vikhyatk/moondream2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vikhyatk/moondream2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/vikhyatk/moondream2
- SGLang
How to use vikhyatk/moondream2 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 "vikhyatk/moondream2" \ --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": "vikhyatk/moondream2", "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 "vikhyatk/moondream2" \ --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": "vikhyatk/moondream2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use vikhyatk/moondream2 with Docker Model Runner:
docker model run hf.co/vikhyatk/moondream2
Add notebook
#76
by merve HF Staff - opened
- notebook.ipynb +67 -0
notebook.ipynb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"nbformat": 4,
|
| 3 |
+
"nbformat_minor": 0,
|
| 4 |
+
"metadata": {
|
| 5 |
+
"colab": {
|
| 6 |
+
"machine_shape": "hm",
|
| 7 |
+
"gpuType": "T4",
|
| 8 |
+
"provenance": []
|
| 9 |
+
},
|
| 10 |
+
"accelerator": "GPU",
|
| 11 |
+
"kaggle": {
|
| 12 |
+
"accelerator": "gpu"
|
| 13 |
+
},
|
| 14 |
+
"language_info": {
|
| 15 |
+
"name": "python"
|
| 16 |
+
},
|
| 17 |
+
"kernelspec": {
|
| 18 |
+
"name": "python3",
|
| 19 |
+
"display_name": "Python 3"
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"cells": [
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "code",
|
| 25 |
+
"source": [
|
| 26 |
+
"!pip install -U transformers"
|
| 27 |
+
],
|
| 28 |
+
"metadata": {
|
| 29 |
+
"id": "4LXugJ1wUN5o"
|
| 30 |
+
},
|
| 31 |
+
"execution_count": null,
|
| 32 |
+
"outputs": []
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"cell_type": "markdown",
|
| 36 |
+
"source": [
|
| 37 |
+
"## Local Inference on GPU\n",
|
| 38 |
+
"Model page: https://huggingface.co/vikhyatk/moondream2\n",
|
| 39 |
+
"\n",
|
| 40 |
+
"⚠️ If the generated code snippets do not work, please open an issue on either the [model repo](https://huggingface.co/vikhyatk/moondream2)\n",
|
| 41 |
+
"\t\t\tand/or on [huggingface.js](https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/src/model-libraries-snippets.ts) 🙏"
|
| 42 |
+
],
|
| 43 |
+
"metadata": {
|
| 44 |
+
"id": "t490XrsVUN5q"
|
| 45 |
+
}
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"cell_type": "code",
|
| 49 |
+
"source": [
|
| 50 |
+
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"vikhyatk/moondream2\")\n",
|
| 53 |
+
"model = AutoModelForCausalLM.from_pretrained(\n",
|
| 54 |
+
" \"vikhyatk/moondream2\",\n",
|
| 55 |
+
" revision=\"2025-06-21\",\n",
|
| 56 |
+
" trust_remote_code=True,\n",
|
| 57 |
+
" device_map={\"\": \"cuda\"}\n",
|
| 58 |
+
")"
|
| 59 |
+
],
|
| 60 |
+
"metadata": {
|
| 61 |
+
"id": "6aWNuxB8UN5s"
|
| 62 |
+
},
|
| 63 |
+
"execution_count": null,
|
| 64 |
+
"outputs": []
|
| 65 |
+
}
|
| 66 |
+
]
|
| 67 |
+
}
|