NormΓ—Direction: Restoring the Missing Query Norm in Vision Linear Attention [ICML 2026]

August 5, 2026 Β· View on GitHub

πŸš€ Welcome to the repo of NaLaFormer!

This repo contains the official PyTorch code for NaLaFormer.

arXiv

Introduction

Motivation

Linear attention mitigates the quadratic complexity of softmax attention but suffers from a critical loss of expressiveness. We identify two primary causes: (1) The normalization operation cancels the query norm, which breaks the correlation between a query's norm and the spikiness (entropy) of the attention distribution as in softmax attention. (2) Standard techniques for enforcing non-negativity cause destructive information loss by nullifying valid inner-product interactions.

To address these challenges, we propose NaLaFormer, which achieves a superior balance between expressive capability and efficiency.

Method

We introduce NaLaFormer, a novel linear attention mechanism built upon a normΓ—direction (ND) decomposition of the query and key vectors. We leverage each component to solve a distinct problem:

  • Query-norm-aware feature map: The query norm is injected into our kernel to create a query-norm-aware map that restores the attention distribution's spikiness.
  • Cosine direction similarity: The direction vectors are processed by a geometric, cosine-based similarity metric that guarantees non-negativity while preserving the rich, fine-grained information of the inner product.

Results

  • Comparison of different models on ImageNet-1K.
ModelParamsFLOPsTop-1 Acc (%)
NaLaFormer-XT8M1.0G79.1
NaLaFormer-T15M2.7G82.6
NaLaFormer-S26M5.1G84.3
NaLaFormer-B52M12G85.2
NaLaFormer-L95M18G85.7

Dependencies

  • Python 3.9+
  • PyTorch == 2.4.0
  • torchvision == 0.19.0
  • numpy
  • timm >= 0.4.12
  • fvcore
  • einops

Data preparation

The ImageNet dataset should be prepared as follows:

$ tree data
imagenet
β”œβ”€β”€ train
β”‚   β”œβ”€β”€ class1
β”‚   β”‚   β”œβ”€β”€ img1.jpeg
β”‚   β”‚   β”œβ”€β”€ img2.jpeg
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ class2
β”‚   β”‚   β”œβ”€β”€ img3.jpeg
β”‚   β”‚   └── ...
β”‚   └── ...
└── val
    β”œβ”€β”€ class1
    β”‚   β”œβ”€β”€ img4.jpeg
    β”‚   β”œβ”€β”€ img5.jpeg
    β”‚   └── ...
    β”œβ”€β”€ class2
    β”‚   β”œβ”€β”€ img6.jpeg
    β”‚   └── ...
    └── ...

Pretrained Models

Pre-trained weights will be released soon. The following models are supported in this repo:

modelResoacc@1model name
NaLaFormer-XT224Β²79.1NALAFORMER_XT
NaLaFormer-T224Β²82.6NALAFORMER_T
NaLaFormer-S224Β²84.3NALAFORMER_S
NaLaFormer-B224Β²85.2NALAFORMER_B
NaLaFormer-L224Β²85.7NALAFORMER_L

Evaluate one model on ImageNet:

python -m torch.distributed.launch --nproc_per_node=8 --use_env main.py \
    --model NALAFORMER_XT \
    --data-path <imagenet-path> \
    --output_dir <output-path> \
    --eval --dist-eval

Train Models from Scratch

To train NaLaFormer on ImageNet from scratch, see pretrain.sh and run:

export DATA=/path/to/imagenet
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
export NPROC=8
bash pretrain.sh

You can also specify the model variant via --model, e.g. NALAFORMER_T, NALAFORMER_S, NALAFORMER_B, NALAFORMER_L.

Citation

If you find this repo helpful, please consider citing us.

@inproceedings{meng2026nalaformer,
  title={Norm$\times$Direction: Restoring the Missing Query Norm in Vision Linear Attention},
  author={Weikang Meng and Yadan Luo and Liangyu Huo and Yingjian Li and Yaowei Wang and Xin Li and Zheng Zhang},
  booktitle={International Conference on Machine Learning},
  year={2026}
}