File size: 14,080 Bytes
69e4868
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
library_name: "fastforks"
pipeline_tag: "image-feature-extraction"
license: "other"
license_name: "mixed-see-variant-table"
license_link: "https://github.com/openai/CLIP/blob/d05afc436d78f1c48dc0dbf8e5980a9d471f35f6/LICENSE"
tags:
- "retrieval"
- "image-retrieval"
- "visual-place-recognition"
- "global-descriptor"
- "cuda"
- "pytorch"
- "fastforks"
- "fastforks-card"
---
# Image-text embeddings (CLIP, SigLIP 2) (fastforks)

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).

This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: <https://github.com/kleinicke/fastforks>. Kernels for the `kernels` backend: <https://huggingface.co/fastforks/kernels>. Original code: <https://github.com/huggingface/transformers> at `c4c4605f9618`.

Author weight repos: <https://huggingface.co/google/siglip2-base-patch16-256>, <https://huggingface.co/google/siglip2-large-patch16-256>, <https://huggingface.co/openai/clip-vit-base-patch16>, <https://huggingface.co/openai/clip-vit-base-patch32>, <https://huggingface.co/openai/clip-vit-large-patch14>.

Task: retrieval. Tier: experimental. Outputs: `descriptor`. Backends: `portable`, `kernels`.

Input: one RGB image. Output: a global descriptor `[D]` (unit L2 norm) for image retrieval / visual place recognition; `fastforks.retrieval.top_k` and `pairs` find the nearest images (cosine similarity) on the GPU.

## Variants

Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in [`card.toml`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/retrieval/models/image_text/card.toml).

| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
| `clip-b16-openai-text@1` | [clip-b16-openai.config.json](https://huggingface.co/openai/clip-vit-base-patch16/resolve/57c216476eefef5ab752ec549e440a49ae4ae5f3/config.json)<br>[clip-b16-openai.pytorch_model.bin](https://huggingface.co/openai/clip-vit-base-patch16/resolve/57c216476eefef5ab752ec549e440a49ae4ae5f3/pytorch_model.bin)<br>[clip-b16-openai.vocab.json](https://huggingface.co/openai/clip-vit-base-patch16/resolve/57c216476eefef5ab752ec549e440a49ae4ae5f3/vocab.json)<br>[clip-b16-openai.merges.txt](https://huggingface.co/openai/clip-vit-base-patch16/resolve/57c216476eefef5ab752ec549e440a49ae4ae5f3/merges.txt) | `eaf1c9089a85`<br>`ec89c7b09c74`<br>`3f0c4f7d2086`<br>`9fd691f7c803` | MIT | yes |
| `clip-b32-openai-text@1` | [clip-b32-openai.config.json](https://huggingface.co/openai/clip-vit-base-patch32/resolve/3d74acf9a28c67741b2f4f2ea7635f0aaf6f0268/config.json)<br>[clip-b32-openai.pytorch_model.bin](https://huggingface.co/openai/clip-vit-base-patch32/resolve/3d74acf9a28c67741b2f4f2ea7635f0aaf6f0268/pytorch_model.bin)<br>[clip-b32-openai.vocab.json](https://huggingface.co/openai/clip-vit-base-patch32/resolve/3d74acf9a28c67741b2f4f2ea7635f0aaf6f0268/vocab.json)<br>[clip-b32-openai.merges.txt](https://huggingface.co/openai/clip-vit-base-patch32/resolve/3d74acf9a28c67741b2f4f2ea7635f0aaf6f0268/merges.txt) | `b575ef3c36f2`<br>`a63082132ba4`<br>`5047b556ce86`<br>`f52639318911` | MIT | yes |
| `clip-l14-openai-text@1` | [clip-l14-openai.config.json](https://huggingface.co/openai/clip-vit-large-patch14/resolve/32bd64288804d66eefd0ccbe215aa642df71cc41/config.json)<br>[clip-l14-openai.model.safetensors](https://huggingface.co/openai/clip-vit-large-patch14/resolve/32bd64288804d66eefd0ccbe215aa642df71cc41/model.safetensors)<br>[clip-l14-openai.vocab.json](https://huggingface.co/openai/clip-vit-large-patch14/resolve/32bd64288804d66eefd0ccbe215aa642df71cc41/vocab.json)<br>[clip-l14-openai.merges.txt](https://huggingface.co/openai/clip-vit-large-patch14/resolve/32bd64288804d66eefd0ccbe215aa642df71cc41/merges.txt) | `8a09b467700c`<br>`a2bf730a0c7d`<br>`3f0c4f7d2086`<br>`9fd691f7c803` | MIT | yes |
| `siglip2-b16-256-text@1` | [siglip2-b16-256.config.json](https://huggingface.co/google/siglip2-base-patch16-256/resolve/3f9f96cb90da5dbc758b01813f2f6f1aee24c1ab/config.json)<br>[siglip2-b16-256.model.safetensors](https://huggingface.co/google/siglip2-base-patch16-256/resolve/3f9f96cb90da5dbc758b01813f2f6f1aee24c1ab/model.safetensors)<br>[siglip2-b16-256.tokenizer.json](https://huggingface.co/google/siglip2-base-patch16-256/resolve/3f9f96cb90da5dbc758b01813f2f6f1aee24c1ab/tokenizer.json) | `7b5aedcb8893`<br>`6125cacc01fa`<br>`cb9140fae3ac` | Apache-2.0 | yes |
| `siglip2-l16-256-text@1` | [siglip2-l16-256.config.json](https://huggingface.co/google/siglip2-large-patch16-256/resolve/787800c8990e6f058423089178e718139608408c/config.json)<br>[siglip2-l16-256.model.safetensors](https://huggingface.co/google/siglip2-large-patch16-256/resolve/787800c8990e6f058423089178e718139608408c/model.safetensors)<br>[siglip2-l16-256.tokenizer.json](https://huggingface.co/google/siglip2-large-patch16-256/resolve/787800c8990e6f058423089178e718139608408c/tokenizer.json) | `172e39dbf014`<br>`fa34f822f016`<br>`cb9140fae3ac` | Apache-2.0 | yes |

## Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0.

Training data: WIT: 400M image-text pairs collected from the web by OpenAI (CLIP paper); not released.

Licence evidence: <https://github.com/openai/CLIP/blob/d05afc436d78f1c48dc0dbf8e5980a9d471f35f6/LICENSE>

## Input size

any H x W >= 32, padded to a multiple of 32
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `clip-b16-openai-text` 3000x4000 (0.7 GiB peak allocated, 0.7 reserved); `clip-b32-openai-text` 3000x4000 (0.7 GiB peak allocated, 0.7 reserved); `clip-l14-openai-text` 3000x4000 (1.2 GiB peak allocated, 1.3 reserved); `siglip2-b16-256-text` 3000x4000 (1.1 GiB peak allocated, 1.2 reserved); `siglip2-l16-256-text` 3000x4000 (2.1 GiB peak allocated, 2.1 reserved)

## Speed and memory

### Retrieval, synthetic, 480x640

| model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `clip-b16-openai-text` | 7.85 | 5.07 | 4.35 | 3.53 | 1.4x | 1.2x | 330 / 380 | 336 / 354 | 328 / 350 |
| `clip-b32-openai-text` | 6.61 | 6.28 | 5.70 | 3.49 | 1.8x | 1.6x | 329 / 398 | 340 / 352 | 331 / 350 |
| `clip-l14-openai-text` | 26.3 | 8.79 | 7.94 | 6.84 | 1.3x | 1.2x | 860 / 934 | 869 / 894 | 858 / 886 |
| `siglip2-b16-256-text` | 9.49 | 5.52 | 4.98 | 4.16 | 1.3x | 1.2x | 767 / 1164 | 774 / 794 | 758 / 786 |
| `siglip2-l16-256-text` | 20.8 | 9.03 | 8.30 | 7.13 | 1.3x | 1.2x | 1720 / 2220 | 1725 / 1740 | 1724 / 1748 |

### Startup and first call

| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
| --- | --- | --- | --- | --- | --- | --- |
| `clip-b16-openai-text` | 0.27 | 0.24 | 2.93 | 0.04 | 0.01 | 0.16 |
| `clip-b32-openai-text` | 0.31 | 0.25 | 2.93 | 0.04 | 0.01 | 0.16 |
| `clip-l14-openai-text` | 0.45 | 0.44 | 3.61 | 0.08 | 0.01 | 0.17 |
| `siglip2-b16-256-text` | 1.79 | 1.13 | 4.02 | 0.46 | 0.01 | 0.14 |
| `siglip2-l16-256-text` | 2.14 | 1.54 | 5.53 | 0.03 | 0.01 | 0.13 |

### torch.compile and TensorRT

| model | input | time: portable | compile | TensorRT (fp16 unless shown) | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `clip-b16-openai-text` | 480x640 | 4.35 ms | 3.07 ms | 1.10 ms | 3.53 ms | 8.72 s | 19.8 s | 336 / 354 | 360 / 370 | 328 / 350 | 526 / 548 |
| `clip-b32-openai-text` | 480x640 | 5.70 ms | 3.27 ms | 0.814 ms | 3.49 ms | 8.64 s | 19.4 s | 340 / 352 | 361 / 368 | 331 / 350 | 529 / 548 |
| `clip-l14-openai-text` | 480x640 | 7.94 ms | 6.42 ms | 3.99 ms | 6.84 ms | 12.8 s | 33.0 s | 869 / 894 | 896 / 906 | 858 / 886 | 1476 / 1484 |
| `siglip2-b16-256-text` | 480x640 | 4.98 ms | 3.23 ms | 1.15 ms | 4.16 ms | 8.60 s | 41.8 s | 774 / 794 | 787 / 804 | 758 / 786 | 958 / 966 |
| `siglip2-l16-256-text` | 480x640 | 8.30 ms | 5.31 ms | 2.96 ms | 7.13 ms | 11.9 s | 45.4 s | 1725 / 1740 | 1754 / 1766 | 1724 / 1748 | 2346 / 2368 |

Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).

Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or `(fp32)` where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.

## Accuracy

### On public datasets

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 with the original code

Every variant is checked against reference outputs of the original code at its pinned commit. 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`).

## 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).

## Usage

```python
from fastforks import retrieval

model = retrieval.load("clip-b16-openai-text")  # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.descriptor  # [D] float32, unit norm
# fastforks.retrieval.top_k(queries, database, k=5): the nearest database images
result.backend  # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
```

Install with `pip install fastforks` (see <https://github.com/kleinicke/fastforks>). Other variants: `clip-b16-openai-text`, `clip-b32-openai-text`, `clip-l14-openai-text`, `siglip2-b16-256-text`, `siglip2-l16-256-text`.

## Kernels backend

`retrieval.load("clip-b16-openai-text", mode="kernels")` runs our CUDA kernels (`fvm_conv`). It needs a prebuilt kernel for your GPU architecture (downloaded from <https://huggingface.co/fastforks/kernels> on first use) and a recent NVIDIA driver; if there is none it raises `BackendUnavailableError` with the reason and never falls back silently. `mode="auto"` picks `kernels` when it can run and logs the choice.

<!-- staged from fastforks 0d8c365f7 (2026-12-02) -->