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
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
| 4 |
+
|
| 5 |
+
moondream2 is a small vision language model designed to run efficiently on edge devices. Check out the [GitHub repository](https://github.com/vikhyat/moondream) for details.
|
| 6 |
+
|
| 7 |
+
**Benchmarks**
|
| 8 |
+
|
| 9 |
+
| Release | VQAv2 | GQA | TextVQA | POPE | TallyQA |
|
| 10 |
+
| --- | --- | --- | --- | --- | --- |
|
| 11 |
+
| **2024-03-04** (latest) | 74.2 | 58.5 | 36.4 | (coming soon) | (coming soon) |
|
| 12 |
+
|
| 13 |
+
**Usage**
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
pip install transformers timm einops
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 21 |
+
from PIL import Image
|
| 22 |
+
|
| 23 |
+
model_id = "vikhyatk/moondream2"
|
| 24 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 25 |
+
model_id, trust_remote_code=True, revision="2024-03-04"
|
| 26 |
+
)
|
| 27 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, revision="2024-03-04")
|
| 28 |
+
|
| 29 |
+
image = Image.open('<IMAGE_PATH>')
|
| 30 |
+
enc_image = model.encode_image(image)
|
| 31 |
+
print(model.answer_question(enc_image, "Describe this image.", tokenizer))
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
The model is updated regularly, so we recommend pinning the model version to a
|
| 35 |
+
specific release as shown above.
|