CUDA CUTLASS FMHA 增量重建
cuda-cutlass-fmha-incremental-rebuild
在编辑 CUTLASS 融合 MHA 头文件(onnxruntime/contrib_ops/cuda/bert/cutlass_fmha/*.h,如 kernel_forward.h 或 fmha_launch_template.h)后重新构建 ONNX Runtime CUDA 时使用;或在头文件修改“通过”了增量构建但测试行为并未变化时使用。解释会产生过时的 Memory-Efficient-Attention(MEA)内核和二进制文件的 nvcc depfile 陷阱,以及如何强制正确重新编译。还涵盖共享 GPU 开发机上的磁盘空间节省技巧。
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 2.2w
- Forks
- 4.4k
01 前言 Front Matter
- name
- cuda-cutlass-fmha-incremental-rebuild
- description
- Use when rebuilding ONNX Runtime CUDA after editing CUTLASS fused-MHA headers (onnxruntime/contrib_ops/cuda/bert/cutlass_fmha/*.h such as kernel_forward.h or fmha_launch_template.h), or when a header edit "passed" an incremental build but test behavior did not change. Explains the nvcc depfile gotcha that produces stale Memory-Efficient-Attention (MEA) kernels and binaries, and how to force a correct recompile. Also covers disk-space frugality on shared GPU dev boxes.
02 资源文件 80
- 脚本scripts/.gitignore25 B
- 脚本scripts/apply.py26.5 KB
- 脚本scripts/blender_prop.py15.4 KB
- 脚本scripts/distill.py19.8 KB
- 脚本scripts/falapi.py30.4 KB
- 脚本scripts/forge.py16.5 KB
- 脚本scripts/HANDOFF-TEMPLATE.md8.5 KB
- 许可证scripts/LICENSE1.0 KB
- 脚本scripts/mint.py7.8 KB
- 脚本scripts/mint3d.py11.6 KB
- 脚本scripts/pipeline.py7.2 KB
- 脚本scripts/pyproject.toml617 B
- 脚本scripts/requirements-live.txt242 B
- 脚本scripts/requirements.txt66 B
- 脚本scripts/resolve_ingest.py19.3 KB
- 脚本scripts/taste/__init__.py—
- 脚本scripts/taste/assemble.py11.6 KB
- 脚本scripts/taste/cadence.py11.1 KB
- 脚本scripts/taste/falapi.py30.4 KB
- 脚本scripts/taste/frames.py11.7 KB
- 脚本scripts/taste/grade.py32.7 KB
- 脚本scripts/taste/pack.py5.3 KB
- 脚本scripts/taste/plates.py9.7 KB
- 脚本scripts/taste/render3d.py10.2 KB
- 脚本scripts/taste/resolve.py297 B
- 脚本scripts/taste/timeline.py20.3 KB
- 脚本scripts/tasteforge/__init__.py926 B
- 脚本scripts/tasteforge/__main__.py172 B
- 脚本scripts/tasteforge/apply.py9.5 KB
- 脚本scripts/tasteforge/assets.py10.7 KB
- 脚本scripts/tasteforge/cli.py8.6 KB
- 脚本scripts/tasteforge/contract.py25.2 KB
- 脚本scripts/tasteforge/distill.py5.7 KB
- 脚本scripts/tasteforge/export.py9.8 KB
- 脚本scripts/tasteforge/fixtures/flashethereal/cadence.json7.8 KB
- 脚本scripts/tasteforge/fixtures/flashethereal/flashethereal-cut.edl8.5 KB
- 脚本scripts/tasteforge/fixtures/flashethereal/grade.json7.2 KB
- 脚本scripts/tasteforge/fixtures/flashethereal/grounding.txt970 B
- 脚本scripts/tasteforge/fixtures/flashethereal/pack.json1.3 KB
- 脚本scripts/tasteforge/fixtures/flashethereal/spec.json1.3 KB
- 脚本scripts/tasteforge/integration.py18.9 KB
- 脚本scripts/tasteforge/interview.py3.2 KB
- 脚本scripts/tasteforge/media/__init__.py85 B
- 脚本scripts/tasteforge/media/capcut.py2.8 KB
- 脚本scripts/tasteforge/media/common.py1.3 KB
- 脚本scripts/tasteforge/media/glitch.py7.0 KB
- 脚本scripts/tasteforge/media/manim_geo.py5.0 KB
- 脚本scripts/tasteforge/media/stills.py3.1 KB
- 脚本scripts/tasteforge/pack.py6.6 KB
- 脚本scripts/tasteforge/provenance.py5.7 KB
- 脚本scripts/tasteforge/providers.py2.8 KB
- 脚本scripts/tasteforge/README.md15.3 KB
- 脚本scripts/tasteforge/resolve.py12.3 KB
- 脚本scripts/tasteforge/schema.py15.0 KB
- 脚本scripts/tasteforge/timeline.py3.5 KB
- 脚本scripts/tasteforge/workflow.py33.8 KB
- 脚本scripts/verify.py9.8 KB
- 脚本scripts/workflow_graphs.py6.6 KB
- 参考文档SOURCE.md2.1 KB
- 脚本tests/test_apply.py10.3 KB
- 脚本tests/test_assets.py8.2 KB
- 脚本tests/test_cli.py15.7 KB
- 脚本tests/test_distill.py3.2 KB
- 脚本tests/test_integration.py29.5 KB
- 脚本tests/test_interview.py3.0 KB
- 脚本tests/test_media_utilities.py16.3 KB
- 脚本tests/test_multimodal_contract.py20.7 KB
- 脚本tests/test_multimodal_workflow.py17.6 KB
- 脚本tests/test_offline_fixture.py2.6 KB
- 脚本tests/test_pack.py3.4 KB
- 脚本tests/test_provenance.py3.1 KB
- 脚本tests/test_providers.py1.7 KB
- 脚本tests/test_resolve.py10.0 KB
- 脚本tests/test_schema.py3.9 KB
- 脚本tests/test_timeline_export.py4.5 KB
- 参考文档workflows/README.md4.4 KB
- 参考文档workflows/taste-apply-motion.json5.4 KB
- 参考文档workflows/taste-apply.json5.1 KB
- 参考文档workflows/taste-distill.json4.6 KB
- 参考文档workflows/taste-prop3d.json2.2 KB
03 SKILL.md 正文
Incremental rebuilds silently use STALE CUTLASS fused-MHA kernels
The general false-green principles (stale binary, wrong-artifact mtime) are summarised in the
ort-testskill's "False-green taxonomy". This skill is the CUDA/CUTLASS-specific detail.
The gotcha (verification-integrity bug)
nvcc-generated depfiles do not track the CUTLASS fused-MHA headers under
onnxruntime/contrib_ops/cuda/bert/cutlass_fmha/ (e.g. kernel_forward.h,
fmha_launch_template.h). These headers are #included by the fmha_sm*.cu
translation units, but the build system does not record that dependency.
Consequence: after you edit one of those headers, an incremental build.sh:
- does not recompile
fmha_sm*.cu, - reports
[100%] Built target ...and exits 0, - leaves the recompiled artifacts — the
fmha_sm*.cu.oobjects and thelibonnxruntime_providers_cuda.sothey link into — unchanged (samemtimeas the pre-edit build).
(Do not use the gtest test-exe mtime as the stale symptom: in the shared-provider
build the exe dlopens the .so and is not relinked, so its mtime stays old even
after a correct rebuild — see "How to confirm" below. The reliable diagnostic signal
is the fmha_sm*.cu.o / .so mtime.)
So your "successful" rebuild is running the old kernel. Tests that should now pass (or fail) reflect the previous code, not your edit. This silently invalidates any FAIL→PASS / PASS→FAIL verification.
The fix — force recompile the .cu units
Before rebuilding after editing any cutlass_fmha/*.h header:
touch onnxruntime/contrib_ops/cuda/bert/cutlass_fmha/*.cu
Then run the normal build command. This forces the fmha_sm*.cu translation units
(and downstream binaries) to recompile against your header change.
How to confirm the rebuild was real (don't trust "[100%] Built")
Confirm that the artifact which actually links the recompiled fmha_sm*.cu.o
is newer than your header edit.
⚠️ Do NOT just check the test EXE mtime — it can falsely flag a good build as
stale. In the shared-provider build configuration (the default here), the CUDA
execution provider is a shared module: the recompiled fmha_sm*.cu.o link into
libonnxruntime_providers_cuda.so, and the onnxruntime_provider_test executable
dlopens that .so — it is not relinked. So after a correct rebuild the
test exe mtime stays old while the .so advances. Checking the exe alone
would wrongly conclude the build was stale.
Check the right artifact for your link mode:
- Shared-provider build (default): the
.sothat links the recompiled.o—build/<dir>/<cfg>/libonnxruntime_providers_cuda.so - Statically-linked provider: the test exe itself (
onnxruntime_provider_test)
Safest check — stat both the recompiled object and the .so, and confirm BOTH
are newer than the header edit:
stat -c '%y %n' onnxruntime/contrib_ops/cuda/bert/cutlass_fmha/kernel_forward.h
# in your build dir, e.g. build/Debug_quickbuild/Debug/:
stat -c '%y %n' libonnxruntime_providers_cuda.so
# and the actual recompiled object (path varies by build dir):
find . -name 'fmha_sm80.cu.o' -exec stat -c '%y %n' {} +
If the .so (and the fmha_sm*.cu.o) timestamps are older than (or equal to) the
header edit, the build was stale — touch the .cu files and rebuild. The most
reliable signal of all is behavioral: a test that was failing now passes (a stale
binary cannot flip its result).
Related: pick the right test binary
This is the CUDA/CUTLASS instance of false-green mode 1 (zero-match / wrong binary) —
see the ort-test skill's "False-green taxonomy" for the general principle. In short:
attention/MEA/Flash boundary gtests (e.g. FlashStructuralEmptyRows*,
Attention_Causal_NonPadKVSeqLen_MEA_*) live in onnxruntime_provider_test, which CI
runs; onnxruntime_test_all does not contain them and gives a false green. Verify the
MEA/Flash boundary fix against onnxruntime_provider_test.
Related: disk frugality on shared GPU dev boxes
Full ORT CUDA builds are large (test binaries ~1 GB each; a build dir can reach
tens of GB). On a shared box, /home filling to 100% makes builds fail in
non-obvious places — e.g. git submodule sync reporting No space left on device
or a config.lock error, not an obvious "disk full" at the compile step.
Before a big rebuild, check free space and clean only clearly-stale, regenerable build directories (old dated experiment dirs). Never delete another agent's active build dir or anything ambiguous:
df -h /home
du -sh build/* | sort -h
04 同仓库更多 Skills
工作空间估计共享头文件
workspace-estimation-shared-header
在编辑边界安全的共享头文件时使用,该头文件须同时被树内代码和共享提供者/插件桥接代码包含(例如 include/onnxruntime/core/framework/workspace_requirement.h,或任何未来支持 OrtKernelWorkspaceEstimateFunc / DeclareWorkspaceRequirements 的头文件,参见 issue #29775 的 Phase-A 工作空间估计路线图),或者当工作空间估计数学辅助函数需要从未来的插件 EP DLL 中调用时。涵盖 Node 前向声明的 ODR 陷阱,以及在实现 PR #29811(MatMulNBits 试点)时发现的数学辅助函数与图解析包装器之间的重用边界。
ONNX Runtime WebGPU 本地测试
webgpu-local-testing
在没有真实 GPU 的 Linux 上构建并运行 ONNX Runtime WebGPU 提供者测试,使用软件 Vulkan 适配器(Mesa lavapipe)。当需要在非 Mac 环境下运行 WebGPU EP 内核时使用——Linux 的 webgpu CI 环节仅做构建,因此软件 Vulkan 是本地实际运行 WebGPU 正确性测试的方式。范围——lavapipe 仅能验证主机侧的 enforce/shape 缺陷以及不含 MatMul 的内核;任何包含 MatMul 的图(包括扩展的 Attention 节点测试)都会使 lavapipe 崩溃,此类测试仅在 macOS-arm64 Metal 上运行,Metal 是这些测试的权威来源。涵盖安装(在 Azure Linux 上用 dnf)、--use_webgpu 构建标志、onnxruntime_provider_test 目标、VK_ICD_FILENAMES,以及 lavapipe 的 MatMul 崩溃陷阱。
Python setattr 安全审查
python-kwargs-setattr-security
在审查或修复 ONNX Runtime 中使用用户可控的 kwargs 通过 setattr() 配置 C++ 扩展对象(SessionOptions、RunOptions 等)的 Python 代码时使用。用于应用白名单模式,防止通过反射属性访问进行任意文件写入和其他攻击。
ONNX Runtime Transformers GPU 测试
ort-transformers-gpu-pytest
针对 GPU wheel 运行 ONNX Runtime transformers Python 测试(onnxruntime/test/python/transformers),并确认真实的 cuDNN/flash SDPA 调度。当 transformers pytest 因 ModuleNotFoundError onnxruntime.capi 失败、torch 自带的 CUDA/cuDNN 库覆盖了 ORT 构建的库(导致错误版本调度或加载错误),或必须证明测试确实执行了 cuDNN SDPA 解码层而非静默跳过或回退到 MATH 时使用。
ONNX Runtime 测试执行与调试
ort-test
运行 ONNX Runtime 测试。当被要求运行测试、调试测试失败,或在 ONNX Runtime 中查找并执行特定测试用例时使用此技能。
ONNX Runtime 发布说明撰写
ort-release-notes
使用预设配置为完整 ORT 或限定范围的组件发布起草 ONNX Runtime 发布说明。适用于生成带 PR 链接的亮点摘要、根据 compile_contributors.py 的输出整理人工贡献者致谢名单,以及应用预设的路径过滤。