Skip to content

Commit b93a0d7

Browse files
aporialiaofacebook-github-bot
authored andcommitted
Update Planner hash to use SHA256 (#3076)
Summary: Pull Request resolved: #3076 Use consistent hash SHA256 for planner input context, similar to topology implemented D76004583 This is called by manifold_planner - so updated return types to be consistently str Reviewed By: micrain Differential Revision: D76317306 fbshipit-source-id: 7f9d0caebba2dd65e9291a27ff00e955de96c6d1
1 parent 204e8ec commit b93a0d7

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

torchrec/distributed/planner/planners.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# pyre-strict
99

1010
import copy
11+
import hashlib
1112
import logging
1213
import time
1314
from functools import reduce
@@ -279,23 +280,25 @@ def collective_plan(
279280
sharders,
280281
)
281282

282-
def hash_planner_context_inputs(self) -> int:
283+
def hash_planner_context_inputs(self) -> str:
283284
"""
284285
Generates a hash for all planner inputs except for partitioner, proposer, performance model, and stats.
285286
These are all the inputs needed to verify whether a previously generated sharding plan is still valid in a new context.
286287
287288
Returns:
288289
Generates a hash capturing topology, batch size, enumerator, storage reservation, stats and constraints.
289290
"""
290-
return hash(
291-
(
292-
self._topology,
293-
self._batch_size,
294-
self._enumerator,
295-
self._storage_reservation,
296-
frozenset(self._constraints.items()) if self._constraints else None,
297-
)
298-
)
291+
hashable_list = [
292+
self._topology,
293+
self._batch_size,
294+
self._enumerator,
295+
self._storage_reservation,
296+
frozenset(self._constraints.items()) if self._constraints else None,
297+
]
298+
serialized_list = str(hashable_list).encode("utf-8")
299+
hash_object = hashlib.sha256(serialized_list)
300+
hash_digest = hash_object.hexdigest()
301+
return hash_digest
299302

300303
def plan(
301304
self,

0 commit comments

Comments
 (0)