Instructions to use moonbox-dev/efficientvit-TensorRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TensorRT
How to use moonbox-dev/efficientvit-TensorRT with TensorRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download README.md from moonbox-dev/efficientvit-TensorRT: direct link, hf CLI and curl.
- Browser
- Download file 19.6 kB
-
https://huggingface.co/moonbox-dev/efficientvit-TensorRT/resolve/main/README.md
- Command line
-
hf download hf://moonbox-dev/efficientvit-TensorRT/README.md
-
curl -L -o README.md https://huggingface.co/moonbox-dev/efficientvit-TensorRT/resolve/main/README.md
license: apache-2.0
pipeline_tag: mask-generation
library_name: tensorrt
tags:
- tensorrt
- moonbox
- efficientvit
- efficientvit-sam
- segment-anything
- image-segmentation
EfficientViT-SAM TensorRT
TensorRT engines of EfficientViT-SAM, made by Moonbox for NVIDIA RTX GPUs. Each precision is one folder holding the
engine, trt_runner.py (a small numpy runner: TensorRT plus Polygraphy, no PyTorch) and a script that does the rest
of the pipeline. What the engine takes and returns is under How to run.
Compatibility. The engines are built hardware compatible (Ampere and newer: RTX 30, 40 and 50 series) and
version compatible (any TensorRT 10.x from 10.13 on, through its lean runtime). That costs a little speed against an
engine built for one GPU, but no rebuild is needed. Install the runtime with
pip install "tensorrt-cu12>=10.13,<11" "tensorrt-lean-cu12>=10.13,<11" polygraphy numpy.
Files
The last column is the benchmark (details under How to run).
| Precision | File | Size | sha256 | Benchmark |
|---|---|---|---|---|
| fp32 | fp32/decoder.engine |
75.1 MB | a2e0a324e55b |
no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms |
| fp32 | fp32/encoder.engine |
293.6 MB | 75711f129358 |
no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms |
| fp32 | fp32/pipeline.py |
4.2 kB | 3cee6dcd2a80 |
no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms |
| fp32 | fp32/pipeline_trt.py |
3.9 kB | fb1791cf9e66 |
no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms |
| fp32 | fp32/trt_runner.py |
3.3 kB | 0da2222f799a |
no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms |
How to run
EfficientViT-SAM (L0: an EfficientViT image encoder with SAM's mask decoder) as TensorRT engines plus
pipeline_trt.py. It follows the repository's EfficientViTSamPredictor like this model's ONNX pipeline.py:
- Picture: the longest side resized to 512, SAM's pixel mean / std, padded to 512 x 512.
- Prompts: given in the 1024 frame; point prompts give three masks, box prompts one.
import sys
import numpy as np
from PIL import Image
sys.path.insert(0, "fp32")
from pipeline_trt import EfficientViTSAMTrt
p = EfficientViTSAMTrt("fp32")
rgb = np.asarray(Image.open("photo.jpg").convert("RGB"))
emb, size = p.embed(rgb) # the image embedding, once per picture
masks, scores = p.point(emb, size, [[410, 300]]) # 3 masks [3, H, W] (bool) for a foreground point
mask, score = p.box(emb, size, [100, 80, 620, 540]) # 1 mask for a box
Or python fp32/pipeline_trt.py photo.jpg masks.npz --point 410 300 --box 100 80 620 540. It needs numpy, Pillow,
TensorRT and Polygraphy; opencv-python makes the final mask resize fast.
The engines.
encoder.engine:image[1, 3, 512, 512] ->image_embeddings[1, 256, 64, 64].decoder.engine: SAM's ONNX decoder wrapper up to its low-resolution masks.- Inputs:
image_embeddings,point_coords[1, N, 2] with N from 1 to 10,point_labels,mask_input,has_mask_input. - Outputs:
iou_predictionsandlow_res_masks[1, 4, 256, 256].
- Inputs:
- Resizing to the picture:
pipeline_trt.pydoes it with the same bilinear arithmetic, because TensorRT can't take the picture size as a float shape input.
Precisions. fp32/ only, as this model's ONNX build: its BatchNorm scales reach 602, and an fp16 build loses
masks (worst IoU 0.12). The engines are built without TF32, full fp32 math. That matters: ONNX Runtime's CUDA
provider uses TF32 by default, and with it this model's worst mask in the benchmark drops to IoU 0.16 against an
exact fp32 run. If you run the ONNX build on CUDA, set use_tf32 to 0.
Benchmark.
- Data: the first 8 photos of DIS5K-250, with a point prompt (3 masks) and the box prompt (1 mask) per photo, both from the ground truth: 32 masks.
- Run: the engines through
pipeline_trt.py, on an RTX 3080 Laptop GPU. - Reference: the ONNX
fp32/build through itspipeline.pyon ONNX Runtime's CPU provider (exact fp32). That build is within IoU 0.999 of the original (EfficientViTSamPredictor, fp32) on every mask. - Pass mark: IoU >= 0.99 against the reference on every mask.
| mask IoU vs the ONNX build (CPU): mean / worst | encoder alone | |
|---|---|---|
ONNX fp32/, CUDA with TF32 off |
- | 43.6 ms |
TensorRT fp32/ |
0.9999 / 0.9977 | 19.3 ms |
How these were made
From EfficientViT-SAM at revision de7d7733cc: each engine was built with TensorRT's builder from Moonbox's published
ONNX graph of the same model and precision. The network is strongly typed: every tensor keeps the precision the
ONNX graph gives it, so an fp16 engine computes what the fp16 ONNX build computes. Built on an RTX 3080 Laptop GPU,
it was benchmarked against the original before upload, and the sha256 column above is what the files must hash to.
License
apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this repository, and it governs your use of these files. The original model card follows unchanged.
Original model card
Efficient Vision Foundation Models for High-Resolution Generation and Perception
News
- (🔥 New) [2025/09/05] We will no longer maintain this codebase. All future updates and announcements will be made on DC-Gen.
- (🔥 New) [2025/01/24] We released DC-AE-SANA-1.1: doc.
- (🔥 New) [2025/01/23] DC-AE and SANA are accepted by ICLR 2025.
- (🔥 New) [2025/01/14] We released DC-AE+USiT models: model, training. Using the default training settings and sampling strategy, DC-AE+USiT-2B achieves 1.72 FID on ImageNet 512x512, surpassing the SOTA diffusion model EDM2-XXL and SOTA auto-regressive image generative models (MAGVIT-v2 and MAR-L).
- (🔥 New) [2024/12/24] diffusers supports DC-AE models. All DC-AE models in diffusers safetensors are released. Usage.
- [2024/10/21] DC-AE and EfficientViT block are used in our latest text-to-image diffusion model SANA! Check the project page for more details.
- [2024/10/15] We released Deep Compression Autoencoder (DC-AE): link!
- [2024/07/10] EfficientViT is used as the backbone in Grounding DINO 1.5 Edge for efficient open-set object detection.
- [2024/07/10] EfficientViT-SAM is used in MedficientSAM, the 1st place model in CVPR 2024 Segment Anything In Medical Images On Laptop Challenge.
- [2024/04/06] EfficientViT-SAM is accepted by eLVM@CVPR'24.
- [2024/03/19] Online demo of EfficientViT-SAM is available: https://evitsam.hanlab.ai/.
- [2024/02/07] We released EfficientViT-SAM, the first accelerated SAM model that matches/outperforms SAM-ViT-H's zero-shot performance, delivering the SOTA performance-efficiency trade-off.
- [2023/11/20] EfficientViT is available in the NVIDIA Jetson Generative AI Lab.
- [2023/09/12] EfficientViT is highlighted by MIT home page and MIT News.
- [2023/07/18] EfficientViT is accepted by ICCV 2023.
Content
[ICLR 2025] Deep Compression Autoencoder for Efficient High-Resolution Diffusion Models [paper] [readme] [poster]
Deep Compression Autoencoder (DC-AE) is a new family of high-spatial compression autoencoders with a spatial compression ratio of up to 128 while maintaining reconstruction quality. It accelerates all latent diffusion models regardless of the diffusion model architecture.
Demo
Figure 1: We address the reconstruction accuracy drop of high spatial-compression autoencoders.
Figure 2: DC-AE speeds up latent diffusion models.
Figure 3: DC-AE enables efficient text-to-image generation on the laptop: SANA.
- Usage of Deep Compression Autoencoder
- Usage of DC-AE-Diffusion
- Evaluate Deep Compression Autoencoder
- Demo DC-AE-Diffusion Models
- Evaluate DC-AE-Diffusion Models
- Train DC-AE-Diffusion Models
- Reference
[CVPR 2024 eLVM Workshop] EfficientViT-SAM: Accelerated Segment Anything Model Without Accuracy Loss [paper] [online demo] [readme]
EfficientViT-SAM is a new family of accelerated segment anything models by replacing SAM's heavy image encoder with EfficientViT. It delivers a 48.9x measured TensorRT speedup on A100 GPU over SAM-ViT-H without sacrificing accuracy.
- Pretrained EfficientViT-SAM Models
- Usage of EfficientViT-SAM
- Evaluate EfficientViT-SAM
- Visualize EfficientViT-SAM
- Deploy EfficientViT-SAM
- Train EfficientViT-SAM
- Reference
[ICCV 2023] EfficientViT-Classification [paper] [readme]
Efficient image classification models with EfficientViT backbones.
- Pretrained EfficientViT Classification Models
- Usage of EfficientViT Classification Models
- Evaluate EfficientViT Classification Models
- Export EfficientViT Classification Models
- Train EfficientViT Classification Models
- Reference
[ICCV 2023] EfficientViT-Segmentation [paper] [readme]
Efficient semantic segmantation models with EfficientViT backbones.
- Pretrained EfficientViT Segmentation Models
- Usage of EfficientViT Segmentation Models
- Evaluate EfficientViT Segmentation Models
- Visualize EfficientViT Segmentation Models
- Export EfficientViT Segmentation Models
- Reference
EfficientViT-GazeSAM [readme]
Gaze-prompted image segmentation models capable of running in real time with TensorRT on an NVIDIA RTX 4070.
Getting Started
conda create -n efficientvit python=3.10
conda activate efficientvit
pip install -U -r requirements.txt
Third-Party Implementation/Integration
Contact
Reference
If EfficientViT or EfficientViT-SAM or DC-AE is useful or relevant to your research, please kindly recognize our contributions by citing our paper:
@inproceedings{cai2023efficientvit,
title={Efficientvit: Lightweight multi-scale attention for high-resolution dense prediction},
author={Cai, Han and Li, Junyan and Hu, Muyan and Gan, Chuang and Han, Song},
booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
pages={17302--17313},
year={2023}
}
@article{zhang2024efficientvit,
title={EfficientViT-SAM: Accelerated Segment Anything Model Without Performance Loss},
author={Zhang, Zhuoyang and Cai, Han and Han, Song},
journal={arXiv preprint arXiv:2402.05008},
year={2024}
}
@article{chen2024deep,
title={Deep Compression Autoencoder for Efficient High-Resolution Diffusion Models},
author={Chen, Junyu and Cai, Han and Chen, Junsong and Xie, Enze and Yang, Shang and Tang, Haotian and Li, Muyang and Lu, Yao and Han, Song},
journal={arXiv preprint arXiv:2410.10733},
year={2024}
}



