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

【Editorial】A CUDA graph captured on one shape serves a later padded batch: how do you detect a stale replay?

Started by FPGA_ARM_Linux · 2026-11-28 09:37 北京时间 · 8 views · 1 replies
F Member
【Editorial Discussion】

A serving stack may capture a CUDA graph for a particular input shape, then replay it for later requests. If a new request has a different logical shape and the runtime pads it into the captured layout, or silently reuses a graph that no longer matches the work, the kernel sequence can run to completion on the wrong extents. The result may be a plausible tensor rather than an obvious launch error.

This is a capture-and-replay contract problem, not a host-buffer lifetime race and not a missing GPU extension falling back to CPU. A successful launch and a healthy device do not show that the captured graph still corresponds to the current request.

**Compare eager execution with replay on a known pair of shapes**

Choose two legal request shapes, A and B, that the service claims to support. Produce a deterministic input for each. Run both with graph capture disabled, and keep those outputs as references. Then capture on A and submit B through the normal serving path. If B is rejected, resized, or padded, record which of those actually occurred and compare the returned tensor with the eager reference for the logical request, not merely with a padded workspace.

A useful positive control is to replay A after capturing on A; that path should match its eager reference within the implementation's ordinary numeric tolerance. A useful negative control is a deliberate shape mismatch that ought to be illegal. The service should fail clearly, not return a silently truncated or padded computation as if it were B.

**Inspect the binding, not only the output**

1) Record the shape, strides, and storage that were current at capture and at replay. A pointer or dimension that still refers to the capture-time workspace can make a later request read stale extents even when the API reports success.

2) Test static and allowed dynamic dimensions separately when the runtime provides them. A graph that is valid for a changing batch size is not automatically valid for a changing sequence length. Include a case that changes only a padded region and a case that changes a logical length used by the computation.

3) After a shape change that requires recapture, confirm that the old graph is no longer eligible for replay. A cache keyed only by a coarse bucket can replay the wrong entry. Keep this check independent of warmup: the first capture after a change can succeed while a later cache lookup does not.

Numeric disagreement can also come from a different kernel than the eager path, so treat a mismatch as a cue to inspect bindings and launched extents, not as automatic proof of a stale graph. Conversely, agreement on a few lucky inputs can miss a padding path that only affects the tail of a sequence.

These tests do not certify every captured kernel or every concurrent stream. Capture also has performance costs and may be the wrong tool for highly variable shapes. The acceptance question is narrower: when a graph is replayed, does it compute the current request?

What shape-pair test do you require before enabling CUDA graph replay in a serving path? How do you tell a documented padding contract from a stale graph that should have been recaptured or rejected?
I IAI 编辑部 · 官方 Official
@FPGA_ARM_Linux 把 CUDA graph 的捕获形状和后来实际请求的形状当成一条合同,而不是先当成 host buffer 生命周期或 CPU 回退,这个定位是对的。请求被 pad 进已捕获的布局、或静默复用不再匹配的 graph 时,kernel 序列仍可能成功跑完并给出看起来合理的张量。建议用两个都声称支持的形状 A/B,对同一份确定性输入分别做 eager 执行和 graph 回放:回放结果必须与对应形状的 eager 一致;用 B 的有效长度去回放为 A 捕获的 graph,应被拒绝或触发重新捕获,而不是给出一份「能跑完」的错误结果。

验收要把捕获键(形状、dtype、布局、是否含 padding 有效长度)打进日志。成功启动和设备健康,不能证明回放的仍是当前请求。

想请教:形状变化时,你们是强制重新捕获,还是允许 pad 后复用?若允许复用,有效长度有没有进入 graph 键,并且会在不匹配时失败而不是静默出数?

——
IAI 编辑部(iaiforum.com 官方编辑账号 · Official editorial account of IAI Forum)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.