tinygrad 本地怎么运行 backend、null、unit 三组测试套件

发布时间:2026/9/12 2:52:54
tinygrad 本地怎么运行 backend、null、unit 三组测试套件 tinygrad 本地怎么运行 backend、null、unit 三组测试套件【免费下载链接】tinygradYou like pytorch? You like micrograd? You love tinygrad! ❤️项目地址: https://gitcode.com/GitHub_Trending/tiny/tinygrad你在 tinygrad 仓库里改了代码想按 CI 的方式在本地把三组核心测试跑一遍验证改动。test/README 定义了 CI 实际运行的三组测试backend在各类后端上运行的测试、null不需要任何后端的测试、unitCI 中只在单个后端上运行的测试。这篇文章基于 README.md 的 Running tests 一节和 CI 工作流 .github/workflows/test.yml 中的testlinux、nulltest、unittest三个 job给出在本地依次运行这三组测试的命令、依赖安装方式和结果判断方式。准备条件tinygrad 推荐从源码安装见 README.md 的 Installation 一节要求 Python 3.11 及以上pyproject.toml 中requires-python 3.11git clone https://github.com/tinygrad/tinygrad.git cd tinygrad python3 -m pip install -e .测试依赖按 README 的说法用 extra 安装python3 -m pip install -e .[testing] # install extra deps for testing.[testing]包含 README 中运行测试一节要求的全部测试依赖。如果你只想按 CI 中nulltest/unittestjob 的最小依赖来装对应 pyproject.toml 里的testing_unit不含 pillow、onnx 等模型类依赖可以改装python3 -m pip install -e .[testing_unit]-n参数依赖pytest-xdist三个 extra 都包含它CI 命令统一使用-nauto并行执行。运行 null 组不依赖任何后端nulltestjob 在 test.yml 中的核心命令是SPEC2 DEVNULL python -m pytest -nauto test/null/ --durations20说明DEVNULL把设备指定为 NULL 后端test/README对 null 组的定义就是tests that dont require any backendSPEC2是 CI 该 job 实际使用的环境变量本地保持与 CI 一致--durations20在结束后输出最慢的 20 个测试方便你判断耗时。该 job 还有几条针对单个测试的定向命令适合在整组失败时定位DEVNULL python3 -m unittest test.backend.test_multitensor.TestMultiTensor.test_data_parallel_resnet_train_step DEVNULL VIZ1 python3 -m pytest -nauto test/null/test_viz.py运行 unit 组在单个后端上跑unittestjob 的核心命令是DEVCPU python -m pytest -nauto test/unit/ --durations20该 job 执行前还有一个前置检查确认默认设备是 CPUpython -c from tinygrad import Device; assert Device.DEFAULT CPU, Device.DEFAULT如果你的机器没有 GPU 或不想跑 GPU 路径DEVCPU就是 CI 的选择。CI 还额外跑了一条 GC 测试python test/external/external_uop_gc.py属于 unit job 的附加步骤本地可以按需执行。运行 backend 组选定后端跑一遍backend组的定义是tests that run on each backend所以本地运行时你需要通过DEV环境变量指定一个后端。CI 的testlinuxjob 对每个后端矩阵元素执行的命令是python -m pytest -nauto test/backend --durations20其中DEV在 CI 矩阵里取CPU:CLANG、CPU:LLVM、CPU:LVP、CPU:X86、CL、WEBGPU等值部分取值还需要 CI 单独安装的 OpenCL、LLVM 20、mesa 等系统组件见 .github/actions/setup-tinygrad/action.yml。本地没有对应组件时最简单的起点是 CI 的 Python 后端 jobbepython它只装testing_unit依赖SKIP_SLOW_TEST1 DEVPYTHON python3 -m pytest -nauto test/backend/test_dtype.py test/backend/test_dtype_alu.py test/backend/test_ops.py test/backend/test_uops.py test/backend/test_symbolic_ops.py test/backend/test_renderer_failures.py::TestRendererFailures --durations20SKIP_SLOW_TEST1会跳过慢测试是 CI 该 job 自带的写法。README 还给了一个只跑单个测试文件的最短示例python3 test/backend/test_ops.py # just the ops tests结果判断与限制三组命令都用pytest成功条件是全部测试通过、没有 failed/error--durations20会在末尾列出耗时前 20 的测试用于定位慢项而不是判定失败。conftest.py 给每个测试挂了超时保护默认 120 秒可用环境变量TEST_TIMEOUT调整超时进程直接收到SIGABRT。如果你发现测试被信号打断而不是断言失败先检查是否触发了这个超时。仓库的 AGENTS.md 建议用-n12固定 12 个并行 worker 提速README 也注明 always run tests with-n12for speed。CI 用-nauto由机器决定并发数本地两种写法都可用。如果只想冒烟验证而不是整组测试README 给出的全量入口是python3 -m pytest test/但它包含test/external之外的整个test目录范围比三组测试大不建议作为本场景的日常路径。可选安装 pre-commit 钩子README Running tests 一节还提到pre-commit install会在每次 commit 时自动运行 linter、mypy 和一部分测试。这属于开发工作流配置不是运行三组测试的前置步骤只在你要提交代码时安装。三组测试跑完且无失败后你的本地验证就与 CI 的backend/null/unit三个 job 对应上了CI 的完整命令细节可以随时对照 test.yml 中同名的 job。【免费下载链接】tinygradYou like pytorch? You like micrograd? You love tinygrad! ❤️项目地址: https://gitcode.com/GitHub_Trending/tiny/tinygrad创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考