Skip to content

Commit fcdb200

Browse files
committed
handle BC
1 parent b95e335 commit fcdb200

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

timm/models/_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ def build_model_with_cfg(
413413
feature_cfg['feature_cls'] = kwargs.pop('feature_cls')
414414

415415
# Instantiate the model
416-
with torch.device("meta") if pretrained else nullcontext():
416+
meta_device = torch.device("meta")
417+
with meta_device if hasattr(meta_device, "__enter__") and pretrained else nullcontext():
417418
if model_cfg is None:
418419
model = model_cls(**kwargs)
419420
else:

0 commit comments

Comments
 (0)