-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Bug] [Relax] Segmentation fault when executeing inference for the IR with branch in the runtime #17348
Comments
@Lunderberg @tqchen @Hzfengsy @junrushao |
Looks like this is a bug in the Before `StaticPlanBlockMemory` (click to expand)@R.function
def main(cond: R.Tensor((), dtype="bool"), x: R.Tensor((1,), dtype="float32")) -> R.Tensor(
(1,), dtype="float32"
):
R.func_attr({"relax.force_pure": True})
cls = ModBeforeStaticPlanBlockMemory
if cond:
alloc = R.builtin.alloc_tensor(
R.shape([1]), R.dtype("float32"), R.prim_value(0), R.str("global")
)
cls.add(x, x, alloc)
gv = alloc
alloc1 = R.builtin.alloc_tensor(
R.shape([1]), R.dtype("float32"), R.prim_value(0), R.str("global")
)
cls.add(x, x, alloc1)
gv1 = alloc1
alloc2 = R.builtin.alloc_tensor(
R.shape([1]), R.dtype("float32"), R.prim_value(0), R.str("global")
)
cls.multiply(gv, gv1, alloc2)
y_then = alloc2
y: R.Tensor((1,), dtype="float32") = y_then
else:
alloc3 = R.builtin.alloc_tensor(
R.shape([1]), R.dtype("float32"), R.prim_value(0), R.str("global")
)
cls.multiply(x, x, alloc3)
gv3 = alloc3
alloc4 = R.builtin.alloc_tensor(
R.shape([1]), R.dtype("float32"), R.prim_value(0), R.str("global")
)
cls.multiply(x, x, alloc4)
gv4 = alloc4
alloc5 = R.builtin.alloc_tensor(
R.shape([1]), R.dtype("float32"), R.prim_value(0), R.str("global")
)
cls.add(gv3, gv4, alloc5)
y_else = alloc5
y: R.Tensor((1,), dtype="float32") = y_else
return y After `StaticPlanBlockMemory` (click to expand)@R.function
def main(cond: R.Tensor((), dtype="bool"), x: R.Tensor((1,), dtype="float32")) -> R.Tensor(
(1,), dtype="float32"
):
R.func_attr({"relax.force_pure": True})
cls = ModAfterStaticPlanBlockMemory
if cond:
storage = R.memory.alloc_storage(
R.shape([4]), R.prim_value(0), R.str("global"), R.dtype("float32")
)
alloc = R.memory.alloc_tensor(
storage, R.prim_value(0), R.shape([1]), R.dtype("float32")
)
cls.add(x, x, alloc)
gv = alloc
storage1 = R.memory.alloc_storage(
R.shape([4]), R.prim_value(0), R.str("global"), R.dtype("float32")
)
alloc1 = R.memory.alloc_tensor(
storage1, R.prim_value(0), R.shape([1]), R.dtype("float32")
)
cls.add(x, x, alloc1)
gv1 = alloc1
alloc2 = R.builtin.alloc_tensor(
R.shape([1]), R.dtype("float32"), R.prim_value(0), R.str("global")
)
cls.multiply(gv, gv1, alloc2)
y_then = alloc2
y: R.Tensor((1,), dtype="float32") = y_then
else:
storage: R.Object
storage1: R.Object
alloc3 = R.memory.alloc_tensor(
storage, R.prim_value(0), R.shape([1]), R.dtype("float32")
)
cls.multiply(x, x, alloc3)
gv3 = alloc3
alloc4 = R.memory.alloc_tensor(
storage1, R.prim_value(0), R.shape([1]), R.dtype("float32")
)
cls.multiply(x, x, alloc4)
gv4 = alloc4
alloc5 = R.builtin.alloc_tensor(
R.shape([1]), R.dtype("float32"), R.prim_value(0), R.str("global")
)
cls.add(gv3, gv4, alloc5)
y_else = alloc5
y: R.Tensor((1,), dtype="float32") = y_else
return y Prior to Investigating to see if there's a clear cause for this. |
After looking into it, it looks like there may be some larger fixes required. Currently, the I've put together a few unit tests to experiment with it (in this dev branch). Depending on which expressions are moved into the conditional, it either results in out-of-scope access of the |
@Lunderberg Thanks for your deep investigation and the fixing plan. |
Actual behavior
Steps to reproduce
cc @junrushao
The text was updated successfully, but these errors were encountered: