add autocudagraph#896
Open
DrRyanHuang wants to merge 2 commits intoPaddlePaddle:developfrom
Open
Conversation
1cdb10c to
9342322
Compare
DrRyanHuang
commented
Apr 30, 2026
| loss.backward() | ||
|
|
||
| losses_eager.append(loss.item()) | ||
| grads_eager.append(model_eager.head2.weight.grad.clone().cpu()) |
Author
There was a problem hiding this comment.
TODO: 记录一个 Paddle 的 BUG,很离谱,这里如果不带 .cpu()
grads_eager.append(model_eager.head2.weight.grad.clone())
每次跑到固定位置,eager 的 grad 就回变成全 0!待排查具体原因
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #896 +/- ##
==========================================
Coverage ? 98.11%
==========================================
Files ? 1
Lines ? 159
Branches ? 33
==========================================
Hits ? 156
Misses ? 1
Partials ? 2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
autocudagraphdecorator for automated CUDAGraph acceleration of forward and backward passes.🌟 Key Features & Implementation
src/paddlefleet/cudagraph.py:核心基础设施CUDAGraphContext):基于dataclass统一管理静态 Tensor Buffer、Fwd/Bwd 句柄与 PyLayer Runner。get_tensors/set_tensors):支持递归遍历嵌套结构(Tensor / list / tuple / dict)提取与写回。autocudagraph):支持 warmup -> capture -> replay 完整生命周期。dispatch_key_fn,超出max_graphs上限时自动无缝回退 Eager 模式。nn.Layer参数梯度,防止 dummy backward 污染真实的跨步累积梯度。paddle.autograd.PyLayer正确路由输入张量梯度与权重参数梯度。🧪 Test Coverage
tests/single_card_tests/test_autocudagraph.pyTestPureFunctionsstop_gradient混合场景TestOOPAndSubmodulesTestConfigurationsdispatch_key_fn动态图分派、max_graphsFallback 机制TestComplexStructuresno_grad上下文对齐TestFatModelTestAdvancedMechanicsTestEdgeMemoryOpsTestGraphLimitationsAndFeaturesTestDispatchNumber/TestNoGradmax_graphs缓存边界限制、no_grad下的对齐📝 Test Plan
test_autocudagraph.py,所有 Case 通过。warmup_steps下,CG 与 Eager 模式前反向 100% 绝对一致 (rtol=0,atol=0)。max_graphs限制时,正常执行不崩溃,平滑回退至 Eager 模式。