Massive increase in memory consumption between 1.0 and 1.1 / 1.2
🐛 Describe the bug
What changes were introduced between versions 1.0 and 1.1/1.2 that could explain why some models exported with XNNPACK delegates in ExecuTorch 1.1/1.2 consume nearly 3× more runtime memory compared to the same models exported with version 1.0?
I encountered this while exporting Kokoro modules using these scripts: first and second.
When profiling memory usage on Android (arm64-v8a), the combined runtime usage for both models is ~800 MB when exported with ExecuTorch 1.0, but suddenly increases to ~2.2 GB when exported with versions 1.1 or 1.2, without any changes in the models.
For reference, the export configurations used are:
python -m export.export_duration_predictor --bundled=true --input-size=inp-16 --max-tokens=32,64,128 --pad-lstm=true --dynamic=true --dtype=fp32
python -m export.export_synthesizer --input-size=inp-16 --dynamic=true --max-tokens=128 --max-duration=296 --dtype=fp32
Both models are exported with dynamic shapes enabled and include the LSTM padding fix (which pads LSTMs to a static sequence length).
Versions
Collecting environment information... PyTorch version: 2.11.0 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A
OS: macOS 26.1 (arm64) GCC version: Could not collect Clang version: 17.0.0 (clang-1700.3.19.1) CMake version: version 3.31.10 Libc version: N/A
Python version: 3.12.11 (main, Jun 3 2025, 15:41:47) [Clang 17.0.0 (clang-1700.0.13.3)] (64-bit runtime) Python platform: macOS-26.1-arm64-arm-64bit 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 Caching allocator config: N/A
CPU: Apple M4 Pro
Versions of relevant libraries: [pip3] executorch==1.2.0a0+0b0e2c5 [pip3] numpy==2.0.0 [pip3] pytorch_tokenizers==1.2.0 [pip3] torch==2.11.0 [pip3] torchao==0.17.0+git02105d46c [pip3] torchaudio==2.11.0 [pip3] torchdata==0.11.0 [pip3] torchsr==1.0.4 [pip3] torchtune==0.0.0 [pip3] torchvision==0.26.0 [conda] Could not collect
cc @GregoryComer @digantdesai @cbilgin
Thanks for the detailed report. I'm not aware of any expected reason for memory regression. I'll run through the instructions and see if I can reproduce the memory differential.
@IgorSwat I ran through the export on release/1.0 and release/1.1 and can't repro the memory increase on Android or Mac. I'm assuming this just means I'm not reproducing the issue you saw correctly. Here's how I did it. Can you clarify if there's anything different I should try? Thanks.
Export (from cloned kokoro-export repo):
python -m export.export_synthesizer \
--input-size=inp-16 --dynamic=true --max-tokens=128 \
--max-duration=296 --dtype=fp32 --output-dir=/tmp/kokoro-repro/v1.0
python -m export.export_duration_predictor \
--bundled=true --input-size=inp-16 --max-tokens=32,64,128 \
--pad-lstm=true --dynamic=true --dtype=fp32 --output-dir=/tmp/kokoro-repro/v1.0
Benchmark:
- Cross compiled
executor_runnerfor Android arm64-v8a. - Ran via adb on Pixel 7 Pro.
Measured data on a Pixel 7 Pro:
| v1.0 runner + v1.0 pte | v1.1 runner + v1.1 pte | |
|---|---|---|
| Synthesizer (after load) | 1412 MB | 1308 MB |
| Synthesizer (after exec) | 1591 MB | 1521 MB |
| Synthesizer planned buffer | 277 MB | 173 MB |
| Duration Pred (after load) | 1343 MB | 1343 MB |
| Duration Pred (after exec) | 1346 MB | 1347 MB |
| Duration Pred planned buffer | 4.0 MB | 4.6 MB |
@IgorSwat could you let us know anything else to reproduce the memory consumption hike?
@nil-is-all Yeah, I will try to prepare a sort of automatic reproduction mechanism or repo for this one. I hesitated a little bit to get around to it because there were other things and I thought this one might be quite tricky. Nevertheless, I will let you know If I finish the reproduction.
@nil-is-all @GregoryComer
I created a reproduction repo for the issue. You can just clone it and follow short instructions from README.md.
A couple of notes from me:
- I tested it on both physical device and emulator and it worked on both, altough emulator's behavior was a little bit weird - therefore I recommend testing it on a physical device.
- If everything works fine, you should see similar results to mine: where the same synthesizer exported with
ExecuTorch 1.0consumes~750 MBat peak, and the one exported withExecuTorch 1.2(or 1.1, the same effect should appear there) consumes~1500 MB. If you export with lower--max-tokensor--max-durationthe absolute values will get lower, but the pattern for 1.2 version consuming ~2x memory still persists. - Instead of using
executor_runner, the model is infered in a custom process on device, and memory is measured for this process withadb shell dumpsys meminfo. - I suspect that the reason for the issue is that something in either handling LSTMs or graphs with large amount of nodes had to change between the
1.0and1.1 / 1.2versions.
If there are any problems with the setup (yes, a significant part of it is vibecoded, so I expect there could be some hidden problems) I am here to answer any question.
Hey, any updates on this one 👀?
@GregoryComer @nil-is-all
Hi @IgorSwat , sorry for the delay in getting back to this. We'll reproduce based on your notes and get back shortly @JakeStevens could you take this up?
Hey @IgorSwat , can you try it out on a version >= 1.3.0? The leading theory is a one-line change that broke weight deduplication in 1.1/1.2 but is resolved in 1.3.
Specifically, tensor.name was appended to the SHA for the named_tensor key, so identical weights with different names would not be deduplicated.
This is no longer the case.
This may be your issue, please confirm and we can close if so, else can continue to investigate.
Hey @JakeStevens , I tested it and it indeed seems to be resolved on 1.3+. Not only the memory bug is resolved, the model runs quicker now. Thank you for fixing it!
Great, thanks for confirming! Close the issue