Skip to content

Commit

Permalink
Fix torch.load (torch.utils.benchmark) after pytorch#137602 (pytorch#…
Browse files Browse the repository at this point in the history
…139810)

After pytorch#137602, the default `weights_only` has been set to True.  This test is failing in trunk slow jobs atm

benchmark_utils/test_benchmark_utils.py::TestBenchmarkUtils::test_collect_callgrind [GH job link](https://github.com/pytorch/pytorch/actions/runs/11672436111/job/32502454946) [HUD commit link](https://hud.pytorch.org/pytorch/pytorch/commit/1aa71be56c39908893273bd9558b127159e1ef3a)
Pull Request resolved: pytorch#139810
Approved by: https://github.com/kit1980
  • Loading branch information
huydhn authored and atalman committed Nov 11, 2024
1 parent 955a1d1 commit 4162540
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ def construct(self) -> str:

elif wrapped_value.serialization == Serialization.TORCH:
path = os.path.join(self._data_dir, f"{name}.pt")
load_lines.append(f"{name} = torch.load({repr(path)})")
# TODO: Figure out if we can use torch.serialization.add_safe_globals here
# Using weights_only=False after the change in
# https://dev-discuss.pytorch.org/t/bc-breaking-change-torch-load-is-being-flipped-to-use-weights-only-true-by-default-in-the-nightlies-after-137602/2573
load_lines.append(f"{name} = torch.load({repr(path)}, weights_only=False)")
torch.save(wrapped_value.value, path)

elif wrapped_value.serialization == Serialization.TORCH_JIT:
Expand Down

0 comments on commit 4162540

Please sign in to comment.