checktag's permissive fallback silently disables tag checking (e.g. for derivative(f!, y, x, cfg))
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 50/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 领域
- tooling
调研方向
先从 checktag 方法和 derivative/derivative! 的调用点开始,然后将它们的行为与 gradient 的 InvalidTagException 路径进行比较。当针对错误函数的 DerivativeConfig 在标量 derivative 调用中被拒绝,并且已考虑文档中 nothing 的行为和自定义标签的行为时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
A DerivativeConfig built for one function is silently accepted by another, so derivative(f!, y, x, cfg) gets no perturbation confusion protection at all:
julia> a!(y, x) = (y .= sin(x)); b!(y, x) = (y .= cos(x));
julia> y = Vector{Float64}(undef, 2);
julia> cfg = ForwardDiff.DerivativeConfig(a!, y, 0.0);
julia> ForwardDiff.derivative(b!, y, 0.0, cfg) # cfg belongs to a!, no complaint
2-element Vector{Float64}:
-0.0
-0.0
gradient does raise InvalidTagException in the analogous situation. This reproduces with a real y on master, so it is unrelated to complex support.
The immediate cause is that every non-fallback checktag method requires x::AbstractArray:
checktag(::Type{Tag{FT,VT}}, f::F, x::AbstractArray{V}) where {FT,VT,F,V} = throw(InvalidTagException{...}())
checktag(::Type{Tag{F,V}}, f::F, x::AbstractArray{V}) where {F,V} = true
while derivative/derivative! call checktag(T, f!, x) with a scalar x. Dispatch lands on the catch-all checktag(z, f, x) = true, so the check argument of derivative(f!, y, x, cfg, Val{true}()) has no effect.
Adding scalar counterparts of those two methods fixes this particular case, but the more interesting question is whether the permissive checktag(z, f, x) = true default should stay. As it stands, any signature that does not match a specific method silently opts out of checking, which is how this gap went unnoticed -- the failure mode is "no error", not "no method". Defaulting to rejection and explicitly accepting only validated tags would make such gaps loud instead of silent.
Two things to note for anyone attempting that:
- The return value is currently discarded -- every call site is
CHK && checktag(...), andchecktagworks purely by throwing. So flipping the default tofalseon its own changes nothing; the call sites would have to throw on afalseresult. Nothingneeds to be accepted explicitly, since anothingtag is documented as usable with any target function. Custom tag types currently pass via the same fallback ("custom tag: you're on your own"), so rejecting by default would be breaking for them unless they opt in by definingchecktagfor their tag type -- arguably the point, but worth a deprecation path.
- 主要语言
- Julia
- 星标
- 1k
- 派生
- 162
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
JuliaDiff/ForwardDiff.jl 的其他 Issue
-
missing floatmin, floatmax, and issubnormal for Dual可能已有人在做 @devmotion 于 16 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
JuliaDiff/ForwardDiff.jl#852 · 6 条评论 ·
-
`fma` and `muladd` ignore NaN-safe mode可能已有人在做 @devmotion 于 2 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
JuliaDiff/ForwardDiff.jl#860 ·
-
Enable NaN-safe mode by default可能已有人在做 @devmotion 于 4 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 25/100
JuliaDiff/ForwardDiff.jl#857 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 52/100
JuliaDiff/ForwardDiff.jl#854 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 75/100
JuliaDiff/ForwardDiff.jl#849 ·
查看 JuliaDiff/ForwardDiff.jl 的全部 Issue
相似的 Issue
-
enhancement good first issue help wanted
难度 2/5 半天 新手友好度 82/100
-
authority-vechtstromen ready-for-agent
难度 1/5 1 小时以内 新手友好度 75/100
Deltares/Ribasim-NL#890 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
JuliaLinearAlgebra/GenericLinearAlgebra.jl#183 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
JuliaGPU/KernelAbstractions.jl#897 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
oscar-system/GAP.jl#1455 ·
维护者通常 1 天内回复