`vect` rrule pullbacks index a thunked cotangent once per argument (quadratic), same pattern as #860
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 85/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- julia
- 领域
- performance
调研方向
三个 vect_pullback 方法位于 src/rulesets/Base/array.jl。在每个方法顶部添加 ȳ = unthunk(ȳ),镜像针对 reduce 的 #861 修复。用 issue 的基准测试确认:thunked back(...) 的时间应下降到接近 unthunked 测量值。
由索引模型根据 Issue 内容生成。
描述
Follow-up to #860 / #861. The rrules for Base.vect (src/rulesets/Base/array.jl, three methods) read the input cotangent once per argument (projects[n](ȳ[n]), ȳ[n], NTuple{N}(ȳ)). When ȳ is a thunk, each access re-evaluates the thunk, so the pullback is quadratic in the number of arguments. This is the same pattern as the reduce(vcat/hcat) pullbacks fixed in #861.
using ChainRules, ChainRulesCore
for N in (256, 1024, 4096)
X = ntuple(i -> iseven(i) ? 1.0 : 1.0f0, N) # hits the Union{Number,AbstractArray{<:Number}} method
y, back = rrule(Base.vect, X...)
dY = @thunk(ones(length(y)))
back(dY); back(unthunk(dY))
t1 = minimum(@elapsed(back(dY)) for _ in 1:20); t2 = minimum(@elapsed(back(unthunk(dY))) for _ in 1:20)
println("N=$N thunk: ", round(t1*1e6, digits=1), " µs unthunked: ", round(t2*1e6, digits=1), " µs")
end
| N | thunk | after unthunk |
|---|---|---|
| 256 | 28.1 µs | 6.0 µs |
| 1024 | 217 µs | 24.2 µs |
| 4096 | 2389 µs | 95.7 µs |
At N = 2048 all three methods (mixed numbers, Any, and uniform Float64) were measured at roughly 600 to 670 µs with a thunk against roughly 40 µs after unthunk. ChainRules 1.74.8, ChainRulesCore 1.26.8, Julia 1.13.2.
Proposal: ȳ = unthunk(ȳ) at the top of each vect_pullback. Downstream in Zygote the cotangent arriving from sum is a thunk, as in FluxML/Zygote.jl#1686.
🧔♂️🤖 Assisted by AI
- 主要语言
- Julia
- 星标
- 479
- 派生
- 100
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 10
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
JuliaDiff/ChainRules.jl 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 25/100
JuliaDiff/ChainRules.jl#863 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 55/100
JuliaDiff/ChainRules.jl#818 ·
维护者通常 1 天内回复
-
refactoring
难度 4/5 3-5 天 新手友好度 35/100
JuliaDiff/ChainRules.jl#815 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 45/100
JuliaDiff/ChainRules.jl#810 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 30/100
JuliaDiff/ChainRules.jl#809 ·
维护者通常 1 天内回复
查看 JuliaDiff/ChainRules.jl 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
backport 1.14 GC
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
`binary_focal_loss` throws a `DomainError` when a negative sample has `ŷ = 1`可能已有人在做 @parth-patel010 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
JuliaDiff/TaylorSeries.jl#445 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
control-toolbox/CTActions#139 · 1 条评论 ·
维护者通常 1 天内回复