`@grad`/`@grad_from_chainrules` fail for rules returning structured arrays (`Diagonal`, `UpperTriangular`, ...)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 56/100
Línea de trabajo
Start with the two tracking paths in src/macros.jl named in the issue: @grad and @grad_from_chainrules. Reproduce the Diagonal and UpperTriangular examples, then trace how output tracking and forward replay handle structured arrays. Done means both examples complete without the IndexStyle assertion and return the expected gradients.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
If a rule's primal output is an array without linear indexing, such as Diagonal or UpperTriangular, ReverseDiff fails when it wraps the output in a TrackedArray. This affects both @grad_from_chainrules and @grad.
using ReverseDiff, ChainRulesCore, LinearAlgebra
f(x) = Diagonal(x)
ChainRulesCore.rrule(::typeof(f), x) = f(x), Δ -> (NoTangent(), diag(unthunk(Δ)))
ReverseDiff.@grad_from_chainrules f(x::ReverseDiff.TrackedArray)
ReverseDiff.gradient(x -> sum(f(x)), [1.0, 2.0])
ERROR: LoadError: AssertionError: IndexStyle(value) === IndexLinear()
Stacktrace:
[1] ReverseDiff.TrackedArray{Float64, Float64, 2, Diagonal{Float64, Vector{Float64}}, Diagonal{Float64, Vector{Float64}}}(value::Diagonal{Float64, Vector{Float64}}, deriv::Diagonal{Float64, Vector{Float64}}, tape::ReverseDiff.InstructionTape)
...
[5] track(::typeof(f), x::ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}})
@ Main ~/.julia/dev/ReverseDiff/src/macros.jl:339
@grad with an UpperTriangular output fails the same way:
g(x) = UpperTriangular(x)
g(x::ReverseDiff.TrackedArray) = ReverseDiff.track(g, x)
ReverseDiff.@grad function g(x)
return UpperTriangular(ReverseDiff.value(x)), Δ -> (triu(Δ),)
end
ReverseDiff.gradient(x -> sum(g(x)), [1.0 2.0; 3.0 4.0])
# ERROR: AssertionError: IndexStyle(value) === IndexLinear()
Expected: [1.0, 1.0] and [1.0 1.0; 0.0 1.0]. Many ChainRules rules return structured matrices (Diagonal, Symmetric, triangular factors, ...), so importing them fails as soon as the output is tracked.
Cause: the macros call track(output_value, tp) on the primal output as is (@grad, @grad_from_chainrules). TrackedArray requires IndexLinear() storage, and even with #216 a Diagonal/UpperTriangular deriv couldn't store the off-structure entries the reverse pass seeds. Materializing such outputs (e.g. collect) before tracking would avoid this. The forward replay value!(output, out_value) has to do the same.
ReverseDiff master (b796032, v1.18.4), Julia 1.13.1.
- Lenguaje dominante
- Julia
- Estrellas
- 396
- Forks
- 61
- Merge medio
- 23 h 18 min
- PR fusionados (30 d)
- 16
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de JuliaDiff/ReverseDiff.jl
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
JuliaDiff/ReverseDiff.jl#318 ·
Los mantenedores suelen responder en 1 día
-
`@grad`/`@grad_from_chainrules` silently reuse a tangent if a pullback returns too few tangentsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
JuliaDiff/ReverseDiff.jl#315 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
JuliaDiff/ReverseDiff.jl#314 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
JuliaDiff/ReverseDiff.jl#320 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
JuliaDiff/ReverseDiff.jl#319 ·
Los mantenedores suelen responder en 1 día
Todos los issues de JuliaDiff/ReverseDiff.jl
Issues similares
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up stepsPosiblemente ocupada @thevolatilebit la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
found-by-agent
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
exanauts/SparseDirectSolver.jl#92 ·
Los mantenedores suelen responder en 1 día
-
`inv` of a dense matrix fails for arrays whose `parent` is not an array of the same kindPosiblemente ocupada @devmotion la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
JuliaLang/LinearAlgebra.jl#1740 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
NumericalEarth/Breeze.jl#1051 ·
Los mantenedores suelen responder en 1 día