Exporting with greedy algorithm fails due to not providing a memory offse
Open
@JacobSzwejbka is already working on this.
Since Sep 15, 2025.
module: exir
- Dominant language
- Python
- Stars
- 5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 581
Description
🐛 Describe the bug
When I try to export my model to executorch using the greedy Algorithm, I get an error because of a padding operation I do inside my model. Executorch complains that I did not provide a memory offset yet documentation does not offer any guidance on how to provide.
Here is my export code:
import torch
from neural_networks.Simple_LSTM import SimpleLSTM
from executorch.exir import to_edge_transform_and_lower
import torch
from torch.export import export, Dim
from executorch.exir import to_edge_transform_and_lower
from executorch.exir import EdgeCompileConfig, to_edge_transform_and_lower
from executorch.runtime import Runtime
from executorch import exir
from executorch.exir.passes import MemoryPlanningPass
from executorch.exir.memory_planning import greedy
model = SimpleLSTM(window_size=240) # your original model
checkpoint = torch.load("SimpleLSTM.pth", weights_only=False)
model.load_state_dict(checkpoint)
model.eval()
# Use exactly the inputs your forward expects
sample_inputs = (torch.randn(1, 1, 240),) # match forward(self, x)
config = EdgeCompileConfig(
_check_ir_validity=True,
_use_edge_ops=True
)
ep = export(model, sample_inputs, dynamic_shapes = {
"x": { # channel dimension
0: Dim.AUTO,
1: Dim.AUTO,
2: Dim.AUTO, # sequence length
}
})
edge_program = to_edge_transform_and_lower(ep, compile_config=config)
exec_prog = edge_program.to_executorch(
exir.ExecutorchBackendConfig(
memory_planning_pass=MemoryPlanningPass(
allow_lifetime_and_storage_overlap=True,
alloc_graph_input=False,
alloc_graph_output=False,
memory_planning_algo=greedy
)
)
)
with open("simple_lstm.pte", "wb") as f:
exec_prog.write_to_file(f)
Trace:
/home/dev/project/venv/lib/python3.11/site-packages/executorch/exir/dialects/edge/_ops.py:9: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
Traceback (most recent call last):
File "/home/dev/project/lower_to_executorch.py", line 35, in <module>
exec_prog = edge_program.to_executorch(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/dev/project/venv/lib/python3.11/site-packages/executorch/exir/program/_program.py", line 114, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/dev/project/venv/lib/python3.11/site-packages/executorch/exir/program/_program.py", line 1606, in to_executorch
new_gm_res = memory_planning_pass.run( # pyre-ignore[16]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/dev/project/venv/lib/python3.11/site-packages/executorch/exir/passes/memory_planning_pass.py", line 165, in run
verifier.verify_storage_reuse()
File "/home/dev/project/venv/lib/python3.11/site-packages/executorch/exir/memory_planning.py", line 173, in verify_storage_reuse
has_storage_overlap = Verifier.storage_overlap(lhs_spec, rhs_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/dev/project/venv/lib/python3.11/site-packages/executorch/exir/memory_planning.py", line 116, in storage_overlap
internal_assert(
File "/home/dev/project/venv/lib/python3.11/site-packages/executorch/exir/error.py", line 32, in internal_assert
raise InternalError(assert_msg)
executorch.exir.error.InternalError: TensorSpec(dtype=torch.float32, shape=[1, 1, 249], layout=torch.strided, is_sparse=False, shape_dynamism=0, const=False, requires_grad=False) should have specified memory offset
Versions
collect_env.py 100%[==============================================================================================>] 29,97K --.-KB/s in 0,002s
2025-09-12 16:11:14 (13,5 MB/s) - ‘collect_env.py’ saved [30687/30687]
Collecting environment information...
PyTorch version: 2.8.0+cu128
Is debug build: False
CUDA used to build PyTorch: 12.8
ROCM used to build PyTorch: N/A
OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0
Clang version: Could not collect
CMake version: version 3.31.6
Libc version: glibc-2.35
Python version: 3.11.13 (main, Jun 4 2025, 08:57:29) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.8.0-79-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Vendor ID: GenuineIntel
Model name: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
CPU family: 6
Model: 140
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
Stepping: 1
CPU max MHz: 4700,0000
CPU min MHz: 400,0000
BogoMIPS: 5606.40
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l2 cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear ibt flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 192 KiB (4 instances)
L1i cache: 128 KiB (4 instances)
L2 cache: 5 MiB (4 instances)
L3 cache: 12 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-7
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Versions of relevant libraries:
[pip3] executorch==0.7.0
[pip3] numpy==2.3.2
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-nccl-cu12==2.27.3
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] onnx==1.19.0
[pip3] onnx-ir==0.1.7
[pip3] onnxruntime==1.22.1
[pip3] onnxscript==0.4.0
[pip3] pytorch-lightning==2.4.0
[pip3] torch==2.8.0
[pip3] torchao==0.12.0
[pip3] torchmetrics==1.8.2
[pip3] triton==3.4.0
[conda] Could not collect
cc @JacobSzwejbka @angelayi
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.