Skip to content

Commit 3577326

Browse files
committed
[Backend Tester] Seed based on test name
ghstack-source-id: 10756ac ghstack-comment-id: 3177836622 Pull-Request: #13313
1 parent 8e27463 commit 3577326

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

backends/test/suite/runner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import hashlib
23
import importlib
34
import re
45
import time
@@ -40,6 +41,15 @@
4041
}
4142

4243

44+
def _get_test_seed(test_base_name: str) -> int:
45+
# Set the seed based on the test base name to give consistent inputs between runs and backends.
46+
# Having a stable hash between runs and across machines is a plus (builtin python hash is not).
47+
# Using MD5 here because it's fast and we don't actually care about cryptographic properties.
48+
hasher = hashlib.md5()
49+
data = test_base_name.encode("utf-8")
50+
hasher.update(data)
51+
return int.from_bytes(hasher.hexdigest(), "little")
52+
4353
def run_test( # noqa: C901
4454
model: torch.nn.Module,
4555
inputs: Any,
@@ -59,6 +69,8 @@ def run_test( # noqa: C901
5969
error_statistics: list[ErrorStatistics] = []
6070
extra_stats = {}
6171

72+
torch.manual_seed(_get_test_seed(test_base_name))
73+
6274
# Helper method to construct the summary.
6375
def build_result(
6476
result: TestResult, error: Exception | None = None

0 commit comments

Comments
 (0)