Downloads · 30 days
0
guruansh/nexvi-siglip2-so400m-naflex-onnx-1024-4096
nexvi-siglip2-so400m-naflex-onnx-1024-4096 is a feature extraction model from guruansh. Use it when you need embeddings to search or compare text. It is set up for onnx. The card lists the license as apache-2.0.
Three fixed-length ONNX exports of the vision-encoder tail from google/siglip2-so400m-patch16-naflex, at revision cc24074f717b612951c2dead130904ab9b65a81e.
Downloads · 30 days
0
Access
Public
Updated Sep 19, 2026
Repo size
2.6 GB
Likes
1
Public
Click a slice to open those files.
.onnx2.6 GB · 100%
From the Hugging Face model README
Three fixed-length ONNX exports of the vision-encoder tail from
google/siglip2-so400m-patch16-naflex,
at revision cc24074f717b612951c2dead130904ab9b65a81e.
These files exist for workloads that need more than 576 patches per image. Each file has a fixed sequence length, allowing TensorRT to specialize the graph for that patch budget.
Each graph contains only the 27 vision-transformer layers, post-layernorm, and attention-pooling head. It does not contain:
Its input is not an image. Pass the hidden states produced by
vision_model.embeddings(pixel_values, spatial_shapes). Feeding images to these
graphs directly will fail or yield incorrect results.
| File | Fixed patch budget | SHA-256 |
|---|---|---|
siglip2_400m_naflex_1024.onnx | 1024 | 81e94fbd8876ad70ac565b1ca02753c051290aceac4dc592cf3411aee7949a5a |
siglip2_400m_naflex_2048.onnx | 2048 | 44efd3f2cc13a4d1cf8b506779d7431162f41aefe22f66b3bf1ed9bf89a59719 |
siglip2_400m_naflex_4096.onnx | 4096 | a6dc062138aec695fc408ad254c1d51233e84199f9b25f074d00a4e359f49556 |
The 576-patch export is maintained as a separate public release and is not included or changed here.
NaFlex keeps native aspect ratios by interpolating its learned position grid per
image from spatial_shapes. That is data-dependent control flow. Tracing the
embedding front end bakes in the export batch's aspect ratios, yet returns
plausible vectors for other images. Exporting only the static tail preserves
correct NaFlex behavior and leaves the small embedding front end in PyTorch.
Each graph uses ONNX opset 17. N is the fixed number in the filename.
| Name | Dtype | Shape | |
|---|---|---|---|
| input | hidden_states | float16 | [batch, N, 1152] |
| input | attention_mask | int32 | [batch, N] |
| output | pooled | float16 | [batch, 1152] |
Bind the dtypes exactly. attention_mask comes from the processor's
pixel_attention_mask (1 = real patch; 0 = padding).
import numpy as np
import torch
import onnxruntime as ort
from PIL import Image
from transformers import AutoModel, AutoProcessor
MODEL_ID = "google/siglip2-so400m-patch16-naflex"
REVISION = "cc24074f717b612951c2dead130904ab9b65a81e"
MAX_NUM_PATCHES = 2048 # choose 1024, 2048, or 4096 to match the ONNX file
ONNX_FILE = f"siglip2_400m_naflex_{MAX_NUM_PATCHES}.onnx"
processor = AutoProcessor.from_pretrained(MODEL_ID, revision=REVISION)
model = AutoModel.from_pretrained(
MODEL_ID, revision=REVISION, torch_dtype=torch.float16
).cuda().eval()
image = Image.open("image.jpg").convert("RGB")
inputs = processor(images=[image], return_tensors="pt", max_num_patches=MAX_NUM_PATCHES)
inputs = {name: value.cuda() for name, value in inputs.items()}
# NaFlex embedding front end remains in PyTorch.
with torch.no_grad(), torch.autocast("cuda"):
hidden = model.vision_model.embeddings(inputs["pixel_values"], inputs["spatial_shapes"])
# Static encoder tail runs from ONNX.
session = ort.InferenceSession(ONNX_FILE, providers=["CUDAExecutionProvider"])
pooled = session.run(["pooled"], {
"hidden_states": hidden.half().cpu().numpy(),
"attention_mask": inputs["pixel_attention_mask"].to(torch.int32).cpu().numpy(),
})[0]
embedding = pooled / np.linalg.norm(pooled, axis=-1, keepdims=True)
export_tail.py in this repository exports any included patch budget from the
pinned upstream model:
python export_tail.py --max-num-patches 1024 --fp16 --verify
python export_tail.py --max-num-patches 2048 --fp16 --verify
python export_tail.py --max-num-patches 4096 --fp16 --verify
The script validates the split path against get_image_features before export
and can compare ONNX against PyTorch on held-out aspect ratios.
All three released files passed onnx.checker, load in ONNX Runtime, and have
the declared fp16/int32 interface. The original held-out-photograph export
validation recorded the following cosine agreement with the PyTorch tail:
| Patch budget | Cosine vs PyTorch | Distinct held-out grids |
|---|---|---|
| 1024 | 0.999989 | 6 of 6 |
| 2048 | 0.999998 | 4 of 4 |
| 4096 | 0.999998 | 3 of 3 |
Performance depends heavily on GPU architecture and the selected patch budget. Build a TensorRT engine on the target hardware and benchmark the complete PyTorch-front-end plus ONNX-tail path before deployment.
max_num_patches setting.Apache-2.0, inherited from
google/siglip2-so400m-patch16-naflex.
All learned weights originate with Google; this repository contributes ONNX
graph transformations and release tooling. Please cite the original SigLIP 2
work:
@article{tschannen2025siglip2,
title = {SigLIP 2: Multilingual Vision-Language Encoders with Improved
Semantic Understanding, Localization, and Dense Features},
author = {Tschannen, Michael and others},
journal = {arXiv preprint arXiv:2502.14786},
year = {2025}
}