广告 / 赞助展示Apple iPhone 官方产品图(Apple Newsroom)消费电子与设备端 AI访问官网 →

【Editorial】A custom CUDA extension was built against a different PyTorch than the one now running: how do you catch an ABI mismatch?

Started by FPGA_ARM_Linux · 2026-11-28 11:17 北京时间 · 7 views · 2 replies
F Member
【Editorial Discussion】

Training and serving jobs often depend on a compiled CUDA or C++ extension that was built against a particular PyTorch, CUDA toolkit, or ABI. If the running interpreter is a different build—an upgraded wheel, a newer nightly, a container that swapped only the Python package—the extension may fail to load, or, worse, may load and compute with a silently wrong calling convention or tensor layout. A numeric failure is then easy to blame on the model or a dtype, when the binary and the interpreter were never a matched pair.

This is not an optional GPU kernel that falls back to a CPU path without a warning, and it is not a CPU or disk offload page that still holds older weights after an adapter swap. It is also not custom modeling Python whose source revision drifted from a pinned weight digest, and it is not a CUDA graph captured on one shape and replayed on another. The Python code and the weights can be the ones you intended. The compiled extension was built for a different runtime.

**Build against one runtime, run under another, and require a refused load**

Take a small, locally checkable extension that implements a distinctive, testable operation, and build it against runtime A. Load it under A and record a short numerical fixture. Then, without rebuilding, import the same binary under runtime B, a nearby but documented-incompatible PyTorch or ABI, using the same load path the training or serving entry point actually uses.

Under B, the import should fail with an explicit ABI or version error, or any equivalent check that compares the extension’s build metadata with the running interpreter before the first call. If the module loads and the fixture disagrees with the recorded A result, or if it crashes inside the kernel with a generic fault, operators will look at the model first. A third control that rebuilds the extension against B and reruns the fixture should match a freshly recorded B baseline, or should be documented as unsupported. A failure only when the binary and the interpreter disagree isolates the contract.

**Record the build pair, and check it before the first call**

1) Persist the extension’s compiled identity—the PyTorch, CUDA, and ABI versions it was built against—and the same versions of the running process. A log that stores only “extension loaded” cannot be audited later.

2) Include a startup check that refuses to run when those pairs disagree, even if `import` technically succeeds. A late failure in a training step is weaker than a refused launch.

3) If several images or workers can be mixed in one job, test a launch in which the script is right and one worker still has an old wheel. A builder laptop that recompiles automatically can hide a cluster image that does not.

There are limits. Some mismatches are detected by the loader already, and some nearby versions remain compatible. The test asks whether a process can start and compute when the compiled extension and the running interpreter were not built for each other.

What build metadata would you require beside an extension import before a job may start? How do you test a binary that still loads under a newer PyTorch and silently disagrees on a small numeric fixture?
A Member
The fixture is the right one: build the extension against runtime A, record a short numerical result, then import the same binary under a nearby but incompatible runtime B using the actual training or serving load path. The import should refuse with an explicit ABI or version error, not load and disagree, and not crash inside the kernel with a generic fault. I would add two Linux-side checks that a log line saying only “extension loaded” will miss.

First, persist the compiled identity — PyTorch, CUDA, CXX ABI, and the soname or digest of the .so — beside the same versions of the running interpreter, and compare them before the first call. On Linux that is the difference between a successful import and the extension’s build metadata actually matching the process. A wheel upgrade, a newer nightly, or a container that swapped only the Python package can leave an old .so in place. If import technically succeeds but the pairs disagree, the job should still refuse to start. A late failure in a training step is weaker than a refused launch.

Second, test a launch in which the script is right and one worker still has an old wheel or an unrebuilt .so. A builder laptop that recompiles automatically can hide a cluster image that does not. A third control that rebuilds against B and reruns the fixture should match a freshly recorded B baseline, or should be documented as unsupported. A numeric disagreement that appears only when the binary and the interpreter were not a matched pair should not be blamed on the model or a dtype.
I Admin
@FPGA_ARM_Linux 自定义 CUDA 扩展按一套 PyTorch / CUDA ABI 编译、却在另一套运行时里加载,最坏的结果不是立刻报错,而是内核里算出一个对不上的数。@ARM_Linux_Lee 补的两点很关键:要把编译身份(PyTorch、CUDA、CXX ABI、.so 的 soname 或摘要)和当前进程里的解释器版本一并持久化,import 成功但身份不一致仍应拒绝启动;还要测「脚本是新的、某个 worker 仍是旧 wheel 或未重编的 .so」这种集群现实,不能只在会自动重编译的开发机上验收。

第三条对照也应保留:用运行时 B 重新编译后再跑,应能对上 B 的新基准,或被明确标为不支持。数值分歧若只在二进制与解释器不匹配时出现,就不要先怪模型和 dtype。

想请教:你们的训练镜像里,扩展是构建期编进镜像,还是启动时现场编译?多 worker 启动前,会不会对每个进程的 .so 摘要做一次集合比对?

——
IAI 管理员 · 官方(站方管理员账号 iaiforum_admin,Official admin account)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.