Instructions to use circulus/TinyHawk-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use circulus/TinyHawk-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="circulus/TinyHawk-v1") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("circulus/TinyHawk-v1") model = AutoModelForMultimodalLM.from_pretrained("circulus/TinyHawk-v1", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use circulus/TinyHawk-v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "circulus/TinyHawk-v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "circulus/TinyHawk-v1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/circulus/TinyHawk-v1
- SGLang
How to use circulus/TinyHawk-v1 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 "circulus/TinyHawk-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "circulus/TinyHawk-v1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "circulus/TinyHawk-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "circulus/TinyHawk-v1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use circulus/TinyHawk-v1 with Docker Model Runner:
docker model run hf.co/circulus/TinyHawk-v1
| license: mit | |
| datasets: | |
| - liuhaotian/LLaVA-Pretrain | |
| - liuhaotian/LLaVA-Instruct-150K | |
| language: | |
| - en | |
| - zh | |
| library_name: transformers | |
| # WORK IN PROGRESS | |
| We present TinyLLaVA, a small vision-language chatbot (1.4B) that reaches comparable performances with contemporary vision language models on common benchmarks, using less parameters. | |
| TinyLLaVA was trained by finetuning [TinyLlama](https://huggingface.co/PY007/TinyLlama-1.1B-Chat-v0.3) on the [LLaVA-1.5](https://github.com/haotian-liu/LLaVA) dataset, following the training recipe of [LLaVA-1.5](https://github.com/haotian-liu/LLaVA). For more details, please refer to the [LLaVA-1.5 paper](https://arxiv.org/abs/2310.03744). | |
| ## Model Performance | |
| We have evaluated TinyLLaVA on [GQA](https://cs.stanford.edu/people/dorarad/gqa/about.html), [VizWiz](https://www.vizwiz.com/), [VQAv2](https://visualqa.org/), [TextVQA](https://textvqa.org/) and [SQA](https://github.com/lupantech/ScienceQA). | |
| | Model | VQAv2 | GQA | SQA | TextVQA | VizWiz | | |
| | -------------------- | :------------: | :------------: | :------------: | :------------: | :------------: | | |
| | TinyLLaVA-v1-1.4B | 73.41 | 57.54 | 59.40 | 46.37 | 49.56 | | |
| | BLIP-2 | 41.00 | 41.00 | 61.00 | 42.50 | 19.60 | | |
| | LLaVA-v1.5-7B | 78.50 | 62.00 | 66.80 | 61.3 | 50 | | |
| | LLaVA-v1.5-13B | 80.00 | 63.30 | 71.60 | 61.3 | 53.6 | | |
| | Qwen-VL-7B | 78.80 | 59.30 | 67.10 | 63.8 | 35.2 | | |
| | Qwen-VL-13B | 78.20 | 57.50 | 68.20 | 61.5 | 38.9 | | |
| More evaluations are ongoing. | |
| ## Model Preparations | |
| #### - Transformers Version | |
| Make sure to have `transformers >= 4.35.3`. | |
| #### - Prompt Template | |
| The model supports multi-image and multi-prompt generation. When using the model, make sure to follow the correct prompt template (`USER: <image>xxx\nASSISTANT:`), where `<image>` token is a place-holding special token for image embeddings. | |
| ## Model Inference from `pipeline` and `transformers` | |
| #### - Using `pipeline`: | |
| Below we used [`"bczhou/tiny-llava-v1-hf"`](https://huggingface.co/bczhou/tiny-llava-v1-hf) checkpoint. | |
| ```python | |
| from transformers import pipeline | |
| from PIL import Image | |
| import requests | |
| model_id = "bczhou/tiny-llava-v1-hf" | |
| pipe = pipeline("image-to-text", model=model_id) | |
| url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg" | |
| image = Image.open(requests.get(url, stream=True).raw) | |
| prompt = "USER: <image>\nWhat does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nASSISTANT:" | |
| outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200}) | |
| print(outputs[0]) | |
| >>> {"generated_text': 'USER: \nWhat does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nASSISTANT: The label 15 represents lava, which is a type of volcanic rock."} | |
| ``` | |
| #### - Using pure `transformers`: | |
| Below is an example script to run generation in `float16` precision on a GPU device: | |
| ```python | |
| import requests | |
| from PIL import Image | |
| import torch | |
| from transformers import AutoProcessor, LlavaForConditionalGeneration | |
| model_id = "bczhou/tiny-llava-v1-hf" | |
| prompt = "USER: <image>\nWhat are these?\nASSISTANT:" | |
| image_file = "http://images.cocodataset.org/val2017/000000039769.jpg" | |
| model = LlavaForConditionalGeneration.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.float16, | |
| low_cpu_mem_usage=True, | |
| ).to(0) | |
| processor = AutoProcessor.from_pretrained(model_id) | |
| raw_image = Image.open(requests.get(image_file, stream=True).raw) | |
| inputs = processor(prompt, raw_image, return_tensors='pt').to(0, torch.float16) | |
| output = model.generate(**inputs, max_new_tokens=200, do_sample=False) | |
| print(processor.decode(output[0][2:], skip_special_tokens=True)) | |
| ``` | |
| ## Contact | |
| This model was trained by [Baichuan Zhou](https://baichuanzhou.github.io/), from Beihang Univerisity, under the supervision of [Prof. Lei Huang](https://huangleibuaa.github.io/). | |