pytorch / pytorch/executorch

_ViewSpec is incompatible with its base on creation

Open
#20,008 2 comments 0 reactions 1 assignee View on GitHub

@JacobSzwejbka is already working on this.

Since Jul 10, 2026.

module: exir
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

🐛 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)
# )



cc @JacobSzwejbka @angelayi

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.