Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit ad1738e

Browse files
Add ct161 security updates. (#139)
1 parent 583335e commit ad1738e

3 files changed

Lines changed: 540 additions & 97 deletions

File tree

PyTorch/Hugging_Face_pipelines/Benchmarking_on_Optimum-habana_with_fp8/Benchmark.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@
44
import json
55
import os
66
import unittest
7-
7+
import subprocess
88
import requests
99

1010
unittest.TestLoader.sortTestMethodsUsing = None
1111

12-
1312
# unittest.TestLoader.sortTestMethodsUsing = lambda self, a, b: (a < b) - (a > b)
1413
class RunCmd:
15-
def run(self, cmd):
16-
import subprocess
17-
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
18-
(output, err) = p.communicate()
14+
def run(self, cmd, env_vars=None):
15+
# Ensure cmd is a list of arguments
16+
if isinstance(cmd, str):
17+
import shlex
18+
cmd = shlex.split(cmd)
19+
20+
# Print the command and environment variables for debugging
21+
print("Running command:", cmd)
22+
if env_vars:
23+
print("With environment variables:", env_vars)
24+
25+
# Execute the command with the environment variables
26+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, env=env_vars)
27+
output, err = p.communicate()
1928
p_status = p.wait()
20-
# print("Command exit status/return code : ", p_status)
29+
30+
# Return the status and output
2131
return p_status, output
2232

2333
class PerfUtility:
@@ -65,7 +75,8 @@ def model_test(self, data, perf_report):
6575
import shutil
6676
import os
6777
cmd = data["run_cmd"]
68-
status, output = RunCmd().run(cmd)
78+
env = data["env_vars"]
79+
status, output = RunCmd().run(cmd, env)
6980
output = output.decode("utf-8")
7081
print(cmd)
7182
# 0.1.1 copy generated hqt_output(dst) to HQT folder(src)
@@ -81,9 +92,10 @@ def model_test(self, data, perf_report):
8192

8293
# 1.Run the instruction
8394
cmd = data["run_cmd"]
95+
env = data["env_vars"]
8496
#print(cmd)
8597
#return 0
86-
status, output = RunCmd().run(cmd)
98+
status, output = RunCmd().run(cmd, env)
8799
output = output.decode("utf-8")
88100

89101
# 2.Parsing the run log
@@ -277,8 +289,9 @@ def test_0_system(self):
277289
def test_1_perfspect(self):
278290
# PerfSpect Report
279291
if not os.path.exists("./perfspect"):
280-
cmd = 'wget -qO- https://github.com/intel/PerfSpect/releases/latest/download/perfspect.tgz | tar xvz'
281-
status, output = RunCmd().run(cmd)
292+
p = subprocess.Popen('wget -qO- https://github.com/intel/PerfSpect/releases/latest/download/perfspect.tgz | tar xvz', stdout=subprocess.PIPE, shell=True)
293+
output, err = p.communicate()
294+
status = p.wait()
282295
cmd = './perfspect/perfspect report --gaudi --output ' + self.perf_report.result_folder_name
283296
status, output = RunCmd().run(cmd)
284297
import socket

0 commit comments

Comments
 (0)