From 8a6cc06af208d11309faab2420d2fb116bb17891 Mon Sep 17 00:00:00 2001 From: Ross Wightman Date: Wed, 16 Oct 2024 17:22:21 -0700 Subject: [PATCH] Switch timm import fallback order to favour new paths, avoid new warnings --- src/open_clip/timm_model.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/open_clip/timm_model.py b/src/open_clip/timm_model.py index 5ddb9a76b..975e37a9d 100644 --- a/src/open_clip/timm_model.py +++ b/src/open_clip/timm_model.py @@ -10,15 +10,16 @@ try: import timm - from timm.models.layers import Mlp, to_2tuple try: - # old timm imports < 0.8.1 - from timm.models.layers.attention_pool2d import RotAttentionPool2d - from timm.models.layers.attention_pool2d import AttentionPool2d as AbsAttentionPool2d - except ImportError: # new timm imports >= 0.8.1 from timm.layers import RotAttentionPool2d from timm.layers import AttentionPool2d as AbsAttentionPool2d + from timm.layers import Mlp, to_2tuple + except ImportError as e: + # fallback, try old timm imports < 0.8.1 + from timm.models.layers.attention_pool2d import RotAttentionPool2d + from timm.models.layers.attention_pool2d import AttentionPool2d as AbsAttentionPool2d + from timm.models.layers import Mlp, to_2tuple except ImportError: timm = None