YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

BinaryAttention: One-Bit QK-Attention for Vision and Diffusion Transformers

1The Hong Kong Polytechnic University, 2OPPO Research Institute
(†) corresponding author

[πŸ“ arXiv paper]   [πŸ€— Hugging Face]


🚩Accepted by CVPR2026

🎬 Overview

main

πŸ“– Abstract

Transformers have achieved widespread and remarkable success, while the computational complexity of their attention modules remains a major bottleneck for vision tasks. Existing methods mainly employ 8-bit or 4-bit quantization to balance efficiency and accuracy. In this paper, with theoretical justification, we indicate that binarization of attention preserves the essential similarity relationships, and propose BinaryAttention, an effective method for fast and accurate 1-bit qk-attention. Specifically, we retain only the sign of queries and keys in computing the attention, and replace the floating dot products with bit-wise operations, significantly reducing the computational cost. We mitigate the inherent information loss under 1-bit quantization by incorporating a learnable bias, and enable end-to-end acceleration. To maintain the accuracy of attention, we adopt quantization-aware training and self-distillation techniques, mitigating quantization errors while ensuring sign-aligned similarity. BinaryAttention is more than 2x faster than FlashAttention2 on A100 GPUs. Extensive experiments on vision transformer and diffusion transformer benchmarks demonstrate that BinaryAttention matches or even exceeds full-precision attention, validating its effectiveness. Our work provides a highly efficient and effective alternative to full-precision attention, pushing the frontier of low-bit vision and diffusion transformers.

🎯 Main Results

  • Image Classification on ImageNet-1K

classification

  • Object Detection and Instance Segmentation on COCO

detection

  • Semantic Segmentation on ADE20K

segmentation

  • Image Generation on ImageNet-1K

generation

πŸ› οΈ Getting Started

# 1. Clone the repository
git clone https://github.com/EdwardChasel/BinaryAttention.git
cd BinaryAttention

# 2. Create and activate a new conda environment
conda create -n BinaryAttention python=3.10
conda activate BinaryAttention

# 3. Install dependent packages
pip install --upgrade pip
pip install -r requirements.txt

✨ Pre-trained Models

ImageNet-1k Image Classification

name pretrain resolution acc@1 #param OPs download
BinaryAttention-T ImageNet-1K 224x224 72.88 6M 1.1G ckpt
BinaryAttention-S ImageNet-1K 224x224 80.24 22M 4.3G ckpt
BinaryAttention-B ImageNet-1K 224x224 82.04 87M 17.0G ckpt
BinaryAttention-B ImageNet-1K 384x384 83.64 87M 50.2G ckpt

πŸ“š Data Preparation

ImageNet is an image database organized according to the WordNet hierarchy. Download and extract ImageNet train and val images from http://image-net.org/. Organize the data into the following directory structure:

imagenet/
β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ n01440764/  (Example synset ID)
β”‚   β”‚   β”œβ”€β”€ image1.JPEG
β”‚   β”‚   β”œβ”€β”€ image2.JPEG
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ n01443537/  (Another synset ID)
β”‚   β”‚   └── ...
β”‚   └── ...
└── val/
    β”œβ”€β”€ n01440764/  (Example synset ID)
    β”‚   β”œβ”€β”€ image1.JPEG
    β”‚   └── ...
    └── ...

πŸš€ Quick Start

To train BinaryAttention models for classification on ImageNet, use the following commands for different configurations:

python -m torch.distributed.launch --nproc_per_node=8 --use_env main.py \
       --model </name/of/model> \
       --attn-quant --attn-bias --pv-quant \
       --batch-size 128 \
       --input-size </size/of/input/image> \
       --epochs 300 --lr 5e-5 --min-lr 5e-6 --weight-decay 0.02 \
       --finetune </path/of/full-precision/checkpoint> \
       --data-path </path/of/dataset> \
       --output_dir </path/of/output> \
       ## optional, defaults to tiny disable, small and base enable.
       # --distillation-type hard \
       # --teacher-path </path/of/full-precision/checkpoint>

To evaluate the performance with pre-trained weights:

python main.py --eval --resume </path/of/checkpoint> --data-path </path/of/dataset> --model </name/of/model> --attn-quant --attn-bias --pv-quant --input-size </size/of/input>

πŸ–ŠοΈ Citation

@inproceedings{xiao2026binary,
  title={BinaryAttention: One-Bit QK-Attention for Vision and Diffusion Transformers},
  author={Xiao, Chaodong and Zhang, Zhengqiang and Zhang, Lei},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year={2026}
}

πŸ’Œ Acknowledgments

This project is largely based on DeiT, SageAttention. We are truly grateful for their excellent work.

🎫 License

This project is released under the Apache 2.0 license.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Paper for EdwardChasel/BinaryAttention