Wrapping a graph in OpFromGraph breaks its gradient when it has an integer output
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 22/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
Start in pytensor/compile/builders.py at _build_and_cache_lop_op, where the cotangent placeholder is created from the output variable's own type — here an integer scalar — and the inner pytensor.grad call then rejects it. Reproduce with the snippet in the issue, then compare against the unwrapped graph to see how a float known_grad reaches the same inner grad. Read the linked discussion #2065 for the Scan case that sends zeros for an integer carry. Note an open pull request (#2718) already targets this, so check its state before starting; done means the wrapped graph differentiates and the float cotangent is handled for the integer output.
索引モデルが issue の本文から書いたものです。
説明
pytensor.grad raises on an OpFromGraph with an integer output when that output receives a float cotangent, though the same graph without the wrapper differentiates. _build_and_cache_lop_op builds the placeholder for that cotangent with the output's integer type, and the inner grad call rejects it. Scan hits this whenever its step is an OpFromGraph with an integer carry, because it sends zeros for that carry, as discussed in #2065.
import pytensor
import pytensor.tensor as pt
from pytensor.compile.builders import OpFromGraph
x = pt.dvector("x")
k0 = pt.lscalar("k0")
known_grads = lambda c, k: {c: pt.ones_like(c), k: pt.zeros((), dtype="float64")}
c, k = x * 2, k0 + 1
pytensor.grad(None, x, known_grads=known_grads(c, k)) # works
ix, ik = x.type(), pt.lscalar()
c, k = OpFromGraph([ix, ik], [ix * 2, ik + 1])(x, k0)
pytensor.grad(None, x, known_grads=known_grads(c, k))
# TypeError: Gradients must always be NullType, DisconnectedType, or continuous,
# but grad was given a known_grad of type Scalar(int64, shape=())
- 主要言語
- Python
- スター
- 655
- フォーク
- 266
- 平均マージ
- 3日 23時間
- マージ済み PR(30日)
- 43
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pymc-devs/pytensor のほかの issue
-
BUG: cumsum and cumprod keep bool and small integer dtypes, so cumsum(x > 0) is wrong対応中かも @rishabhsai が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
Docs of mode still mentions C/CVM as the default with FAST_RUN対応中かも @ADITYASINGH1206 が 13 日前に担当しました。 オープンdocs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
pymc-devs/pytensor#2641 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Update conditions page in docs対応中かも @caxaxa が 3 日前に担当しました。 オープンdocs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
BUG: geomspace returns wrong sign for the endpoints when start and stop are negative対応中かも @mayuriphad が 32 日前に担当しました。 オープン
難易度 2/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
pymc-devs/pytensor#2430 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
pymc-devs/pytensor の issue をすべて見る
似ている issue
-
triage
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
kornia/kornia-rs#1416 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
ui
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
PolicyEngine/ai-inequality#64 ·
メンテナーはふだん 1 日以内に返信
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over time対応中かも @PabloRoque が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
pymc-devs/pymc-extras#839 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信