Image-Text-to-Text
Transformers
Safetensors
Arabic
English
arabic
vision
image-captioning
image-understanding
siglip2
jais
Instructions to use dhadlab/dhad-vision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dhadlab/dhad-vision with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="dhadlab/dhad-vision")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("dhadlab/dhad-vision", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use dhadlab/dhad-vision with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dhadlab/dhad-vision" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dhadlab/dhad-vision", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/dhadlab/dhad-vision
- SGLang
How to use dhadlab/dhad-vision 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 "dhadlab/dhad-vision" \ --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": "dhadlab/dhad-vision", "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 "dhadlab/dhad-vision" \ --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": "dhadlab/dhad-vision", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use dhadlab/dhad-vision with Docker Model Runner:
docker model run hf.co/dhadlab/dhad-vision
Download code/encoder.py from dhadlab/dhad-vision: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/dhadlab/dhad-vision/resolve/main/code/encoder.py
- Command line
-
hf download hf://dhadlab/dhad-vision/code/encoder.py
-
curl -L -o encoder.py https://huggingface.co/dhadlab/dhad-vision/resolve/main/code/encoder.py
2.19 kB
| """SigLIP2-B/16 NaFlex vision tower (frozen), fixed 384x384 -> 24x24 = 576 patches x 768. | |
| encode(images) -> fp16 numpy [N,576,768]: last_hidden_state of the vision tower = AFTER the final post-layernorm, | |
| BEFORE the attention-pooling head (the head is not used). Pixel prep: resize to 384x384 (bicubic, aspect NOT kept), | |
| rescale 1/255, normalise mean=std=0.5, patchify row-major (16x16x3 -> 768, order (ph,pw,c)).""" | |
| import os, numpy as np, torch | |
| from PIL import Image | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| # Local copy of the encoder if SIGLIP2_PATH is set; otherwise the public Hub repo (auto-downloaded). | |
| MODEL_DIR = os.environ.get("SIGLIP2_PATH") or os.path.join(HERE, "siglip2") | |
| if not os.path.isdir(MODEL_DIR): MODEL_DIR = "google/siglip2-base-patch16-naflex" | |
| S, P = 384, 16; G = S // P # 24 | |
| _model = None | |
| def load(device="cpu", dtype=torch.float16): | |
| global _model | |
| from transformers import Siglip2VisionModel | |
| m = Siglip2VisionModel.from_pretrained(MODEL_DIR, dtype=dtype).to(device).eval() | |
| for p in m.parameters(): p.requires_grad_(False) | |
| _model = (m, device, dtype); return _model | |
| def prep(img): | |
| if not isinstance(img, Image.Image): img = Image.open(img) | |
| img = img.convert("RGB").resize((S, S), Image.BICUBIC) | |
| a = (np.asarray(img, dtype=np.float32) / 255.0 - 0.5) / 0.5 # [384,384,3] | |
| a = a.reshape(G, P, G, P, 3).transpose(0, 2, 1, 3, 4).reshape(G * G, P * P * 3) # [576,768] | |
| return a | |
| def encode(images, device="cpu", batch=8): | |
| """images: list of PIL images / paths -> np.float16 [N,576,768]""" | |
| global _model | |
| if _model is None or _model[1] != device: load(device) | |
| m, dev, dt = _model; out = [] | |
| for i in range(0, len(images), batch): | |
| x = torch.from_numpy(np.stack([prep(im) for im in images[i:i + batch]])).to(dev, dt) | |
| b = x.shape[0] | |
| mask = torch.ones(b, G * G, dtype=torch.long, device=dev) | |
| shapes = torch.tensor([[G, G]] * b, dtype=torch.long, device=dev) | |
| h = m(pixel_values=x, pixel_attention_mask=mask, spatial_shapes=shapes).last_hidden_state | |
| out.append(h.float().cpu().numpy().astype(np.float16)) | |
| return np.concatenate(out) | |