Eigh of a constant gets a different eigenvector sign inside Scan than outside

未关闭
#2,724 10 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #2725 来自 @lyn1dev —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
numpy, python

调研方向

Start by reading the scan_push_out_non_seq change referenced by commit 14da9a865 and trace how constant-only expressions are handled inside Scan. Compare the constant-folding path through NumPy with the compiled inner path described in the report. The issue is resolved when the repeated-eigenvalue example returns consistent eigenvector signs inside and outside Scan; a linked closed pull request may contain relevant work.

由索引模型根据 Issue 内容生成。

描述

bug graph rewriting scan

A compiled function that reads the same pt.linalg.eigh output inside and outside a Scan gets two different values for it. Since 14da9a865, scan_push_out_non_seq keeps constant-only expressions inside the scan, so the Eigh runs twice. Constant folding evaluates the outer copy through numpy, and the numba-compiled inner function evaluates the inner one, and the two pick opposite signs for the eigenvectors of a repeated eigenvalue.

import pytensor
import pytensor.tensor as pt

_, eigenvectors = pt.linalg.eigh(25.0 * pt.eye(2))
corner = eigenvectors[0, 0]

trace = pytensor.scan(
    lambda total: total + corner, outputs_info=[pt.zeros(())], n_steps=2, return_updates=False
)
f = pytensor.function([], [trace[-1], corner])

print(f())  # [-2.0, 1.0], expected [2.0, 1.0] as on ae782b0fb
主要语言
Python
星标
655
派生
266
平均合并
3 天 23 小时
30 天内合并 PR
43

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pymc-devs/pytensor 的其他 Issue

查看 pymc-devs/pytensor 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。