Reductions with `dims` bypass the recorded instructions, and `sum(x, dims)` errors
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Julia
- Stelle
- 396
- Fork
- 61
- Merge medio
- 23h 18m
- PR unite (30g)
- 16
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JuliaDiff/ReverseDiff.jl
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
JuliaDiff/ReverseDiff.jl#318 ·
I maintainer di solito rispondono entro 1 giorno
-
`@grad`/`@grad_from_chainrules` silently reuse a tangent if a pullback returns too few tangentsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
JuliaDiff/ReverseDiff.jl#315 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
JuliaDiff/ReverseDiff.jl#314 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 56/100
JuliaDiff/ReverseDiff.jl#321 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
JuliaDiff/ReverseDiff.jl#320 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di JuliaDiff/ReverseDiff.jl
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
SciML/DiffEqNoiseProcess.jl#342 ·
-
Broken links in the docsAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
oxfordcontrol/COSMO.jl#211 ·
-
documentation
Difficoltà 2/5 Mezza giornata Idoneità per principianti 65/100
I maintainer di solito rispondono entro 6 giorni