🐛 Describe the bug
Description
Exporting an LSTM model with dynamic shapes and calling .to_executorch() fails in ReplaceViewCopyWithViewPass because _ViewSpec recomputes shape_dynamism from concretized shapes (returning STATIC=0) while the base tensor retains DYNAMIC_BOUND=1.
Error
File ".../exir/passes/replace_view_copy_with_view_pass.py", line 159, in init
raise Exception(
Exception: _ViewSpec is incompatible with its base on creation.
It has shape_dynamism=0, but its base has shape_dynamism=1.
Versions
PyTorch version: 2.12.0+cpu
OS: Ubuntu 24.04.4 LTS (x86_64)
Python version: 3.11.15 (main, Mar 11 2026, 17:20:07) [GCC 14.3.0] (64-bit runtime)
CPU:
Architecture: x86_64
Versions of relevant libraries:
[pip3] executorch==1.4.0a0+82cf123
[conda] pytorch-tokenizers 1.1.0 pypi_0 pypi
[conda] torch 2.12.0+cpu pypi_0 pypi
[conda] torchvision 0.27.0+cpu pypi_0 pypi
Steps to Reproduce
import torch
from torch.export import Dim, export
from executorch.exir import to_edge_transform_and_lower
from torch.export._patches import register_lstm_while_loop_decomposition
class LSTM(torch.nn.Module):
def __init__(self, h):
super().__init__()
self.lstm = torch.nn.LSTM(h, h)
def forward(self, x, h0, c0):
out, (_, _) = self.lstm(x, (h0, c0))
return out
h = 512
x = torch.randn(64, 16, h)
h0, c0 = torch.randn(1, 16, h), torch.randn(1, 16, h)
model = LSTM(h)
dynamic_shapes = {"x": {0: Dim("seq_len", min=2, max=64)}, "h0": None, "c0": None}
with register_lstm_while_loop_decomposition():
exported_program = export(model, (x, h0, c0), dynamic_shapes=dynamic_shapes)
# This crashes:
to_edge_transform_and_lower(exported_program).to_executorch()
# Workaround (skips the pass):
# from executorch.exir import ExecutorchBackendConfig
# to_edge_transform_and_lower(exported_program).to_executorch(
# ExecutorchBackendConfig(remove_view_copy=False)
# )
🐛 Describe the bug
Description
Exporting an LSTM model with dynamic shapes and calling
.to_executorch()fails inReplaceViewCopyWithViewPassbecause_ViewSpecrecomputesshape_dynamismfrom concretized shapes (returning STATIC=0) while the base tensor retains DYNAMIC_BOUND=1.Error
File ".../exir/passes/replace_view_copy_with_view_pass.py", line 159, in init
raise Exception(
Exception: _ViewSpec is incompatible with its base on creation.
It has shape_dynamism=0, but its base has shape_dynamism=1.
Versions
PyTorch version: 2.12.0+cpu
OS: Ubuntu 24.04.4 LTS (x86_64)
Python version: 3.11.15 (main, Mar 11 2026, 17:20:07) [GCC 14.3.0] (64-bit runtime)
CPU:
Architecture: x86_64
Versions of relevant libraries:
[pip3] executorch==1.4.0a0+82cf123
[conda] pytorch-tokenizers 1.1.0 pypi_0 pypi
[conda] torch 2.12.0+cpu pypi_0 pypi
[conda] torchvision 0.27.0+cpu pypi_0 pypi
Steps to Reproduce