Skip to content

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

@aseyboldt

Description

@aseyboldt

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions