Skip to content
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

fix: Set torch.load weights_only to True for security #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/gazesam/load_demo_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def load_depth_model(mode, precision):

encoder = "vitb" # or 'vitb', 'vits'
model = DepthAnything(model_configs[encoder])
model.load_state_dict(torch.load(f"{PYTORCH_MODEL_DIR}/depth_anything_{encoder}14.pth"))
model.load_state_dict(torch.load(f"{PYTORCH_MODEL_DIR}/depth_anything_{encoder}14.pth", weights_only=True))
model = model.eval().cuda()
return model

Expand Down
2 changes: 1 addition & 1 deletion efficientvit/apps/trainer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def sync_model(self):
print("Sync model")
self.save_model(model_name="sync.pt")
dist_barrier()
checkpoint = torch.load(os.path.join(self.checkpoint_path, "sync.pt"), map_location="cpu")
checkpoint = torch.load(os.path.join(self.checkpoint_path, "sync.pt"), map_location="cpu", weights_only=True)
dist_barrier()
if is_master():
os.remove(os.path.join(self.checkpoint_path, "sync.pt"))
Expand Down
2 changes: 1 addition & 1 deletion efficientvit/models/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def build_kwargs_from_config(config: dict, target_func: callable) -> dict[str, a

def load_state_dict_from_file(file: str, only_state_dict=True) -> dict[str, torch.Tensor]:
file = os.path.realpath(os.path.expanduser(file))
checkpoint = torch.load(file, map_location="cpu")
checkpoint = torch.load(file, map_location="cpu", weights_only=True)
if only_state_dict and "state_dict" in checkpoint:
checkpoint = checkpoint["state_dict"]
return checkpoint