SuperAPI AI 工具集

testsystem

测试与质量

查看项目

更新于 10-16 09:46

技能介绍

用途:面向 Megatron-LM 的测试系统与 CI 流程说明,指导在其仓库中组织测试、编写用例、触发 CI 并排查失败。

测试布局:tests/unit_tests/ 使用 pytest,运行于 1 节点 8 GPU 的 torch.distributed runner;tests/functional_tests/ 为端到端 shell 加训练脚本,按 test_cases/{model}/{test_case}/ 存放 model_config.yaml 与 golden_values_{env}_{platform}.json;tests/test_utils/ 含 recipes(h100、gb200 的 YAML)与 python_scripts 辅助工具。

执行方式:GitHub Actions runner 调用 launch_nemo_run_workload.py,经 nemo-run 启动 DockerExecutor 容器,仓库挂载于 /opt/megatron-lm,数据挂载于 /mnt/artifacts。单元测试经 torch.distributed.run 派发,rank 0 与 3 输出到 stdout,其余仅写日志,日志位于 {assets_dir}/logs/1/ 并作为 artifact 上传。功能测试由 run_ci_test.sh 驱动,仅 rank 0 运行 pytest 校验。启动脚本对 NCCL 超时、ECC 错误、段错误、HuggingFace 连接等已知瞬时故障最多自动重试 3 次。

Recipe YAML:位于 tests/test_utils/recipes/,由 recipe_parser.py 解析,将 cartesian products 块展开为各 workload spec,包含 name、model、build、nodes、gpus、n_repeat、platforms、time_limit、script_setup、script 等字段,并使用 {assets_dir}、{artifacts_dir}、{test_case}、{environment}、{platforms}、{n_repeat} 等占位符。

CI 范围标签:流水线依据 PR 标签决定范围、n_repeat 与镜像。合并组自动为 mr-github、n_repeat=1、非轻量;标签 Run tests 为轻量、训练 4 步、不比对 golden value;Run functional tests 训练 100 步并比对;无标签则用 mr-github-slim 子集。container::lts 标签可切换 LTS 基础镜像,Run MBridge tests 额外触发 MBridge L1 测试。

临时禁用测试:在 recipe YAML 中给 scope 值加 -broken 后缀(如 mr-github-broken),不要删除条目。

新增测试:单元测试放在 tests/unit_tests/<category>/test_<name>.py,使用 conftest.py 中的 fixture,可用 @pytest.mark.internal、flaky、experimental 标记;功能测试放在 tests/functional_tests/test_cases/<model>/<test_name>/,写 model_config.yaml 并在 recipes/h100/(如需 gb200/)添加 recipe,推送后加 Run functional tests 标签,成功后用 download_golden_values.py 下载并提交 golden values。

内部 CI:通过 tools/trigger_internal_ci.py 触发,使用前需添加 GitLab 远端并设置 GITLAB_TOKEN,脚本以 pull-request/<branch> 强推分支并输出流水线 URL。主工作流为 .github/workflows/cicd-main.yml,触发条件包括 pull-request/[0-9]+、deploy-release/*、合并组、每日定时与手动派发。

失败排查:CI 分支遵循 pull-request/<number>,可用 gh pr view/diff 查看 PR 元数据与改动,用 gh run list/view 查看运行;rank 全量日志不在 runner stdout,需下载名为 logs-<test_case>-<run_id>-<uuid> 的 artifact,日志文件可能超过 10000 行,应先查看行数再按约 200 行分段读取。常见根因包括 linting 失败、容器构建失败、单元/功能测试失败、golden value 不匹配与 flaky 测试。限制:资料未提供具体价格、平台支持范围或性能数据。