CANN/torchtitan-npu测试设计指南
Test Design【免费下载链接】torchtitan-npuAscend Extension for torchtitan项目地址: https://gitcode.com/cann/torchtitan-npuPurposeThis document explains the current test layering intorchtitan-npuand helps contributors decide where a new test should live.The goals are simple:Keep unit tests fast and hardware-independentKeep smoke tests focused on real execution pathsMake test placement easy to understand for new contributorsTest LayersLayerDirectoryNPU RequiredUse CasesFunction UTtests/unit_tests/functions/NoPure functions, config parsing, helpers, validation logicModule UTtests/unit_tests/modules/NoWrappers, checkpoint logic, distributed initialization logicConverter UTtests/unit_tests/converters/NoConverter registration, replacement, and mapping logicPatch UTtests/unit_tests/patches/NoPatch activation, wiring, and small patch behaviorFeature Smoketests/smoke_tests/features/YesReal NPU feature paths, fused ops, wrapper execution chainsModel Parallel Smoketests/smoke_tests/model_parallel/YesCP/TP/EP behavior, mesh setup, DTensor, model-parallel scenariosHow to Choose a LayerIf the test can run without NPU, prefer UTIf the value of the test depends on real NPU execution, use smokeIf the change is about mesh, shard, placement, or DTensor behavior, use model-parallel smokeIf the change is about a small helper or pure transformation, keep it in UTWhat Smoke Means HereIn this repository, smoke tests are not import checks. They are integration-style checks over real execution paths.build.sh -sruns two parts by default:Core smoke: minimal end-to-end training path validationExtended smoke: local feature and model-parallel smoke suitesUpstream smoke is kept as a separate targeted entry. It is heavier, takes longer, and may be affected by low-level hardware issues, so it is not part of the default smoke path.Rules for Adding TestsPrefer real behavior validation over import-only checks.Do not add placeholder tests that only make the suite look larger.Keep UT fully hardware-independent.Use smoke only when the behavior matters on real NPU.If a test depends on external artifacts or a special runtime setup, state that clearly.Readability GuidelinesUse test names that describe behavior and expected outcome directlyKeep setup short and easy to scanUse blank lines to separate Arrange, Act, and Assert when it helps readabilityLet assertions show the exact behavior being protectedAvoid:Long per-test docstringsComments that just restate the test nameDecorative section comments with no real meaningBuild Entry Pointsbuild.sh -u: run all unit testsbuild.sh -s: run all smoke testsUseful variants:ONLY_CORE_SMOKEtrue build.sh -sONLY_EXTENDED_SMOKEtrue build.sh -sONLY_UPSTREAM_SMOKEtrue build.sh -sPre-Submission ChecklistIs the test in the right directory?Does it validate real behavior instead of a placeholder path?Can a new contributor understand the test quickly?If the change affects test execution or test usage, did you update the docs?【免费下载链接】torchtitan-npuAscend Extension for torchtitan项目地址: https://gitcode.com/cann/torchtitan-npu创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考