xtensor vectorize_graph raises max() iterable argument is empty when new_tensor_dims is given but no replacement is a plain tensor

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

メンテナーはふだん 1 日以内に返信

@koushik-hs がすでに取り組んでいます。

2026年11月23日 から。

  • #2708 @koushik-hs による — オープン

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
compilers

調査の方向性

Start in pytensor/xtensor/vectorization.py near line 602, where vectorize_graph calls broadcast_shape with new_tensor_dim_lengths, which is empty when no plain tensor replacement exists. Run the two calls in the issue's snippet to reproduce the ValueError. The issue leaves open whether to skip the broadcast or raise a clearer error, so confirm the choice with maintainers before editing. Done means the chosen behaviour is implemented and a test covers new_tensor_dims with only xtensor replacements.

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

説明

pytensor.xtensor.vectorization.vectorize_graph raises an unhelpful error when new_tensor_dims is not empty and every replacement is an XTensorVariable:

import numpy as np
from pytensor.xtensor import xtensor_constant
from pytensor.xtensor.type import xtensor
from pytensor.xtensor.vectorization import vectorize_graph

x = xtensor("x", dims=("date",), shape=(3,))
new = xtensor_constant(np.ones((4, 3)), dims=("sample", "date"))

vectorize_graph(x * 2.0, replace={x: new})  # dims ("sample", "date"), fine
vectorize_graph(x * 2.0, replace={x: new}, new_tensor_dims=("sample",))
# ValueError: max() iterable argument is empty

With new_tensor_dims set, vectorize_graph calls broadcast_shape(*new_tensor_dim_lengths, arrays_are_shapes=True) (pytensor/xtensor/vectorization.py:602), and new_tensor_dim_lengths only collects the batch shapes of plain tensor replacements. With none, it is empty, and broadcast_shape_iter fails on max().

Found in pymc-labs/pymc-marketing#3402, where extract_response_distribution replaces posterior variables declared with pymc.dims by xtensors and those declared with pymc by plain tensors. A model can have either kind or both, so the call passes new_tensor_dims=("sample",) only when at least one replacement is a plain tensor.

Should vectorize_graph skip the broadcast when there are no tensor replacements (the names then match nothing), or raise a ValueError that says new_tensor_dims was given without a tensor replacement?

PyTensor 3.3.8; vectorization.py is the same on main (daafd793).

主要言語
Python
スター
655
フォーク
266
平均マージ
3日 23時間
マージ済み PR(30日)
43

環境構築

はじめの一歩

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

pymc-devs/pytensor のほかの issue

pymc-devs/pytensor の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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