Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`test_rrule`: also check output tangents with thunked fields

Aperta
#296 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Ambito
testing

Direzione di ricerca

Start with test_rrule and the existing check_thunked_output_tangent option, which currently calls the pullback with only the outer output tangent thunked. Reproduce the failure by wrapping each field of a Tangent output in a thunk and calling the pullback, as in the findnz example. Done means the new check runs for Tangent, Tuple and NamedTuple outputs, and that the unthunked and thunked results match. Decide with a maintainer whether to reuse the existing flag or add a new one.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

check_thunked_output_tangent=true only checks the pullback with the whole output tangent thunked, i.e. pullback(@thunk(ȳ)). But AD systems also pass structural tangents whose fields are thunks. For example, Zygote's tuple getindex adjoint keeps thunks, so for f(x)[i] the rule receives Tangent{Any}((ZeroTangent(), …, thunk, …)).

Rules that handle the outer thunk correctly can still fail on this. In JuliaDiff/ChainRules.jl#843, the findnz rule passed test_rrule, but with Zygote it failed:

using SparseArrays, Zygote
Zygote.gradient(A -> sum(findnz(A)[3]), sprand(5, 5, 0.4))
# MethodError: no method matching sparse(::Vector{Int64}, ::Vector{Int64}, ::InplaceableThunk{...}, ::Int64, ::Int64)

The pullback destructured _, _, V̄ = unthunk(Δ). Destructuring a Tangent does not unthunk its fields, unlike getindex/getproperty (see JuliaDiff/ChainRulesCore.jl#712).

Proposal: when the output tangent ȳ is a Tangent, or a Tuple/NamedTuple that is converted to one, test_rrule should additionally call the pullback with every field wrapped in a thunk, e.g. Tangent{P}(map(x -> @thunk(x), backing(ȳ))...), and compare the result with the unthunked cotangents. This could reuse the existing check_thunked_output_tangent flag or get a new one.

Lingua principale
Julia
Stelle
50
Fork
18
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaDiff/ChainRulesTestUtils.jl

Tutte le issue di JuliaDiff/ChainRulesTestUtils.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.