Skip to content

Commit

Permalink
Summary test results to csv
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoguochun1995 committed Sep 24, 2024
1 parent de26274 commit 84802cc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/runs_on_ascend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
echo "start to test"
bash ci/run_op_tools_test_cases.sh
Test_with_pytorch_test_case:
Test_use_pytorch_test_case:
name: run pytorch test case on ascend
runs-on: tps-ascend-ci-910b
needs: [Build]
Expand All @@ -57,6 +57,7 @@ jobs:
run: |
set -ex
source /mnt/cache/share/platform/cienv/ditorch_env
export PYTHONPATH=${PYTHONPATH}:$PWD
cd ${DEEPLINK_PATH}/${GITHUB_RUN_NUMBER} && rm -rf ${GITHUB_JOB} && cp -R Build ${GITHUB_JOB} && cd ${GITHUB_JOB}
echo "start to test"
bash ci/run_pytorch_test_cases.sh 2>&1
1 change: 1 addition & 0 deletions .github/workflows/runs_on_camb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ jobs:
cd ${DEEPLINK_PATH}/${GITHUB_RUN_NUMBER} && rm -rf ${GITHUB_JOB} && cp -R Build ${GITHUB_JOB} && cd ${GITHUB_JOB}
echo "start to test"
source /mnt/cache/share/platform/env/ditorch_env
export PYTHONPATH=${PYTHONPATH}:$PWD
srun -p camb_mlu370_m8 -n 1 --gres=mlu:1 bash ci/run_pytorch_test_cases.sh
12 changes: 12 additions & 0 deletions .github/workflows/runs_on_nv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@ jobs:
cd ${DEEPLINK_PATH}/${GITHUB_RUN_NUMBER} && rm -rf ${GITHUB_JOB} && cp -R Build ${GITHUB_JOB} && cd ${GITHUB_JOB}
echo "start to test"
srun --job-name=${GITHUB_JOB} bash -c "source /mnt/cache/share/platform/env/ditorch_env && cd ${DEEPLINK_PATH}/${GITHUB_RUN_NUMBER}/${GITHUB_JOB} && bash ci/run_op_tools_test_cases.sh"
TestTorch:
name: run pytorch test case on nv
runs-on: tps-sco-ci
needs: [Build]
steps:
- name: test
run: |
set -ex
cd ${DEEPLINK_PATH}/${GITHUB_RUN_NUMBER} && rm -rf ${GITHUB_JOB} && cp -R Build ${GITHUB_JOB} && cd ${GITHUB_JOB}
echo "start to test"
srun --job-name=${GITHUB_JOB} bash -c "source /mnt/cache/share/platform/env/ditorch_env && export PYTHONPATH=${PYTHONPATH}:$PWD && cd ${DEEPLINK_PATH}/${GITHUB_RUN_NUMBER}/${GITHUB_JOB} && bash ci/run_pytorch_test_cases.sh"
24 changes: 3 additions & 21 deletions ditorch/test/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
import json
import os
from multiprocessing import Process
import atexit
from prettytable import PrettyTable

gloabl_test_result = []


class CommandRunner:
Expand All @@ -22,6 +18,8 @@ def __init__(self, commands, max_workers=4, output_dir="pytorch_test_result", cw
self.output_dir = output_dir
self.cwd = cwd
os.makedirs(f"{self.output_dir}", exist_ok=True)
os.makedirs(f"{self.output_dir}/passed", exist_ok=True)
os.makedirs(f"{self.output_dir}/failed", exist_ok=True)

def _run_command(self, command_id, command):
"""运行命令并将结果写入独立的 JSON 文件中"""
Expand All @@ -37,13 +35,11 @@ def _run_command(self, command_id, command):
result_data["returncode"] = result.returncode

# 将结果写入 JSON 文件
output_file = f"{self.output_dir}/result_{command_id}.json"
output_file = f'{self.output_dir}/{"passed" if result.returncode == 0 else "failed"}/result_{command_id}.json'
with open(output_file, "w") as f:
json.dump(result_data, f, indent=4)

print(f'\"{command}\" exit {result.returncode} {output_file}')
simple_result = {"test_case_id": command_id, "exit_code": result.returncode}
gloabl_test_result.append(simple_result)

def run(self):
processes = []
Expand Down Expand Up @@ -78,17 +74,3 @@ def run(self):
runner.run()

print("所有命令已完成,结果已保存为 JSON 格式到独立文件中")


def dump_all_test_result():
table = PrettyTable()
table.field_names = ["test_case_id", "exit_code"]
for result in gloabl_test_result:
table.add_row([result["test_case_id"], result["exit_code"]])
print(table)

with open("pytorch_test_result/run_pytorch_test_cases_results.csv", "w") as f:
f.write(table.get_csv_string())


atexit.register(dump_all_test_result)
26 changes: 26 additions & 0 deletions ditorch/test/summary_test_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import glob
import json
from prettytable import PrettyTable


def summary_test_results(test_result_dir):
test_result_files = glob.glob(test_result_dir + '/result_test_*.json')
table = PrettyTable()
table.field_names = ["test_case_id", "exit_code"]
for file_name in test_result_files:
try:
with open(file_name, 'r') as f:
test_result = json.load(f)
table.add_row([test_result["command_id"], test_result["returncode"]])
except Exception as e:
print(f"Error reading file {file_name}: {e}")
print(table)
if table.rowcount > 0:
summary_file = test_result_dir + '/summary_test_result.csv'
with open(summary_file, 'w') as f:
f.write(table.get_string())
print(f"Summary test results saved to {summary_file}")


if __name__ == "__main__":
summary_test_results('pytorch_test_result')
4 changes: 3 additions & 1 deletion ditorch/test/test_torch_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import shutil
from ditorch.test.command_runner import CommandRunner
from ditorch.test.summary_test_results import summary_test_results


def copy_add_ditorch_import_to_pytorch_test_file(file_name, pytorch_dir, dest_dir):
Expand Down Expand Up @@ -59,7 +60,7 @@ def main():
return -1
pytorch_test_temp = "pytorch_test_temp"
shutil.rmtree(pytorch_test_temp, ignore_errors=True)
shutil.copytree(pytorch_dir, pytorch_test_temp)
shutil.copytree(pytorch_dir, pytorch_test_temp, dirs_exist_ok=True)

run_command_in_sub_process(f"python ditorch/test/discover_pytorch_test_case.py {pytorch_test_temp}/test pytorch_test_result")
with open("pytorch_test_result/all_test_cases.json", "r") as f:
Expand Down Expand Up @@ -88,6 +89,7 @@ def main():

testcase_runner = CommandRunner(commands_list, max_workers=64, cwd="pytorch_test_temp/test")
testcase_runner.run()
summary_test_results("pytorch_test_result")


if __name__ == "__main__":
Expand Down

0 comments on commit 84802cc

Please sign in to comment.