Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`test_rrule`: also check output tangents with thunked fields

オープン
#296 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
領域
testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Julia
スター
50
フォーク
18
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

JuliaDiff/ChainRulesTestUtils.jl のほかの issue

JuliaDiff/ChainRulesTestUtils.jl の issue をすべて見る

似ている issue

Julia の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。