Skip to content

Commit fd962c4

Browse files
committed
Native SiLU (Swish) op doesn't export to ONNX
1 parent 27bbc70 commit fd962c4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

timm/models/layers/create_act.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ def get_act_fn(name='relu'):
9898
# custom autograd, then fallback
9999
if name in _ACT_FN_ME:
100100
return _ACT_FN_ME[name]
101-
if not is_no_jit():
101+
if is_exportable() and name in ('silu', 'swish'):
102+
# FIXME PyTorch SiLU doesn't ONNX export, this is a temp hack
103+
return swish
104+
if not (is_no_jit() or is_exportable()):
102105
if name in _ACT_FN_JIT:
103106
return _ACT_FN_JIT[name]
104107
return _ACT_FN_DEFAULT[name]
@@ -114,7 +117,10 @@ def get_act_layer(name='relu'):
114117
if not (is_no_jit() or is_exportable() or is_scriptable()):
115118
if name in _ACT_LAYER_ME:
116119
return _ACT_LAYER_ME[name]
117-
if not is_no_jit():
120+
if is_exportable() and name in ('silu', 'swish'):
121+
# FIXME PyTorch SiLU doesn't ONNX export, this is a temp hack
122+
return Swish
123+
if not (is_no_jit() or is_exportable()):
118124
if name in _ACT_LAYER_JIT:
119125
return _ACT_LAYER_JIT[name]
120126
return _ACT_LAYER_DEFAULT[name]

0 commit comments

Comments
 (0)