Image-Text-to-Text
Transformers
Safetensors
English
Chinese
ristretto
feature-extraction
conversational
custom_code
Instructions to use LiAutoAD/Ristretto-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LiAutoAD/Ristretto-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="LiAutoAD/Ristretto-3B", trust_remote_code=True) 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 AutoModel model = AutoModel.from_pretrained("LiAutoAD/Ristretto-3B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use LiAutoAD/Ristretto-3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LiAutoAD/Ristretto-3B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LiAutoAD/Ristretto-3B", "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/LiAutoAD/Ristretto-3B
- SGLang
How to use LiAutoAD/Ristretto-3B 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 "LiAutoAD/Ristretto-3B" \ --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": "LiAutoAD/Ristretto-3B", "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 "LiAutoAD/Ristretto-3B" \ --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": "LiAutoAD/Ristretto-3B", "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 LiAutoAD/Ristretto-3B with Docker Model Runner:
docker model run hf.co/LiAutoAD/Ristretto-3B
| # -------------------------------------------------------- | |
| # Ristretto | |
| # Copyright (c) 2025 LiAutoAD | |
| # Licensed under The MIT License | |
| # -------------------------------------------------------- | |
| import numpy as np | |
| from torch import nn | |
| import torch.nn.functional as F | |
| class FFN(nn.Module): | |
| def __init__(self, dim, out_dim, mlp_ratio=3): | |
| super().__init__() | |
| self.layernorm = nn.LayerNorm(dim) | |
| self.f1 = nn.Linear(dim, mlp_ratio * dim) | |
| self.f2 = nn.Linear(dim, mlp_ratio * dim) | |
| self.g = nn.Linear(mlp_ratio * dim, out_dim) | |
| self.act = nn.SiLU() | |
| def forward(self, x): | |
| x = self.layernorm(x) | |
| input = x | |
| x1, x2 = self.f1(x), self.f2(x) | |
| x = self.act(x1) * x2 | |
| x = self.g(x) | |
| return x | |
| class TokenAdaptiveProjector(nn.Module): | |
| def __init__(self, vit_hidden_size, llm_hidden_size, num_image_token): | |
| super().__init__() | |
| self.num_image_token = num_image_token | |
| self.mlp = FFN(vit_hidden_size, llm_hidden_size) | |
| def find_resize_hw(self, H, W, num_image_token): | |
| target_h = target_w = int(num_image_token ** 0.5) | |
| resize_h = int(np.ceil(H / target_h)) * target_h | |
| resize_w = int(np.ceil(W / target_w)) * target_h | |
| return resize_h, resize_w, target_h, target_w | |
| def forward(self, x, num_image_token=None): | |
| bs, L, C = x.shape | |
| if num_image_token is None: | |
| num_image_token = self.num_image_token | |
| H = W = int(L ** 0.5) | |
| assert L == H * W, "L should equal H * W" | |
| resize_h, resize_w, target_h, target_w = self.find_resize_hw( | |
| H, W, num_image_token | |
| ) | |
| x = x.view(bs, H, W, C).permute(0, 3, 1, 2) # [bs, C, H, W] | |
| if resize_h != H or resize_w != W: | |
| x = F.interpolate( | |
| x, size=(resize_h, resize_w), mode="bilinear", align_corners=True | |
| ) | |
| _, _, H, W = x.shape | |
| n = target_h | |
| patch_h = patch_w = H // n | |
| x = ( | |
| F.avg_pool2d(x, (patch_h, patch_w)).permute(0, 2, 3, 1).reshape(bs, -1, C) | |
| ) | |
| x = self.mlp(x) | |
| return x | |