Skip to content

[RFC] Faster load time for large models #2350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
support pytorch<2
  • Loading branch information
gau-nernst committed Mar 30, 2025
commit c3445e9d758ad3c5f3ec66c6b722cf7b78c9d325
3 changes: 2 additions & 1 deletion timm/models/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ def build_model_with_cfg(
model = model_cls(cfg=model_cfg, **kwargs)

# convert meta-device tensors to concrete tensors
device = kwargs.get("device", torch.get_default_device())
default_device = torch.get_default_device() if hasattr(torch, "get_default_device") else "cpu"
device = kwargs.get("device", default_device)
model._apply(lambda t: (torch.empty_like(t, device=device) if t.is_meta else t))

model.pretrained_cfg = pretrained_cfg
Expand Down