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

svd_rev issue with orthogonal matricies

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
32/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
julia
領域
tooling

調査の方向性

リンク先の位置にある src/rulesets/LinearAlgebra/factorization.jl の SVD ルールから始め、次に単位行列と直交行列を含む 3 つの Zygote.gradient の例を再現してください。報告されている特異値の縮退を調査し、直交入力に対して期待される動作を判断してください。完了には、合意されたアプローチと回帰テストまたは文書化された制限が必要ですが、issue ではメンテナーがどの結果を望んでいるかは指定されていません。

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

説明

using Zygote
using LinearAlgebra

r = rand(8,8); Σ = r' * r
foo(X) = tr(svd(X).U)
_orthogonal(X) = svd(X).U * svd(X).V'

Zygote.gradient(foo, Σ) # Works
Zygote.gradient(foo, 1.0 * Matrix(I(5))) # Nan
Zygote.gradient(foo, _orthogonal(rand(5,7))) # NaN/Inf

This reads as an edge case, but the reason this came up because of interest in introducing an orthogonality constraint in a pipeline. As the matrix is constrainted to be orthogonal, a natural initialisation would be also orthogonal, however it leads to the above issue (this essentially does the same thing):

using ParameterHandling: value, orthogonal

bar(X) = tr(value(orthogonal(X)))
Zygote.gradient(bar, Σ) # Works

# A natural initialisation for an orthogonal constrained matrix is orthogonal
Zygote.gradient(bar, _orthogonal(Σ)) # Fails

IIUC, I believe that the for orthogonal matrix as the singular values are 1 the F in the svd rule will explode.

A workaround was to add a small noise term suggesting that somewhere perhaps this should cancel? - the UᵀŪ - ŪᵀU) and (VᵀV̄ - V̄ᵀV terms) but idk

Zygote.gradient(bar, _orthogonal(Σ) + 1e-10 * Diagonal(rand(size(Σ, 1)))) # Works
# ([3.032964106070741e-29 -6.862457650747e-16 … -8.654203384732967e-16 2.8416261314487268e-15; 6.862728701290122e-16 -2.4424906535614213e-15 … 1.1744348982906105e-15 -1.2198799099766983e-15; … ; 8.654203384732967e-16 -1.4343655928804322e-15 … -1.7763568394002505e-15 2.310651670001107e-15; -2.841639683975883e-15 1.0009591625611408e-15 … -1.7551064768195346e-15 -1.5543122344752192e-15],)

There doesn't seem to be anything wrong with the rule themselves, and the workaround is reasonable once it's understood what's occuring, however as this started impacting another internally I thought i'd raise this as an issue. If the diagnosis is correct, are there any approaches to make this nice in the scenario described?

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

環境構築

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

はじめの一歩

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

JuliaDiff/ChainRules.jl のほかの issue

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

似ている issue

Julia の issue をもっと見る

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

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