@@ -76,51 +76,68 @@ def main():
7676 output_dir = os .path .join (args .output_dir , "TEST01" )
7777 unixmode = ""
7878 if args .unixmode :
79- unixmode = " --unixmode"
80- for binary in ["wc" , "md5sum" , "grep" , "awk" , "sed" , "head" , "tail" ]:
79+ if os .name != "posix" :
80+ print (
81+ "Warning: --unixmode not supported on this OS. Using Python fallback..." )
82+ unixmode = ""
83+ else :
84+ unixmode = " --unixmode"
8185 missing_binary = False
82- if shutil .which (binary ) is None :
83- print (
84- "Error: This script requires the {:} commandline utility" .format (
85- binary
86+ for binary in ["wc" , "md5sum" , "grep" ,
87+ "awk" , "sed" , "head" , "tail" ]:
88+ if shutil .which (binary ) is None :
89+ print (
90+ "Error: This script requires the {:} commandline utility" .format (
91+ binary
92+ )
8693 )
87- )
88- missing_binary = True
89- if missing_binary :
90- exit ()
94+ missing_binary = True
95+ if missing_binary :
96+ exit ()
9197
9298 dtype = args .dtype
9399
94100 verify_accuracy_binary = os .path .join (
95101 os .path .dirname (__file__ ), "verify_accuracy.py"
96102 )
103+
104+ unixmode_str = unixmode if unixmode == "" else unixmode + " "
105+
97106 # run verify accuracy
98107 verify_accuracy_command = (
99- "python3 "
108+ sys . executable + " "
100109 + verify_accuracy_binary
101110 + " --dtype "
102111 + args .dtype
103- + unixmode
112+ + unixmode_str
104113 + " -r "
105- + results_dir
106- + "/accuracy/mlperf_log_accuracy.json"
114+ + os .path .join (results_dir , "accuracy" , "mlperf_log_accuracy.json" )
107115 + " -t "
108- + compliance_dir
109- + "/mlperf_log_accuracy.json | tee verify_accuracy.txt"
116+ + os .path .join (compliance_dir , "mlperf_log_accuracy.json" )
110117 )
111118 try :
112- os .system (verify_accuracy_command )
119+ with open ("verify_accuracy.txt" , "w" ) as f :
120+ process = subprocess .Popen (
121+ verify_accuracy_command ,
122+ stdout = subprocess .PIPE ,
123+ stderr = subprocess .STDOUT ,
124+ shell = True ,
125+ text = True
126+ )
127+ # Write output to both console and file
128+ for line in process .stdout :
129+ print (line , end = "" )
130+ f .write (line )
131+ process .wait ()
113132 except Exception :
114133 print (
115134 "Exception occurred trying to execute:\n " +
116135 verify_accuracy_command )
117136 # check if verify accuracy script passes
118137
119- accuracy_pass_command = "grep PASS verify_accuracy.txt"
120138 try :
121- accuracy_pass = "TEST PASS" in subprocess .check_output (
122- accuracy_pass_command , shell = True
123- ).decode ("utf-8" )
139+ with open ("verify_accuracy.txt" , "r" ) as file :
140+ accuracy_pass = "TEST PASS" in file .read ()
124141 except Exception :
125142 accuracy_pass = False
126143
@@ -129,28 +146,38 @@ def main():
129146 os .path .dirname (__file__ ), "verify_performance.py"
130147 )
131148 verify_performance_command = (
132- "python3 "
149+ sys . executable + " "
133150 + verify_performance_binary
134- + " -r "
135- + results_dir
136- + "/performance/run_1/mlperf_log_detail.txt"
137- + " -t "
138- + compliance_dir
139- + "/mlperf_log_detail.txt | tee verify_performance.txt"
151+ + " -r"
152+ + os .path .join (results_dir , "performance" ,
153+ "run_1" , "mlperf_log_detail.txt" )
154+ + " -t"
155+ + os .path .join (compliance_dir , "mlperf_log_detail.txt" )
140156 )
157+
141158 try :
142- os .system (verify_performance_command )
159+ with open ("verify_performance.txt" , "w" ) as f :
160+ process = subprocess .Popen (
161+ verify_performance_command ,
162+ stdout = subprocess .PIPE ,
163+ stderr = subprocess .STDOUT ,
164+ text = True ,
165+ shell = True ,
166+ )
167+ # Write output to both console and file
168+ for line in process .stdout :
169+ print (line , end = "" )
170+ f .write (line )
171+ process .wait ()
143172 except Exception :
144173 print (
145174 "Exception occurred trying to execute:\n " +
146175 verify_performance_command )
147176
148177 # check if verify performance script passes
149- performance_pass_command = "grep PASS verify_performance.txt"
150178 try :
151- performance_pass = "TEST PASS" in subprocess .check_output (
152- performance_pass_command , shell = True
153- ).decode ("utf-8" )
179+ with open ("verify_performance.txt" , "r" ) as file :
180+ performance_pass = "TEST PASS" in file .read ()
154181 except Exception :
155182 performance_pass = False
156183
0 commit comments