Image-text embeddings (CLIP, SigLIP 2)
CLIP (OpenAI, 2021) and SigLIP 2 (Google, 2025): image and text towers in one space, for text search over photos ("a red car") and zero-shot labels you type (`search`, `zero_shot`). MIT (CLIP B/32, B/16, L/14) and Apache-2.0 (SigLIP 2 B/16, L/16) code and weights.
experimental Fork of huggingface/transformers@c4c4605 · backends: portable, kernels
- Paper Learning Transferable Visual Models From Natural Language Supervision ICML 2021 · first released 26 Feb 2021
- Authors’ code openai/CLIP (PyTorch), not the code forked here: fastforks follows the transformers port, which loads the authors' converted weights without the repo's own CLIP package.
Paper 2021 Added in 0.4.0 Evaluated with 0.4.0
Use it
pip install fastforks Lean install with only what this model needs: pip install "fastforks-core[transformers]"
from fastforks import retrieval
model = retrieval.load("clip-b32-openai-text") # fastest backend that runs here
result = model("photo.jpg")
# result fields: descriptor
descriptor = result.descriptor # a torch tensor
arrays = result.numpy() # the tensor fields as NumPy arrays: arrays["descriptor"]
result.backend # what ran: mode, device, dtype
Other ways to run it
- Backend:
retrieval.load("clip-b32-openai-text", mode="kernels") # or "portable", "auto" (default) - Precision:
retrieval.load("clip-b32-openai-text", dtype="float32") # full precision: slower, portable only
fastforks bench clip-b32-openai-text Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
Input: synthetic, 480x640 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32transformers 5.19.0 get_image_features on the HF processor's resize (pre-processing not timed on the same path) | fp32 | 6.61 | 0.95× | 620 MiB/664 MiB | 3.0 | 0.29 |
| Original fp16transformers 5.19.0 get_image_features on the HF processor's resize (pre-processing not timed on the same path) | fp16 | 6.28 | – | 329 MiB/398 MiB | 0.3 | 0.04 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 5.70 | 1.1× | 340 MiB/352 MiB | 0.3 | 0.01 |
| Kernels | fp16 | 3.49 | 1.8× | 331 MiB/350 MiB | 2.9 | 0.16 |
| Portable + torch.compile | 3.27 | 1.9× | 361 MiB/368 MiB | 9 (build) | – | |
| TensorRT fp16 | fp16 | 0.814 | 7.7× | 200 MiBenginenot comparable | 19 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-29 to 2026-12-02. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
Not measured on other devices yet.
Licence and weights
Commercial use allowed
- Code
- Apache-2.0
- Weights
- MIT source
- Training data
- WIT: 400M image-text pairs collected from the web by OpenAI (CLIP paper); not released
Our reading of the licences, not legal advice.
Weights
clip-b32-openai.config.json 4.2 KB· hosted on Hugging Faceclip-b32-openai.pytorch_model.bin 605 MB· hosted on Hugging Faceclip-b32-openai.vocab.json 862 KB· hosted on Hugging Faceclip-b32-openai.merges.txt 525 KB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download clip-b32-openai-text).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
COCO val2017 captions
every 5th image (1000 images, 5 captions each), recall@1 / @5 % image to text / text to image
| Run | dtype | i2t_r1 ↑ | i2t_r5 ↑ | t2i_r1 ↑ | t2i_r5 ↑ | Δ i2t_r1 vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 68.50 | 90.10 | 48.14 | 76.38 | reference | 1000 | 5.26 |
| Original fp16 | fp16 | 68.50 | 90.10 | 48.14 | 76.36 | ±0.00 | 1000 | 5.20 |
| Portable fp32 | fp32 | 68.60 | 89.90 | 48.16 | 76.30 | +0.10 | 1000 | 4.73 |
| Portable | fp16 | 68.70 | 89.90 | 48.18 | 76.36 | +0.20 | 1000 | 4.66 |
| Kernels | not measured | |||||||
Every query's descriptor against every database descriptor (cosine similarity, exact top-k on the GPU); a query counts as found at k when one of its k nearest database images is within 25 m (UTM positions of the file names), the standard visual place recognition protocol. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-30; portable fp32, portable: RTX 5060 Ti, torch 2.14.1+cu130, fastforks d5364b118, 2026-11-30.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output descriptor).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.02 | 0.00095 |
| GPU default dtypes, p99 |diff| | ≤ 0.25 | 0.00405 |
Recorded for clip-b32-openai-text on RTX 5060 Ti, torch 2.14.1+cu130, 2026-12-02, with these kernels: fvm_conv
Details
Joint image and text embeddings for text-to-image search and zero-shot classification: OpenAI CLIP (ViT-B/32, B/16, L/14) and SigLIP 2 (ViT-B/16, L/16 at 256 px). `encode_image` / the call give a unit descriptor of an image, `encode_text` one of a list of strings in the same space, so the dot product is the image-text cosine similarity; `zero_shot` turns it into label probabilities (softmax for CLIP, per-label sigmoid for SigLIP 2) and `search` ranks stored image descriptors for a text query. The image side is resized as the original processors do (CLIP: bicubic shortest side, centre crop; SigLIP 2: the whole image squashed to 256 x 256).
- Input / output
- Input: one RGB image. Output: a global descriptor
[D](unit L2 norm) for image retrieval / visual place recognition;fastforks.retrieval.top_kandpairsfind the nearest images (cosine similarity) on the GPU. - Input size
- any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (742 MiB allocated)
- Outputs
descriptor- Checkpoint
arch="CLIPModel",kind="clip",size=224,context=77,dim=512- CUDA kernels
fvm_convfused convolutions for image classifiers
- Apple (MPS)
- fp32, fp16
Limitations
- Requires the optional transformers library (the networks are its `CLIPModel` / `SiglipModel`) and, for SigLIP 2, its `tokenizers` dependency.
- The kernels backend (CUDA, fp16) speeds up the image tower only (fused fp16-accumulate GEMMs, a CUDA graph per batch size); `encode_text` runs the portable text tower. An Apple MLX port of both towers runs with `device="mlx"` (fp32, fp16).
- Text is truncated to the context (CLIP 77 tokens, SigLIP 2 64 tokens, the end token kept); SigLIP 2 lower-cases its text as the original tokenizer does. CLIP prompts are expected to be clean Unicode (the ftfy repair of the original tokenizer is left out).
- The SigLIP 2 checkpoints are the fixed-resolution 256 px models (`model_type: siglip`); the NaFlex variants are not included. SigLIP 2 scores are independent per label (sigmoid with the checkpoint's scale and bias), CLIP scores are a softmax over the labels given.
- The original in the parity checks and benchmarks is the Hugging Face transformers 5.19.0 port with the authors' weights (openai/clip-vit-*, google/siglip2-*-patch16-256); the authors' openai/CLIP and big_vision code was not run.
- Not included: OpenCLIP LAION weights (they ship as `open_clip` files, not in the transformers layout), DFN (Apple research-only licence).
Full reference, generated from the repository
CLIP (OpenAI, 2021) and SigLIP 2 (Google, 2025): image and text towers in one space, for text search over photos ("a red car") and zero-shot labels you type (search, zero_shot). MIT (CLIP B/32, B/16, L/14) and Apache-2.0 (SigLIP 2 B/16, L/16) code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
clip-b32-openai-text | synthetic (480x640) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 6.61 6.28 5.70 3.49 3.27 0.814 | 620 / 664 329 / 398 340 / 352 331 / 350 361 / 368 529 / 548 |
clip-b16-openai-text | synthetic (480x640) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 7.85 5.07 4.35 3.53 3.07 1.10 | 613 / 668 330 / 380 336 / 354 328 / 350 360 / 370 526 / 548 |
clip-l14-openai-text | synthetic (480x640) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 26.3 8.79 7.94 6.84 6.42 3.99 | 1684 / 1730 860 / 934 869 / 894 858 / 886 896 / 906 1476 / 1484 |
siglip2-b16-256-text | synthetic (480x640) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 9.49 5.52 4.98 4.16 3.23 1.15 | 1473 / 1554 767 / 1164 774 / 794 758 / 786 787 / 804 958 / 966 |
siglip2-l16-256-text | synthetic (480x640) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 20.8 9.03 8.30 7.13 5.31 2.96 | 3409 / 3414 1720 / 2220 1725 / 1740 1724 / 1748 1754 / 1766 2346 / 2368 |
Details
- Original code: https://github.com/huggingface/transformers at
c4c4605f9618 - Code licence: Apache-2.0 (permissive); files:
- Weights licence: MIT
siglip2-b16-256-text: Apache-2.0siglip2-l16-256-text: Apache-2.0
- Licence evidence: https://github.com/openai/CLIP/blob/d05afc436d78f1c48dc0dbf8e5980a9d471f35f6/LICENSE
- Training data: WIT: 400M image-text pairs collected from the web by OpenAI (CLIP paper); not released
siglip2-b16-256-text: WebLI (Google web image-text data, not released) (WebLI image-text pairs (multilingual), sigmoid contrastive loss plus captioning / self-distillation / masked prediction (SigLIP 2 paper); not released)siglip2-l16-256-text: WebLI (Google web image-text data, not released) (WebLI image-text pairs (multilingual), sigmoid contrastive loss plus captioning / self-distillation / masked prediction (SigLIP 2 paper); not released)
- Kernel libraries:
fvm_conv - Variants:
clip-b32-openai-text,clip-b16-openai-text,clip-l14-openai-text,siglip2-b16-256-text,siglip2-l16-256-text - Outputs: descriptor
- Input size: any H x W >= 32, padded to a multiple of 32
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
clip-b32-openai-text3000x4000 (0.7 GiB peak allocated, 0.7 reserved);clip-b16-openai-text3000x4000 (0.7 GiB peak allocated, 0.7 reserved);clip-l14-openai-text3000x4000 (1.2 GiB peak allocated, 1.3 reserved);siglip2-b16-256-text3000x4000 (1.1 GiB peak allocated, 1.2 reserved);siglip2-l16-256-text3000x4000 (2.1 GiB peak allocated, 2.1 reserved) clip-b32-openai-text480x640, first call: portable + torch.compile 9 s (cold Inductor cache), TensorRT fp16 19 s (ONNX + engine).clip-b16-openai-text480x640, first call: portable + torch.compile 9 s (cold Inductor cache), TensorRT fp16 20 s (ONNX + engine).clip-l14-openai-text480x640, first call: portable + torch.compile 13 s (cold Inductor cache), TensorRT fp16 33 s (ONNX + engine).siglip2-b16-256-text480x640, first call: portable + torch.compile 9 s (cold Inductor cache), TensorRT fp16 42 s (ONNX + engine).siglip2-l16-256-text480x640, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 45 s (ONNX + engine).clip-b32-openai-textoriginal (fp32) 480x640, original 480x640: transformers 5.19.0 get_image_features on the HF processor's resize (pre-processing not timed on the same path)clip-b16-openai-textoriginal (fp32) 480x640, original 480x640: transformers 5.19.0 get_image_features on the HF processor's resize (pre-processing not timed on the same path)clip-l14-openai-textoriginal (fp32) 480x640, original 480x640: transformers 5.19.0 get_image_features on the HF processor's resize (pre-processing not timed on the same path)siglip2-b16-256-textoriginal (fp32) 480x640, original 480x640: transformers 5.19.0 get_image_features on the HF processor's resize (pre-processing not timed on the same path)siglip2-l16-256-textoriginal (fp32) 480x640, original 480x640: transformers 5.19.0 get_image_features on the HF processor's resize (pre-processing not timed on the same path)clip-b32-openai-textload / first call: original 0.31 s / 0.04 s, portable 0.25 s / 0.01 s, kernels 2.93 s / 0.156 sclip-b16-openai-textload / first call: original 0.27 s / 0.04 s, portable 0.24 s / 0.01 s, kernels 2.93 s / 0.161 sclip-l14-openai-textload / first call: original 0.45 s / 0.08 s, portable 0.44 s / 0.01 s, kernels 3.61 s / 0.166 ssiglip2-b16-256-textload / first call: original 1.79 s / 0.46 s, portable 1.13 s / 0.01 s, kernels 4.02 s / 0.139 ssiglip2-l16-256-textload / first call: original 2.14 s / 0.03 s, portable 1.54 s / 0.01 s, kernels 5.53 s / 0.13 s- Protocol, median of 20 after warm-up, uint8 CUDA input, card defaults
Measured
Every query's descriptor against every database descriptor (cosine similarity, exact top-k on the GPU); a query counts as found at k when one of its k nearest database images is within 25 m (UTM positions of the file names), the standard visual place recognition protocol. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | note |
|---|---|---|---|---|---|---|
clip-b32-openai-text | COCO val2017 captions, every 5th image (1000 images, 5 captions each), recall@1 / @5 % image to text / text to image | 68.50 / 90.10 / 48.14 / 76.38 | 68.50 / 90.10 / 48.14 / 76.36 | 68.70 / 89.90 / 48.18 / 76.36 | 68.60 / 89.90 / 48.16 / 76.30 | |
clip-b16-openai-text | COCO val2017 captions, every 5th image (1000 images, 5 captions each), recall@1 / @5 % image to text / text to image | 70.50 / 90.40 / 49.48 / 78.82 | 70.50 / 90.30 / 49.50 / 78.80 | 70.30 / 90.00 / 49.74 / 78.70 | 70.20 / 90.00 / 49.68 / 78.76 | |
clip-l14-openai-text | COCO val2017 captions, every 5th image (1000 images, 5 captions each), recall@1 / @5 % image to text / text to image | 73.60 / 91.80 / 53.10 / 79.86 | 73.60 / 91.80 / 53.08 / 79.82 | 73.20 / 91.60 / 53.10 / 79.52 | 73.30 / 91.60 / 53.12 / 79.52 | |
siglip2-b16-256-text | COCO val2017 captions, every 5th image (1000 images, 5 captions each), recall@1 / @5 % image to text / text to image | 83.90 / 96.10 / 70.18 / 89.86 | 83.90 / 96.20 / 70.16 / 89.84 | 83.80 / 96.20 / 70.10 / 89.78 | 83.70 / 96.20 / 70.14 / 89.80 | |
siglip2-l16-256-text | COCO val2017 captions, every 5th image (1000 images, 5 captions each), recall@1 / @5 % image to text / text to image | 83.80 / 96.20 / 70.34 / 89.84 | 83.70 / 96.20 / 70.36 / 89.78 | 83.70 / 96.20 / 70.28 / 89.90 | 83.60 / 96.20 / 70.34 / 89.94 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks d5364b118, 2026-11-30.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output descriptor).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
clip-b32-openai-text | 0.00095 / 0.00405 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
clip-b16-openai-text | 0.0005 / 0.00173 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
clip-l14-openai-text | 0.00048 / 0.00154 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
siglip2-b16-256-text | 0.0002 / 0.00074 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
siglip2-l16-256-text | 0.00028 / 0.00094 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
Limitations
- Requires the optional transformers library (the networks are its
CLIPModel/SiglipModel) and, for SigLIP 2, itstokenizersdependency. - The kernels backend (CUDA, fp16) speeds up the image tower only (fused fp16-accumulate GEMMs, a CUDA graph per batch size);
encode_textruns the portable text tower. An Apple MLX port of both towers runs withdevice="mlx"(fp32, fp16). - Text is truncated to the context (CLIP 77 tokens, SigLIP 2 64 tokens, the end token kept); SigLIP 2 lower-cases its text as the original tokenizer does. CLIP prompts are expected to be clean Unicode (the ftfy repair of the original tokenizer is left out).
- The SigLIP 2 checkpoints are the fixed-resolution 256 px models (
model_type: siglip); the NaFlex variants are not included. SigLIP 2 scores are independent per label (sigmoid with the checkpoint's scale and bias), CLIP scores are a softmax over the labels given. - The original in the parity checks and benchmarks is the Hugging Face transformers 5.19.0 port with the authors' weights (openai/clip-vit-, google/siglip2--patch16-256); the authors' openai/CLIP and big_vision code was not run.
- Not included: OpenCLIP LAION weights (they ship as
open_clipfiles, not in the transformers layout), DFN (Apple research-only licence).
Example output
No example rendered for this checkpoint yet.