BingBertSquad_test_common.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (c) Microsoft Corporation.
  2. # SPDX-License-Identifier: Apache-2.0
  3. # DeepSpeed Team
  4. import unittest
  5. import subprocess
  6. import os
  7. import time
  8. class BaseTestCase(unittest.TestCase):
  9. def __init__(self, methodName="DeepSpeed performance test"):
  10. super(BaseTestCase, self).__init__(methodName)
  11. self.test_dir = "./test"
  12. self.baseline_dir = "./baseline"
  13. self.timestr = time.strftime("%Y%m%d-%H%M%S")
  14. def gen_output_name(self, test_config, prefix):
  15. other_args = test_config["other_args"] if "other_args" in test_config else ""
  16. zero_args = "_zero" if "zero" in test_config and test_config["zero"] else ""
  17. other_args = other_args.strip(' -\\').replace(" ", "").replace("\"", "")
  18. if other_args:
  19. other_args = "_" + other_args
  20. if test_config["deepspeed"]:
  21. file_name = "_gpu{0}_{1}_ds{2}-{3}.log".format(test_config["gpus"], other_args, zero_args, self.timestr)
  22. save_dir = self.test_dir
  23. else:
  24. file_name = "_gpu{0}_{1}.log".format(test_config["gpus"], other_args)
  25. save_dir = self.baseline_dir
  26. return os.path.join(save_dir, prefix + file_name)
  27. def ensure_directory_exists(self, filename):
  28. dirname = os.path.dirname(filename)
  29. if not os.path.exists(dirname):
  30. os.makedirs(dirname)
  31. def clean_test_env(self):
  32. cmd = "dlts_ssh pkill -9 -f /usr/bin/python"
  33. print(cmd)
  34. subprocess.run(cmd, shell=True, check=False, executable='/bin/bash')
  35. time.sleep(20)
  36. def run_BingBertSquad_test(self, test_config, output):
  37. ds_flag = " -d --deepspeed_config " + test_config["json"] if test_config["deepspeed"] else " "
  38. other_args = " " + test_config["other_args"] if "other_args" in test_config else " "
  39. cmd = "./run_BingBertSquad_sanity.sh -e 1 -g {0} {1} {2}".format(test_config["gpus"], other_args, ds_flag)
  40. self.ensure_directory_exists(output)
  41. with open(output, "w") as f:
  42. print(cmd)
  43. subprocess.run(cmd, shell=True, check=False, executable='/bin/bash', stdout=f, stderr=f)