Instructions to use sofieneb/omni-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sofieneb/omni-small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="sofieneb/omni-small", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("sofieneb/omni-small", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
OMNI-S: Scaling Multi-Teacher Distillation for Digital Pathology
Model Summary
OMNI-S is a 28.7M-parameter pathology vision encoder distilled from 9 state-of-the-art pathology foundation models at once. Instead of compressing all teachers into a single CLS token (vanilla multi-teacher distillation), OMNI learns one token per teacher, together with a structured attention mask, Mixture-of-Experts (MoE) layers and a per-teacher contrastive loss. This lets distillation keep improving as more teachers are added.
By default the model returns the average of its 9 teacher-specific tokens, which is the embedding used for all results below. The individual teacher tokens and the patch tokens can also be returned with a flag.
- โก Efficient: 5.48 GFLOPs per 224ร224 tile
- ๐ง Distilled from 9 teachers: H-optimus-0, Virchow2, UNI2-h, Prov-GigaPath, Kaiko-ViT-B/8, CONCH v1.5, Hibou-L, KEEP, DINOv3-ViT-L/16
- ๐ Trained on 10M tiles from 10k TCGA whole-slide images
Note on the teachers. Due to the license terms of some teacher models, the released weights were distilled from a different set of teachers than the one used in our paper. The architecture and training recipe are unchanged; the results of the released models are reported in the Results section.
Other sizes of the collection:
| Model | Params | Dim | GFLOPs | Tile LP F1 (%) | Slide LP BAcc (%) |
|---|---|---|---|---|---|
| OMNI-T | 7.3M | 192 | 1.39 | 83.9 | 62.7 |
| OMNI-S (this model) | 28.7M | 384 | 5.48 | 85.9 | 62.6 |
| OMNI-B | 114M | 768 | 21.8 | 86.8 | 63.2 |
๐ Paper: Scaling Multi-Teacher Distillation for Digital Pathology (NeurIPS 2026)
Model Details
| Architecture | ViT-Small/14 with a MoE tail |
| Embedding dim | 384 |
| Depth / heads | 12 blocks / 6 heads |
| MoE | last 3 blocks, 5 experts, top-2 routing |
| Teacher tokens | 9 (one per teacher) |
| Input | 224 ร 224 RGB, ImageNet normalization |
| Patch tokens | 16 ร 16 = 256 |
Results
Due to the license terms of some teacher models, the released models were distilled from a different set of teachers than the one used in the paper. The table compares the released models with the models trained on the original set of teachers, on the benchmarks of the paper: linear probing on THUNDER (tile level, F1) and PathoBench (slide level, balanced accuracy, mean pooling).
| Model | Tile LP F1 (%), original teachers | Tile LP F1 (%), released | ฮ | Slide LP BAcc (%), original teachers | Slide LP BAcc (%), released | ฮ |
|---|---|---|---|---|---|---|
| OMNI-T | 83.9 | 83.9 | +0.0 | 63.2 | 62.7 | โ0.5 |
| OMNI-S | 85.3 | 85.9 | +0.6 | 63.1 | 62.6 | โ0.5 |
| OMNI-B | 87.1 | 86.8 | โ0.3 | 63.2 | 63.2 | +0.0 |
Usage
import torch
from PIL import Image
from transformers import AutoModel
device = "cuda" if torch.cuda.is_available() else "cpu"
# Load OMNI-S
model = AutoModel.from_pretrained("sofieneb/omni-small", trust_remote_code=True).to(device).eval()
transform = model.get_transform() # resize to 224 + ImageNet normalization
image = Image.open("tile.png").convert("RGB")
x = transform(image).unsqueeze(0).to(device) # (1, 3, 224, 224)
with torch.inference_mode():
embedding = model(x) # average of the 9 teacher tokens
print(embedding.shape) # (1, 384)
Teacher tokens and patch tokens
with torch.inference_mode():
out = model(x, return_teacher_tokens=True, return_patch_tokens=True)
out["embedding"] # (1, 384) average of the teacher tokens (same as model(x))
out["teacher_tokens"] # (1, 9, 384) one token per teacher
out["patch_tokens"] # (1, 256, 384) 16 x 16 patch tokens
# Teacher order of the tokens
print(model.teachers)
# Example: keep the token of a single teacher
idx = 0 # position of the teacher you want in model.teachers
single_teacher = out["teacher_tokens"][:, idx] # (1, 384)
Teacher tokens are well separated and complementary, so the simple average works well out of the box. You can also learn a task-specific weighting of the 9 tokens (see Table 2 of the paper).
Mixed precision
with torch.inference_mode(), torch.autocast(device_type="cuda", dtype=torch.bfloat16):
embedding = model(x)
Quick evaluation with THUNDER
eval_thunder.py wraps the model for the THUNDER benchmark:
pip install thunder-bench
export THUNDER_BASE_DATA_FOLDER=/path/to/thunder_data
thunder download-datasets bach
# kNN + linear probing on BACH
python eval_thunder.py --datasets bach --tasks knn linear_probing
# or through THUNDER's CLI (any task)
thunder benchmark custom:eval_thunder.py bach linear_probing
Results are written to $THUNDER_BASE_DATA_FOLDER/outputs/res/<dataset>/omni-small/<task>/.
Offline usage (HPC clusters without internet)
If compute nodes don't have internet, always run jobs with the offline flags:
export HF_HUB_OFFLINE=1
export TRANSFORMERS_OFFLINE=1
Prepare the model in advance on a front-end/login node (with internet):
hf download sofieneb/omni-small --local-dir ./omni-small
Then in your offline job/script:
from transformers import AutoModel
model = AutoModel.from_pretrained(
"./omni-small", # local path instead of hub ID
trust_remote_code=True,
local_files_only=True, # uses local files only
)
Citation
If our work contributes to your research, please consider citing our paper:
@inproceedings{boutaj2026omni,
title={Scaling Multi-Teacher Distillation for Digital Pathology},
author={Boutaj, Sofi{\`e}ne and Marza, Pierre and Belagali, Varun and Samaras, Dimitris and Vakalopoulou, Maria and Christodoulidis, Stergios},
booktitle={Advances in Neural Information Processing Systems (NeurIPS)},
year={2026}
}
- Downloads last month
- -