Repository navigation
Keep the view after a linear when only its shape bounds match - #24626
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24626
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit c8a750e with merge base dadc829 ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude /pr-review |
|
Claude finished @shoumikhin's task in 19m 25s —— View job PR Review: #24626. I found no blockers. The new symbolic comparison is correct and only removes views the old bound check also removed. Three minor follow-ups: XNNPACK's concrete linear metadata now keeps some no-op views with dynamic shapes, the same function has an older stale-metadata bug that the changed check still reads, and there are test gaps. Detailed reviewSummaryThe PR changes All findings come from reading the code. Python commands needed approval in this run, so I did not run the new test or the trigger models below. Code Quality
Testing
Performance
RecommendationApprove. The fix is correct and never removes a view the old check kept. The items above are minor or were already there before this PR, and can be follow-ups. |
09d8b8d to
aa88861
Compare
|
Thanks for the review. Fixed:
Static models still lower byte-identically with XNNPACK and Vulkan. |
|
@claude /pr-review |
|
Claude finished @shoumikhin's task in 26m 5s —— View job PR Review: #24626. No blockers; the issues are minor test gaps, mainly that the new transform tests mostly compare with eager instead of checking the rewritten graph, and that the new XNNPACK test covers only fp32 with a 2-D input. Detailed reviewSummaryThe PR removes the view after a linear only when the symbolic shapes are provably equal, rewires the linear to the dequantized input only when that view goes, and gives XNNPACK's Code Quality
Testing
RecommendationApprove. Nothing blocks the PR. The two-linear test is worth adding here, because that behavior is new and has no test. |
aa88861 to
27cd6ab
Compare
|
Thanks for the review. Fixed:
|
|
@claude /pr-review |
|
Claude finished @shoumikhin's task in 30m 45s —— View job PR Review: #24626. I found no blockers or correctness bugs, only two test gaps: the new qd8 XNNPACK test passes on main without reaching the changed code, and no transform test covers the fallback to the linear's own input when a dequantize node exists. Detailed reviewSummaryThe PR removes the view after a linear only when the symbolic shapes are provably equal, rewires the linear to the dequantized input only when that view goes, and gives XNNPACK's Testing
RecommendationApprove. Nothing blocks the PR. The qd8 test is worth fixing in this PR, because the description lists it as coverage for this change. |
AddmmToLinearTransform folds the views around a linear when the linear can produce the same shape on its own. It decided that by comparing the upper bounds of the two shapes. With dynamic shapes, two different shapes can have the same bounds. For example, with a and b both in [2, 8], the linear output [a, b, 8] and a following view to [b, a, 8] both have the bounds [8, 8, 8]. The view was then dropped, so the output had the shape [a, b, 8] instead of [b, a, 8]. A dim with no upper bound is compared by its example size, so the same happens when the example sizes are equal. XNNPACK, Vulkan and Samsung lowering run this transform. Inside a Vulkan delegate the swapped view above is dropped today. Now the transform compares the symbolic shapes, and drops the view only when they are known to be equal. Static shapes are plain integers, so their result is the same as before. XNNPACK's ConvertToLinearPass gave each linear it makes a tensor sized by the upper bounds of the op it replaces. The transform then could not prove that a view after a second linear keeps its shape, and kept it. The linear now takes the value of the op it replaces, so such a view still goes.
…goes When a linear reads a dequantized tensor through views, AddmmToLinearTransform points it at the dequantized tensor itself. That changes the shape of the linear output, from [6, 8] to [2, 3, 8] for an input of [2, 3, 16], and it did this even when no view after the linear was removed to make up for it. It also redirected every other reader of the view, and left the linear's shape metadata at the old shape, so a later linear could drop a view based on that stale shape. For example, view(-1, 16) -> linear -> output returned [2, 3, 8] instead of [6, 8], and view(-1, 16) -> linear -> linear -> view(-1, 4) returned [2, 3, 4] instead of [6, 4]. Now the linear reads the dequantized tensor only when that makes its output match the view after it, and that view is removed in the same step. Only the linear is rewired, and it takes the shape of the removed view. Otherwise it keeps its input, and a view that does not change its output shape still goes. The dequantized tensor no longer has to have a single reader, so two linears that read one dequantized input through their own views are both rewired, and their views go.
27cd6ab to
c8a750e
Compare
|
Thanks for the review. Both test gaps are fixed.
|
|
@claude /pr-review |
|
Claude finished @shoumikhin's task in 25m 11s —— View job PR Review: #24626. I found no blockers, only three minor issues: the rewire can also replace the linear's weight (main has this too), no test covers the guard that now decides the rewire, and the docstring doesn't say that removing the view now needs symbolic shapes. Detailed reviewSummaryThe PR removes the view after a linear only when the symbolic shapes are provably equal. It points the linear at the dequantized input only when that view goes, and it gives XNNPACK's What I could not do in this run:
Code Quality
Testing
API Design
RecommendationApprove. Nothing blocks the PR. All three items are minor, and main already has the first one. |
|
Thanks. Merging as is. The guard test, the docstring note on symbolic shapes, and the weight case go into a follow-up PR together with the addmm fixes. |
|
Follow-up for the review points: #24658 |
What is wrong today
AddmmToLinearTransformremoves the view after a linear when the linear already produces that shape. It compares upper bounds, and two different dynamic shapes can have the same bounds.Example: a dequantized input
[a, b, 16], withaandbboth in[2, 8], goes throughview(-1, 16), a linear, andview(b, a, 8). The transform points the linear at the dequantized tensor, so its output[a, b, 8]and the view[b, a, 8]both have the bounds[8, 8, 8]. The view is removed and the output has the wrong shape.The transform points a linear at the dequantized tensor even when no view after it is removed. That changes its output shape:
view(-1, 16) -> linearon a[2, 3, 16]input returns[2, 3, 8]instead of[6, 8].XNNPACK, Vulkan and Samsung lowering run this transform, and so does the LLM export through
ConvertToLinearPass.What this change does
ConvertToLinearPassnow gives each linear it makes the value of the op it replaces, not a fixed-size tensor, so a no-op view after a second linear still goes.Testing
backends/transforms/test/test_addmm_mm_to_linear.py: the swapped view is kept, with bounded and unbounded dims; a view back to the linear's shape is still removed, and the linear takes its value; each linear reads the dequantized tensor only when its view goes, not for a view that only restates its shape; two linears sharing one dequantized tensor both lose their views. Each checks the graph and compares with eager, and each fails on main.backends/xnnpack/test/passes/test_convert_to_linear.py: a no-op view after two linears with a dynamic batch is removed, as on main; the swapped view after a linear is kept with both dims dynamic (fails on main).