Skip to content

Commit 2bf71f5

Browse files
committed
Merge remote-tracking branch 'origin/main' into naflex
2 parents fe2867c + a22366e commit 2bf71f5

File tree

11 files changed

+2818
-91
lines changed

11 files changed

+2818
-91
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212

1313
## What's New
1414

15+
## May 28, 2025
16+
* Add a number of small/fast models thanks to https://github.com/brianhou0208
17+
* SwiftFormer - [(ICCV2023) SwiftFormer: Efficient Additive Attention for Transformer-based Real-time Mobile Vision Applications](https://github.com/Amshaker/SwiftFormer)
18+
* FasterNet - [(CVPR2023) Run, Don’t Walk: Chasing Higher FLOPS for Faster Neural Networks](https://github.com/JierunChen/FasterNet)
19+
* SHViT - [(CVPR2024) SHViT: Single-Head Vision Transformer with Memory Efficient](https://github.com/ysj9909/SHViT)
20+
* StarNet - [(CVPR2024) Rewrite the Stars](https://github.com/ma-xu/Rewrite-the-Stars)
21+
* GhostNet-V3 [GhostNetV3: Exploring the Training Strategies for Compact Models](https://github.com/huawei-noah/Efficient-AI-Backbones/tree/master/ghostnetv3_pytorch)
22+
* Update EVA ViT (closest match) to support Perception Encoder models (https://arxiv.org/abs/2504.13181) from Meta, loading Hub weights but I still need to push dedicated `timm` weights
23+
* Add some flexibility to ROPE impl
24+
* Big increase in number of models supporting `forward_intermediates()` and some additional fixes thanks to https://github.com/brianhou0208
25+
* DaViT, EdgeNeXt, EfficientFormerV2, EfficientViT(MIT), EfficientViT(MSRA), FocalNet, GCViT, HGNet /V2, InceptionNeXt, Inception-V4, MambaOut, MetaFormer, NesT, Next-ViT, PiT, PVT V2, RepGhostNet, RepViT, ResNetV2, ReXNet, TinyViT, TResNet, VoV
26+
* TNT model updated w/ new weights `forward_intermediates()` thanks to https://github.com/brianhou0208
27+
* Add `local-dir:` pretrained schema, can use `local-dir:/path/to/model/folder` for model name to source model / pretrained cfg & weights Hugging Face Hub models (config.json + weights file) from a local folder.
28+
* Fixes, improvements for onnx export
29+
1530
## Feb 21, 2025
1631
* SigLIP 2 ViT image encoders added (https://huggingface.co/collections/timm/siglip-2-67b8e72ba08b09dd97aecaf9)
1732
* Variable resolution / aspect NaFlex versions are a WIP

tests/test_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
'regnet', 'byobnet', 'byoanet', 'mlp_mixer', 'hiera', 'fastvit', 'hieradet_sam2', 'aimv2*', 'tnt',
5757
'tiny_vit', 'vovnet', 'tresnet', 'rexnet', 'resnetv2', 'repghost', 'repvit', 'pvt_v2', 'nextvit', 'nest',
5858
'mambaout', 'inception_next', 'inception_v4', 'hgnet', 'gcvit', 'focalnet', 'efficientformer_v2', 'edgenext',
59-
'davit', 'rdnet', 'convnext', 'pit'
59+
'davit', 'rdnet', 'convnext', 'pit', 'starnet', 'shvit', 'fasternet', 'swiftformer', 'ghostnet',
6060
]
6161

6262
# transformer / hybrid models don't support full set of spatial / feature APIs and/or have spatial output.
6363
NON_STD_FILTERS = [
6464
'vit_*', 'tnt_*', 'pit_*', 'coat_*', 'cait_*', '*mixer_*', 'gmlp_*', 'resmlp_*', 'twins_*',
65-
'convit_*', 'levit*', 'visformer*', 'deit*', 'xcit_*', 'crossvit_*', 'beit*', 'aimv2*',
65+
'convit_*', 'levit*', 'visformer*', 'deit*', 'xcit_*', 'crossvit_*', 'beit*', 'aimv2*', 'swiftformer_*',
6666
'poolformer_*', 'volo_*', 'sequencer2d_*', 'mvitv2*', 'gcvit*', 'efficientformer*', 'sam_hiera*',
6767
'eva_*', 'flexivit*', 'eva02*', 'samvit_*', 'efficientvit_m*', 'tiny_vit_*', 'hiera_*', 'vitamin*', 'test_vit*',
6868
]
@@ -221,6 +221,7 @@ def test_model_backward(model_name, batch_size):
221221
EARLY_POOL_MODELS = (
222222
timm.models.EfficientVit,
223223
timm.models.EfficientVitLarge,
224+
timm.models.FasterNet,
224225
timm.models.HighPerfGpuNet,
225226
timm.models.GhostNet,
226227
timm.models.MetaNeXt, # InceptionNeXt

timm/layers/attention.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ def __init__(
2828
num_heads: int = 8,
2929
qkv_bias: bool = False,
3030
qk_norm: bool = False,
31+
scale_norm: bool = False,
3132
proj_bias: bool = True,
3233
attn_drop: float = 0.,
3334
proj_drop: float = 0.,
34-
norm_layer: Type[nn.Module] = nn.LayerNorm,
35+
norm_layer: Optional[Type[nn.Module]] = None,
3536
) -> None:
3637
"""Initialize the Attention module.
3738
@@ -47,6 +48,8 @@ def __init__(
4748
"""
4849
super().__init__()
4950
assert dim % num_heads == 0, 'dim should be divisible by num_heads'
51+
if qk_norm or scale_norm:
52+
assert norm_layer is not None, 'norm_layer must be provided if qk_norm or scale_norm is True'
5053
self.num_heads = num_heads
5154
self.head_dim = dim // num_heads
5255
self.scale = self.head_dim ** -0.5
@@ -56,6 +59,7 @@ def __init__(
5659
self.q_norm = norm_layer(self.head_dim) if qk_norm else nn.Identity()
5760
self.k_norm = norm_layer(self.head_dim) if qk_norm else nn.Identity()
5861
self.attn_drop = nn.Dropout(attn_drop)
62+
self.norm = norm_layer(dim) if scale_norm else nn.Identity()
5963
self.proj = nn.Linear(dim, dim, bias=proj_bias)
6064
self.proj_drop = nn.Dropout(proj_drop)
6165

@@ -84,6 +88,7 @@ def forward(
8488
x = attn @ v
8589

8690
x = x.transpose(1, 2).reshape(B, N, C)
91+
x = self.norm(x)
8792
x = self.proj(x)
8893
x = self.proj_drop(x)
8994
return x

timm/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .efficientvit_mit import *
2121
from .efficientvit_msra import *
2222
from .eva import *
23+
from .fasternet import *
2324
from .fastvit import *
2425
from .focalnet import *
2526
from .gcvit import *
@@ -61,7 +62,10 @@
6162
from .selecsls import *
6263
from .senet import *
6364
from .sequencer import *
65+
from .shvit import *
6466
from .sknet import *
67+
from .starnet import *
68+
from .swiftformer import *
6569
from .swin_transformer import *
6670
from .swin_transformer_v2 import *
6771
from .swin_transformer_v2_cr import *

0 commit comments

Comments
 (0)