SuperAPI AI 工具集

mcore-testing

测试与质量

查看项目

更新于 10-16 09:51

技能介绍

mcore-testing 是 Megatron-LM 的测试体系说明,用于组织、运行与维护其测试套件。

用途:指导测试布局、编写与执行单元测试和功能测试、管理 golden values 以及接入 CI。

主要能力与结构:tests/ 下分为 unit_tests(pytest,1 节点 ×8 GPU,torch.distributed 运行器)、functional_tests(端到端 shell 与训练脚本,用例位于 test_cases/{model}/{test_case}/,含 model_config.yaml 与 golden_values_{env}_{platform}.json)和 test_utils(recipes/h100、recipes/gb200 及 python_scripts 辅助脚本)。CI 由 launch_nemo_run_workload.py 调 nemo-run 启动 DockerExecutor,仓库挂载于 /opt/megatron-lm,训练数据挂载于 /mnt/artifacts;仅 rank 0 和 3 tee 到 stdout,其余写日志并按 GitHub artifact 上传。功能测试由 tests/functional_tests/shell_test_utils/run_ci_test.sh 驱动,仅 rank 0 运行 pytest 校验;瞬态失败最多自动重试 3 次。

使用方式:本地运行单元测试须走 torch.distributed.run,例如 uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q tests/unit_tests,可用 -k 过滤名称、用 -m "not flaky and not flaky_in_dev" 排除易失败用例、--experimental 纳入实验用例;复现 CI 用 tests/unit_tests/run_ci_test.sh。新增单元测试放 tests/unit_tests/<category>/test_<name>.py,使用 conftest.py 的 fixture 与 @pytest.mark.internal、flaky_in_dev、flaky、experimental 等标记。新增功能测试需建 test_cases/<model>/<test_name>/,编写 model_config.yaml 并在 recipes/h100(必要时 gb200)加 recipe,字段含 scope、environment、platform、n_repeat、time_limit;PR 打上 Run functional tests 标签触发,成功后用 python tests/test_utils/python_scripts/download_golden_values.py --source github --pipeline-id <run-id> 下载并提交 golden values。

限制与注意事项:禁用测试不应删除,功能 recipe 将 scope 后缀改为 -broken(如 scope: [mr-github-broken]),单元测试用 pytest marker 跳过;pyproject.toml 的 addopts 含 -s 会致多 rank 输出交错,调试单 rank 时加 --capture=fd;conftest.py 默认在 /opt/data 查找数据并可能下载,非标准容器需手动提供或跳过依赖数据的测试。GB200 任务需维护者权限。