Skip to content
项目

关于

DynamicTanh(DyT)的代码发布

其他项目

这些数字如何统计

实测星标增长

24小时
0
7天
-1
15天
-4
1个月
-1

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Transformers without Normalization

Official PyTorch implementation of DynamicTanh (DyT), from the following paper:

Transformers without Normalization. CVPR 2025.
Jiachen Zhu, Xinlei Chen, Kaiming He, Yann LeCun and Zhuang Liu
FAIR, NYU, MIT, Princeton
[arXiv][project page]


We propose DynamicTanh(DyT), an element-wise operation defined as: DyT(x) = tanh($\alpha$x), where $\alpha$ is a learnable scaler. DyT is designed to replace normalization layers in Transformers. Models with DyT achieves similar or better performance than their normalized counterparts.

Installation

To reproduce our results, run the following commands to set up the Python environment:

conda create -n DyT python=3.12
conda activate DyT
conda install pytorch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 pytorch-cuda=12.4 -c pytorch -c nvidia
pip install timm==1.0.15 tensorboard

Training

To reproduce our results on ImageNet-1K with ViT and ConvNeXt, run the following commands:
(For results with LN, set --dynamic_tanh to false.)

ViT-B
torchrun --nnodes=8 --nproc_per_node=8 main.py \
    --model vit_base_patch16_224 \
    --drop_path 0.1 \
    --batch_size 64 \
    --lr 4e-3 \
    --update_freq 1 \
    --model_ema true \
    --model_ema_eval true \
    --data_path /path/to/imagenet \
    --output_dir /path/to/saving_dir \
    --dynamic_tanh true
ViT-L
torchrun --nnodes=8 --nproc_per_node=8 main.py \
    --model vit_large_patch16_224 \
    --drop_path 0.4 \
    --batch_size 64 \
    --lr 4e-3 \
    --update_freq 1 \
    --model_ema true \
    --model_ema_eval true \
    --opt_betas 0.9 0.95 \
    --data_path /path/to/imagenet \
    --output_dir /path/to/saving_dir \
    --dynamic_tanh true
ConvNeXt-B
torchrun --nnodes=8 --nproc_per_node=8 main.py \
    --model convnext_base \
    --drop_path 0.5 \
    --batch_size 64 \
    --lr 4e-3 \
    --update_freq 1 \
    --model_ema true \
    --model_ema_eval true \
    --data_path /path/to/imagenet \
    --output_dir /path/to/saving_dir \
    --dynamic_tanh true
ConvNeXt-L
torchrun --nnodes=8 --nproc_per_node=8 main.py \
    --model convnext_large \
    --drop_path 0.5 \
    --batch_size 64 \
    --lr 4e-3 \
    --update_freq 1 \
    --model_ema true \
    --model_ema_eval true \
    --data_path /path/to/imagenet \
    --output_dir /path/to/saving_dir \
    --dynamic_tanh true

ImageNet-1K Results

name acc@1 (LN) acc@1 (DyT)
ViT-B 82.3% 82.5%
ViT-L 83.1% 83.6%
ConvNeXt-B 83.7% 83.7%
ConvNeXt-L 84.3% 84.4%

Other Tasks

To reproduce results for other tasks, follow the instructions in the respective folders:

To apply DyT to your own models, see the HowTo guide.

Efficiency

To reproduce the computational efficiency results in Section 6.1, follow the instructions in the Efficiency folder.

Acknowledgement

This repository is built using the timm library and ConvNeXt repository.

License

This project is released under the MIT license. Please see the LICENSE file for more information.

Citation

If you find this repository helpful, please consider citing:

@inproceedings{Zhu2025DyT,
  title={Transformers without Normalization},
  author={Zhu, Jiachen and Chen, Xinlei and He, Kaiming and LeCun, Yann and Liu, Zhuang},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2025}
}

探索相关项目

加载中…