Open lucianopaz opened 1 year ago
This looks more like a bug in broadcast_to
, which should do some input validation in the perform method.
import pytensor
from pytensor import tensor as pt
import numpy as np
a = pt.as_tensor_variable(np.zeros((3, 2)), name="a")
a_bcast = pt.broadcast_to(a, (3, 4))
a_bcast.eval() # Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
Numpy does the right thing:
a = np.zeros((3, 2))
np.broadcast_to(a, (3, 4))
# ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (3,2) and requested shape (3,4)
broadcast_to
, but pytensor.tensor.random.utils.params_broadcast_shapes
still returns invalid broadcast shapes
Describe the issue:
pytensor.tensor.random.utils.params_broadcast_shapes
says that it performs numpy broadcasting on shape tuples. This works kind of fine, unless the shapes are not broadcastable with each other. In those cases,params_broadcast_shapes
will happily return a shape that is the maximum between the input shape tuples.This causes a set of problems down the line.
pytensor.tensor.random.utils.params_broadcast_shapes
is used by default inRandomVariable.infer_shape
. This causes potentially wrong shape inferences, that might raise an exception at runtime.pytensor.tensor.random.utils.params_broadcast_shapes
is used tobroadcast_to
, the resulting tensors will look like they would work fine, but they can lead to segfaults or kernel crashes at runtime.Reproducable code example:
Error message:
PyTensor version information:
Context for the issue:
No response