Instructions to use moonbox-ai/efficientvit-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use moonbox-ai/efficientvit-MLX with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download moonbox-ai/efficientvit-MLX --local-dir efficientvit-MLX
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
- EfficientViT-SAM MLX
- Original model card
- Efficient Vision Foundation Models for High-Resolution Generation and Perception
- News
- Content
- [ICLR 2025] Deep Compression Autoencoder for Efficient High-Resolution Diffusion Models [paper] [readme] [poster]
- [CVPR 2024 eLVM Workshop] EfficientViT-SAM: Accelerated Segment Anything Model Without Accuracy Loss [paper] [online demo] [readme]
- [ICCV 2023] EfficientViT-Classification [paper] [readme]
- [ICCV 2023] EfficientViT-Segmentation [paper] [readme]
- EfficientViT-GazeSAM [readme]
- Getting Started
- Third-Party Implementation/Integration
- Contact
- Reference
- News
EfficientViT-SAM MLX
MLX builds of EfficientViT-SAM, made by Moonbox for Apple Silicon Macs. Each precision is a folder; keep a folder's files together. Only the parts listed below are converted: the rest of the pipeline comes from the original repository unless the section below says otherwise.
Files
The last column is how far each build is from the original PyTorch model on the same inputs (see the section below for what was measured).
| Precision | File | Size | sha256 | Checked against the original |
|---|---|---|---|---|
| bf16 | bf16/config.json |
0.3 kB | 9e98792690f7 |
below threshold (experimental): mask IoU 0.714 mean / 0.091 worst |
| bf16 | bf16/mlx_model.py |
25.4 kB | 42cea84fb312 |
below threshold (experimental): mask IoU 0.714 mean / 0.091 worst |
| bf16 | bf16/model.safetensors |
122.7 MB | e7acc4ef2253 |
below threshold (experimental): mask IoU 0.714 mean / 0.091 worst |
| fp16 | fp16/config.json |
0.3 kB | 9b286f991620 |
below threshold (experimental): mask IoU 0.942 mean / 0.611 worst (float32 port: 0.9996 / 0.997) |
| fp16 | fp16/mlx_model.py |
25.4 kB | 42cea84fb312 |
below threshold (experimental): mask IoU 0.942 mean / 0.611 worst (float32 port: 0.9996 / 0.997) |
| fp16 | fp16/model.safetensors |
122.7 MB | f4b4b159c9f7 |
below threshold (experimental): mask IoU 0.942 mean / 0.611 worst (float32 port: 0.9996 / 0.997) |
How to run
EfficientViT-SAM L2 (EfficientViT-L2 image encoder at 512 px + SAM's prompt encoder and mask decoder) ported to
MLX. Each folder holds model.safetensors, config.json and mlx_model.py, the port (only mlx, numpy and
pillow needed), with EfficientViTSamPredictor's interface:
import numpy as np, mlx_model
from PIL import Image
model = mlx_model.load("fp16")
rgb = np.array(Image.open("in.jpg").convert("RGB"))
emb = mlx_model.embed(model, rgb)
masks, scores, low_res, logits = mlx_model.predict(model, emb, points=[[320, 240]], labels=[1], multimask=True)
Both folders are experimental: this model needs float32. Thirty of its 1x1 convolutions are followed by a
BatchNorm with a running variance down to 5.5e-7 (scales up to 600): those channels carry their signal in the 4th-5th
significant digit of the convolution output, which 16-bit weights or arithmetic can't hold. The port itself is exact:
run in float32 (with MLX_ENABLE_TF32=0, else MLX's float32 matmuls use TF32) it matches PyTorch to mask IoU 0.9996.
There are no 8bit / 6bit / 4bit folders: quantized, the model gives no usable masks.
| Precision | Size | Mask IoU vs PyTorch fp32 (mean / worst) | Status |
|---|---|---|---|
fp16/ |
122.7 MB | 0.942 / 0.611 | below threshold (0.95), experimental |
bf16/ |
122.7 MB | 0.714 / 0.091 | below threshold, experimental |
To run in float32, load either folder and cast the parameters up (model.update(mlx.utils.tree_map(lambda a: a.astype(mx.float32), model.parameters()))): fp16 weights in float32 give 0.966 mean / 0.62 worst, still short of
the original's float32 weights. About 55 ms per image (encoder + 2 prompts) on an Apple M5.
How these were made
From EfficientViT-SAM at revision de7d7733cc: the original weights loaded in MLX and stored as bf16 or fp16, or
quantized with MLX's affine quantization (8bit, 6bit, 4bit, group size 64; layers MLX can't quantize, such as
convolutions and norms, stay bf16). Every build was checked against the original before upload; 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}
}
Quantized




# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download moonbox-ai/efficientvit-MLX --local-dir efficientvit-MLX