Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pytensor/link/jax/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pytensor.compile.mode import Mode
from pytensor.gradient import DisconnectedType
from pytensor.graph import Apply, Op, Variable
from pytensor.tensor.basic import infer_static_shape
from pytensor.tensor.basic import as_tensor, infer_static_shape
from pytensor.tensor.type import TensorType


Expand Down Expand Up @@ -384,7 +384,7 @@ def _find_output_types(
try:
shape_evaluation_function = function(
[],
resolved_input_shapes,
[as_tensor(s, dtype="int64") for s in resolved_input_shapes],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyTensor was complaining that we were trying to define tuples as outputs

on_unused_input="ignore",
mode=Mode(linker="py", optimizer="fast_compile"),
)
Expand All @@ -394,7 +394,7 @@ def _find_output_types(
"Please provide inputs with fully determined shapes by "
"calling pt.specify_shape."
) from e
resolved_input_shapes = shape_evaluation_function()
resolved_input_shapes = [tuple(s) for s in shape_evaluation_function()]

# Determine output types using jax.eval_shape with dummy inputs
output_metadata_storage = {}
Expand Down Expand Up @@ -422,6 +422,7 @@ def wrapped_jax_function(input_arrays):
output_static = output_metadata_storage["output_static"]

# If we used shape evaluation, set all output shapes to unknown
# TODO: This is throwing away potential static shape information.
if requires_shape_evaluation:
output_types = [
TensorType(
Expand Down
12 changes: 12 additions & 0 deletions tests/link/jax/test_wrap_jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,15 @@ def f(x, y):
compare_jax_and_py([x, y], [out, *grad_out], test_values)
else:
compare_jax_and_py([x, y], [out], test_values)


def test_mixed_static_shape():
x_unknown = shared(np.ones((3,)))
x_known = shared(np.ones((4,)), shape=(4,))

def f(x1, x2):
return jax.numpy.concatenate([x1, x2])

assert wrap_jax(f)(x_known, x_known).type.shape == (8,)
assert wrap_jax(f)(x_known, x_unknown).type.shape == (None,)
assert wrap_jax(f)(x_unknown, x_known).type.shape == (None,)
Loading