pymc-devs / pytensor

PyTensor allows you to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays.

Home Page:https://pytensor.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fusion rewriter error

ricardoV94 opened this issue · comments

Description

import pytensor
from pytensor.tensor as pt

x = pt.vector("x", shape=(1,))
pow = pt.vector("pow(x, 2)", shape=(None,))
pytensor.graph.Apply(
    pt.pow,
    [x, pt.as_tensor(2)],
    [pow]
)
out = pt.exp(pow)

fn = pytensor.function([x], out)
ERROR (pytensor.graph.rewriting.basic): SequentialGraphRewriter apply <pytensor.tensor.rewriting.elemwise.FusionOptimizer object at 0x7f73e15095e0>
ERROR (pytensor.graph.rewriting.basic): Traceback:
ERROR (pytensor.graph.rewriting.basic): Traceback (most recent call last):
  File "/home/ricardo/Documents/Projects/pytensor/pytensor/graph/rewriting/basic.py", line 291, in apply
    sub_prof = rewriter.apply(fgraph)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ricardo/Documents/Projects/pytensor/pytensor/tensor/rewriting/elemwise.py", line 1028, in apply
    for inputs, outputs in find_next_fuseable_subgraph(fgraph):
  File "/home/ricardo/Documents/Projects/pytensor/pytensor/tensor/rewriting/elemwise.py", line 1020, in find_next_fuseable_subgraph
    update_fuseable_mappings_after_fg_replace(
  File "/home/ricardo/Documents/Projects/pytensor/pytensor/tensor/rewriting/elemwise.py", line 962, in update_fuseable_mappings_after_fg_replace
    (new_composite_node,) = next_nodes - starting_nodes
    ^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 1)

Nevermind I was creating an invalid Elemwise node. Should have been:

pytensor.graph.Apply(
    pt.pow,
    [x, pt.as_tensor([2]),
    [pow]
)

The two must have the same rank!