File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 11import argparse
2+ import hashlib
23import importlib
34import re
45import time
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+
4353def 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
You can’t perform that action at this time.
0 commit comments