|
| 1 | +############################################################################### |
| 2 | +# Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved. |
| 3 | +# |
| 4 | +# See LICENSE for license information. |
| 5 | +################################################################################# |
| 6 | + |
| 7 | + |
| 8 | +import os |
| 9 | +import subprocess |
| 10 | +import sys |
| 11 | +import time |
| 12 | +import unittest |
| 13 | + |
| 14 | +from primus.core.utils import logger |
| 15 | +from tests.utils import PrimusUT |
| 16 | + |
| 17 | + |
| 18 | +class TestMegatronTrainer(PrimusUT): |
| 19 | + def __init__(self, *args, **kwargs): |
| 20 | + super().__init__(*args, **kwargs) |
| 21 | + |
| 22 | + def setUp(self): |
| 23 | + pass |
| 24 | + |
| 25 | + def tearDown(self): |
| 26 | + pass |
| 27 | + |
| 28 | + def test_pretrain(self): |
| 29 | + shell_entry = "examples/megatron/run_pretrain.sh" |
| 30 | + do_print_at_runtime = False |
| 31 | + run_stdout = subprocess.PIPE if not do_print_at_runtime else sys.stdout |
| 32 | + run_stderr = subprocess.PIPE if not do_print_at_runtime else sys.stderr |
| 33 | + try: |
| 34 | + logger.info(f"Begin run {shell_entry}...") |
| 35 | + start = time.time() |
| 36 | + result = subprocess.run( |
| 37 | + ["bash", f"{shell_entry}"], |
| 38 | + check=True, |
| 39 | + stdout=run_stdout, |
| 40 | + stderr=run_stderr, |
| 41 | + text=True, |
| 42 | + ) |
| 43 | + logger.info(f"End run {shell_entry}, time={time.time()-start:.3f} s") |
| 44 | + if not do_print_at_runtime: |
| 45 | + ut_log_path = os.environ.get("UT_LOG_PATH", "ut_out") |
| 46 | + logger.info(f"Training log path: {ut_log_path}/logs/UT-{self.__class__.__name__}") |
| 47 | + |
| 48 | + logger.debug(f"Standard Output:\n {result.stdout}") |
| 49 | + logger.debug(f"Standard Error:\n {result.stderr}") |
| 50 | + except subprocess.CalledProcessError as e: |
| 51 | + os.environ["SCRIPT_ERROR"] = e.stderr.strip() |
| 52 | + assert False, f"Shell script failed: {os.environ['SCRIPT_ERROR']}" |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + unittest.main(buffer=False) |
0 commit comments