Skip to content

Commit 70724bd

Browse files
janselpytorchmergebot
authored andcommitted
Bugfix for nondeterminstic torch_key (#128111)
Pull Request resolved: #128111 Approved by: https://github.com/oulgen
1 parent 00c6ca4 commit 70724bd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

torch/_inductor/codecache.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,13 @@ def get_code_hash(roots):
565565
module = spec.origin
566566
assert module is not None
567567
with open(module, "rb") as f:
568-
contents[module] = f.read()
569-
570-
return hashlib.sha256(pickle.dumps(contents)).digest()
568+
contents[spec.name] = f.read()
569+
hasher = hashlib.sha256()
570+
# Iterate over dict in sorted order since iter_modules may not be deterministic
571+
for name, value in sorted(contents.items()):
572+
hasher.update(name.encode("utf-8"))
573+
hasher.update(value)
574+
return hasher.digest()
571575

572576

573577
@functools.lru_cache(None)

0 commit comments

Comments
 (0)