Instructions to use IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration")# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration") model = AutoModelForMultimodalLM.from_pretrained("IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration
- SGLang
How to use IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration 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 "IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration" \ --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": "IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration", "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 "IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration" \ --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": "IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration with Docker Model Runner:
docker model run hf.co/IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration
Does not contain `<image>` token.
Running
from PIL import Image
import requests
from transformers import AutoProcessor, LlavaForConditionalGeneration
model_id = "IlyasMoutawwakil/tiny-random-LlavaForConditionalGeneration"
model = LlavaForConditionalGeneration.from_pretrained(model_id)
processor = AutoProcessor.from_pretrained(model_id)
prompt = "<image>\nUSER: What's the content of the image?\nASSISTANT:"
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(text=prompt, images=image, return_tensors="pt")
# Generate
generate_ids = model.generate(**inputs, max_length=30)
processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
results in
ValueError: The input provided to the model are wrong. The number of image tokens is 0 while the number of image given to the model is 1. This prevents correct indexing and breaks batch generation.
This is because you're missing the <image> token in the tokenizer (and the model embedding layer is only 32000 x 16).
I've forked your model and added it with:
processor.tokenizer.add_tokens(["<image>", "<pad>"], special_tokens=True)
model.resize_token_embeddings(len(processor.tokenizer))
The final model can be found at https://huggingface.co/Xenova/tiny-random-LlavaForConditionalGeneration
Thanks a lot ! I was wondering why the model only worked for image captioning image-to-text with an AutoImageProcessor in my tests π₯²
I'll use yours and delete this one π