Model Card for ToMe-SigLIP2 (tome-siglip2-base-patch16-224)
A Token Merging (ToMe) wrapper around google/siglip2-base-patch16-224 using bipartite soft matching (bipartite_soft_matching_merge) across vision encoder layers to reduce visual patch tokens during inference.
Model Details
Model Description
TomeSiglip2Model wraps a SigLIP2 vision-language backbone (Siglip2Model) inside a custom transformers PreTrainedModel with auto_map support (TomeSiglip2Config and TomeSiglip2Model). A forward pre-hook on the vision embeddings handles 4D image tensor patchification and spatial shape construction, while forward hooks on vision encoder layers merge similar patch tokens dynamically controlled by tokens_to_prune_per_layer (r).
- Developed by:
- Funded by [optional]: [More Information Needed]
- Shared by [optional]:
<your-hf-username> - Model type: Vision-Language / Zero-Shot Image Classification with Token Merging (
tome_siglip2) - Language(s) (NLP): English (text prompts)
- License: apache-2.0
- Finetuned from model [optional]:
google/siglip2-base-patch16-224
Model Sources [optional]
- Repository:
https://huggingface.co/<your-hf-username>/tome-siglip2-base-patch16-224
Uses
Direct Use
Zero-shot image classification and image/text embedding extraction with configurable visual token merging (r) for lower-latency vision inference.
Downstream Use [optional]
Can be integrated into interactive demos (such as Gradio Spaces) or adapted for visual search, filtering, and edge/low-latency vision pipelines where slight spatial token compression is acceptable.
Out-of-Scope Use
Not intended for safety-critical clinical, medical, or high-stakes autonomous decision-making without task-specific validation and calibration.
Bias, Risks, and Limitations
- Token Merging Trade-Off: Higher
r(tokens_to_prune_per_layer) reduces visual tokens and compute cost but can merge fine-grained visual details or small objects. - Patch Embedding & Weight Loading Caveats: Verify
vision_model.embeddings.patch_embedding.weightshapes and calibrate probability thresholds on real target images before relying on raw sigmoid scores. - Trusted Remote Code: Requires
trust_remote_code=Truewhen loading viaAutoModel.from_pretrainedbecauseTomeSiglip2ConfigandTomeSiglip2Modelare defined in custom module files (auto_map).
Recommendations
Users (both direct and downstream) should test across candidate r values (e.g., 0, 4, 6, 8) on representative data to balance speed against accuracy, and only load with trust_remote_code=True from trusted repositories.
How to Get Started with the Model
Use the code below to get started with the model.
import torch
from PIL import Image
from transformers import AutoModel, AutoProcessor
repo_id = "<your-hf-username>/tome-siglip2-base-patch16-224"
processor = AutoProcessor.from_pretrained(repo_id)
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).eval()
# Optional: adjust tokens merged per layer at runtime
model.r = 6
image = Image.new("RGB", (224, 224), color=(30, 120, 210))
inputs = processor(
text=["a blue photo", "a dark photo"],
images=image,
padding="max_length",
return_tensors="pt",
)
with torch.no_grad():
outputs = model(**inputs)
probs = torch.sigmoid(outputs.logits_per_image)[0]
print("Probabilities:", probs.tolist())