File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1
1
import argparse
2
+ import hashlib
2
3
import importlib
3
4
import re
4
5
import time
40
41
}
41
42
42
43
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
+ # Torch doesn't like very long seeds.
52
+ return int .from_bytes (hasher .digest (), "little" ) % 100_000_000
53
+
43
54
def run_test ( # noqa: C901
44
55
model : torch .nn .Module ,
45
56
inputs : Any ,
@@ -59,6 +70,8 @@ def run_test( # noqa: C901
59
70
error_statistics : list [ErrorStatistics ] = []
60
71
extra_stats = {}
61
72
73
+ torch .manual_seed (_get_test_seed (test_base_name ))
74
+
62
75
# Helper method to construct the summary.
63
76
def build_result (
64
77
result : TestResult , error : Exception | None = None
You can’t perform that action at this time.
0 commit comments