Fix control flow output memory aliasing - #21818
Open
JacobSzwejbka wants to merge 2 commits into
Open
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21818
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 58f7f6a with merge base 914705c ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Contributor
Author
|
This approach is wrong gonna try to fix the memory planning issue rather then just deepcopying |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #21490.
Control-flow branches intentionally share a memory arena, but their tensor outputs escape through
MoveCall. The planner previously allowed a later higher-order operation to reuse branch storage while the earlier logical output was still live.Memory planning now assigns each higher-order-op submodule arena a lifespan at its call site. For
cond, that lifespan extends through the last use of its logical outputs. The true and false branches retain the same arena location because they are mutually exclusive, while consecutive conditionals receive non-overlapping storage when their outputs are simultaneously live. The emitter continues to useMoveCall; no tensor copy is added.Regression coverage checks the original nested-condition and mutable-state failure, verifies non-overlapping allocations for consecutive conditional outputs, and asserts that branch results are emitted with
MoveCall.Test plan
pytest -q exir/tests/test_memory_planning.py::TestCond::test_consecutive_cond_output_lifetime exir/emit/test/test_emit.py::TestEmit::test_emit_cond exir/emit/test/test_emit.py::TestEmit::test_emit_cond_output_lifetime(3 passed)pytest -q exir/tests/test_memory_planning.py -k "not custom_kv_cache_shared_buffers"(37 passed, 1 deselected; the installed custom-op library is binary-incompatible with the local Torch build)pytest -q exir/emit/test/test_emit.py::TestEmit -k "not test_emit_sym_ite and not test_emit_sym_not"(68 passed, 2 skipped, 2 deselected; the installed ExecuTorch 1.3.1 runtime does not contain those current prim kernels)python -m ufmt check exir/memory_planning.py exir/tests/test_memory_planning.py exir/emit/_emitter.py exir/emit/test/test_emit.pypython -m flake8 exir/memory_planning.py exir/tests/test_memory_planning.py exir/emit/_emitter.py exir/emit/test/test_emit.pyAuthored with Codex.