Skip to content

A graph replace that changes the type from dynamic to static can lead to miscompilation #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aseyboldt opened this issue May 2, 2024 · 2 comments

Comments

@aseyboldt
Copy link
Member

aseyboldt commented May 2, 2024

Description

If I replace a tensor with shape (None,) by one with static shape (1,) llvm aborts during codegen for me. Maybe some rewrite doesn't behave properly, and we produce invalid llvm code somewhere?

import pytensor.tensor as pt
import pytensor

x = pt.vector("x")
logp = -(x ** 2).sum()

pytensor.dprint(logp, print_type=True)

# Works if I set the shape to x.shape
#x_known = pt.vector("x_known", shape=x.type.shape)
x_known = pt.vector("x_known", shape=(1,))

logp = pytensor.graph_replace(logp, {x: x_known})

print("after")
pytensor.dprint(logp, print_type=True)
pytensor.function((x_known,), logp, mode=pytensor.compile.NUMBA)

Maybe we should just check that we don't change the type in a graph_replace?

@ricardoV94
Copy link
Member

ricardoV94 commented May 2, 2024

Here is a more direct example:

import pytensor.tensor as pt
import pytensor

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

func = pytensor.function((x,), pow_out, mode="NUMBA")
pytensor.dprint(func, print_destroy_map=True)
func([0.5])

Edit: Updated

@aseyboldt
Copy link
Member Author

I also opened a numba issue: numba/numba#9554

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants