Image-Text-to-Text
Transformers
Safetensors
llava_next
granite
vision
quantization
text-generation-inference
4-bit precision
bitsandbytes
Instructions to use hassenhamdi/granite-vision-3.1-2b-preview-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hassenhamdi/granite-vision-3.1-2b-preview-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="hassenhamdi/granite-vision-3.1-2b-preview-4bit")# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("hassenhamdi/granite-vision-3.1-2b-preview-4bit") model = AutoModelForImageTextToText.from_pretrained("hassenhamdi/granite-vision-3.1-2b-preview-4bit") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use hassenhamdi/granite-vision-3.1-2b-preview-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hassenhamdi/granite-vision-3.1-2b-preview-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "hassenhamdi/granite-vision-3.1-2b-preview-4bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/hassenhamdi/granite-vision-3.1-2b-preview-4bit
- SGLang
How to use hassenhamdi/granite-vision-3.1-2b-preview-4bit 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 "hassenhamdi/granite-vision-3.1-2b-preview-4bit" \ --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": "hassenhamdi/granite-vision-3.1-2b-preview-4bit", "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 "hassenhamdi/granite-vision-3.1-2b-preview-4bit" \ --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": "hassenhamdi/granite-vision-3.1-2b-preview-4bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use hassenhamdi/granite-vision-3.1-2b-preview-4bit with Docker Model Runner:
docker model run hf.co/hassenhamdi/granite-vision-3.1-2b-preview-4bit
About the uploaded model
- Quantized by: hassenhamdi
- Original model: ibm-granite/granite-vision-3.1-2b-preview
- precision: 4-bit
Setup
You can run the quantized model with these steps:
Check requirements from the original. In particular, check python, cuda, and transformers versions.
Make sure that you have installed quantization related packages.
pip install bitsandbytes>=0.39.0
pip install --upgrade accelerate transformers
- Load & run the model.
from transformers import AutoProcessor, AutoModelForVision2Seq
from huggingface_hub import hf_hub_download
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForVision2Seq.from_pretrained('hassenhamdi/granite-vision-3.1-2b-preview-4bit', trust_remote_code=True).to(device)
tokenizer = AutoProcessor.from_pretrained('ibm-granite/granite-vision-3.1-2b-preview')
# prepare image and text prompt, using the appropriate prompt template
img_path = hf_hub_download(repo_id=model_path, filename='example.png')
conversation = [
{
"role": "user",
"content": [
{"type": "image", "url": img_path},
{"type": "text", "text": "What is the highest scoring model on ChartQA and what is its score?"},
],
},
]
inputs = processor.apply_chat_template(
conversation,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt"
).to(device)
# autoregressively complete prompt
output = model.generate(**inputs, max_new_tokens=100)
print(processor.decode(output[0], skip_special_tokens=True))
Configurations
- The configuration info are in config.json.
- Downloads last month
- 10
Inference Providers NEW
This model isn't deployed by any Inference Provider. 馃檵 Ask for provider support
Model tree for hassenhamdi/granite-vision-3.1-2b-preview-4bit
Base model
ibm-granite/granite-3.1-2b-base Finetuned
ibm-granite/granite-3.1-2b-instruct