Reductions with `dims` bypass the recorded instructions, and `sum(x, dims)` errors
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
- 68/100
Línea de trabajo
Read src/derivatives/linalg/reductions.jl, especially line 41 and the existing scalar and sum! instruction paths. Run the documented sum(t, 1) reproduction and inspect the reduction tests, noting that the issue says this method is currently untested. Done means dims reductions use the intended instruction paths and the positional form no longer errors.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
ReverseDiff records sum over an array in one instruction, and sum! writes the derivative back in one step. Neither is reachable through the documented dims keyword, so sum(x; dims = 1) falls through to Base's generic reduction and records one instruction per element.
Results stay correct. Only the tape size does not.
Tape entries, n × 3 matrix reduced over dimension 1
| call | n=4 | n=40 | n=400 |
|---|---|---|---|
sum(x) |
1 | 1 | 1 |
sum!(y, x) |
1 | 1 | 1 |
mean(x) |
1 | 1 | 1 |
sum(x; dims = :) |
11 | 119 | 1199 |
sum(x; dims = 1) |
12 | 120 | 1200 |
prod(x; dims = 1) |
12 | 120 | 1200 |
mean(x; dims = 1) |
28 | 244 | 2404 |
maximum, minimum and cumsum with dims behave the same way.
sum(x; dims = :) is worth calling out separately: it is sum(x) by definition, and the one-instruction method for it already exists — the keyword form simply does not dispatch to it.
sum(x, dims) errors
src/derivatives/linalg/reductions.jl:41 defines the positional form:
function Base.sum(x::TrackedArray{V,D}, dims) where {V,D}
tp = tape(x)
out = track(sum(value(x), dims), D, tp)
sum(A, dims) was removed from Base in Julia 1.0, and that spelling now means sum(f, itr). So the inner call passes a Matrix where a function is expected, and every call to this method fails:
julia> t = ReverseDiff.track(rand(4, 3), ReverseDiff.InstructionTape());
julia> sum(t, 1)
ERROR: MethodError: objects of type Matrix{Float64} are not callable
It is the only method routing to the sum! instruction, and nothing in the test suite calls it.
What a fix would look like
A Base.sum(x::TrackedArray; dims = :) method that forwards dims === Colon() to the existing scalar path and anything else to the existing sum! instruction, replacing the positional method. prod, maximum, minimum and mean would each need their own instruction rather than a rename.
Found while fixing #172, which is a separate problem on the generic fall-through path.
- 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 4/5 3-5 días Aptitud para principiantes 56/100
JuliaDiff/ReverseDiff.jl#321 ·
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
Todos los issues de JuliaDiff/ReverseDiff.jl
Issues similares
-
Add DocStringExtensionsAbiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
ohno/Antique.jl#165 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
JuliaLang/LinearAlgebra.jl#1749 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
grame-cncm/faust#1344 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
SciML/DiffEqNoiseProcess.jl#342 ·