google/docci
Updated • 436 • 77
How to use fal/moondream2-docci-instruct with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="fal/moondream2-docci-instruct", trust_remote_code=True) # Load model directly
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("fal/moondream2-docci-instruct", trust_remote_code=True, dtype="auto")How to use fal/moondream2-docci-instruct with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "fal/moondream2-docci-instruct"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "fal/moondream2-docci-instruct",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/fal/moondream2-docci-instruct
How to use fal/moondream2-docci-instruct with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "fal/moondream2-docci-instruct" \
--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": "fal/moondream2-docci-instruct",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "fal/moondream2-docci-instruct" \
--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": "fal/moondream2-docci-instruct",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use fal/moondream2-docci-instruct with Docker Model Runner:
docker model run hf.co/fal/moondream2-docci-instruct
Fine tuned version of moondream2 model using gokaygokay/random_instruct_docci dataset. Which gives extremely detailed captions of the images.
pip install transformers timm einops bitsandbytes accelerate flash-attn
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from PIL import Image
DEVICE = "cuda"
DTYPE = (
torch.float32 if DEVICE == "cpu" else torch.float16
) # CPU doesn't support float16
revision = "3ec40c7b6b5d87bc0c51edee45e21f5f29b449d8"
tokenizer = AutoTokenizer.from_pretrained(
"fal-ai/moondream2-docci-instruct",
trust_remote_code=True,
revision=revision
)
moondream = AutoModelForCausalLM.from_pretrained(
"fal-ai/moondream2-docci-instruct",
trust_remote_code=True,
torch_dtype=DTYPE,
device_map={"": DEVICE},
attn_implementation="flash_attention_2",
revision=revision
)
moondream.eval()
image_path = "<your_image_path>"
image = Image.open(image_path).convert("RGB")
md_answer = moondream.answer_question(
moondream.encode_image(image),
"what is this picture about",
tokenizer=tokenizer,
)
print(md_answer)