Skip to content

Commit 5e9ff57

Browse files
committed
Adding pos embed resize fns to FX autowrap exceptions
1 parent f0fb471 commit 5e9ff57

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

timm/layers/pos_embed.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
def resample_abs_pos_embed(
18-
posemb,
18+
posemb: torch.Tensor,
1919
new_size: List[int],
2020
old_size: Optional[List[int]] = None,
2121
num_prefix_tokens: int = 1,
@@ -58,7 +58,7 @@ def resample_abs_pos_embed(
5858

5959

6060
def resample_abs_pos_embed_nhwc(
61-
posemb,
61+
posemb: torch.Tensor,
6262
new_size: List[int],
6363
interpolation: str = 'bicubic',
6464
antialias: bool = True,
@@ -69,7 +69,6 @@ def resample_abs_pos_embed_nhwc(
6969

7070
orig_dtype = posemb.dtype
7171
posemb = posemb.float()
72-
# do the interpolation
7372
posemb = posemb.reshape(1, posemb.shape[-3], posemb.shape[-2], posemb.shape[-1]).permute(0, 3, 1, 2)
7473
posemb = F.interpolate(posemb, size=new_size, mode=interpolation, antialias=antialias)
7574
posemb = posemb.permute(0, 2, 3, 1).to(orig_dtype)

timm/models/_features_fx.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
# Layers we went to treat as leaf modules
2020
from timm.layers import Conv2dSame, ScaledStdConv2dSame, CondConv2d, StdConv2dSame, Format
21+
from timm.layers import resample_abs_pos_embed, resample_abs_pos_embed_nhwc
2122
from timm.layers.non_local_attn import BilinearAttnTransform
2223
from timm.layers.pool2d_same import MaxPool2dSame, AvgPool2dSame
2324
from timm.layers.norm_act import (
@@ -75,7 +76,10 @@ def get_notrace_modules():
7576

7677

7778
# Functions we want to autowrap (treat them as leaves)
78-
_autowrap_functions = set()
79+
_autowrap_functions = {
80+
resample_abs_pos_embed,
81+
resample_abs_pos_embed_nhwc,
82+
}
7983

8084

8185
def register_notrace_function(func: Callable):

0 commit comments

Comments
 (0)