Repository navigation
[inductor] pad_mm: benchmark padded operands in the layout the graph will use instead of contiguous - #204782
[inductor] pad_mm: benchmark padded operands in the layout the graph will use instead of contiguous#204782LuFinch wants to merge 1 commit into
Conversation
PR Status: missing actionable issueAuto PR Triage did not find either of the following when it checked this PR:
Such PRs are a low priority for maintainers to review and might not get a response given the very high volume of PRs we receive. Please focus on If one of these applies, add the matching line to the PR description. If there is no 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/204782
Note: Links to docs will display an error until the docs builds have been completed.
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
1 similar comment
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
This PR needs a
|
should_pad_benchdecides whether shape padding is profitable by timing an unpaddedmm against a padded one. The padded operands it times can have a different memory
layout from the ones the compiled graph actually produces, so the decision can be
based on a kernel that is never run.
For example,
aten.constant_pad_ndalways materializes a contiguous output. Inductor lowersconstant_pad_ndas a pointwise op and preserves the stride order of its input.Padding a transposed operand therefore gives a contiguous tensor in eager and a
transposed one in the compiled graph.
The
mmbehind annn.Linearhasmat2 = weight.t(),which is column major. Whenever such an mm is a padding candidate, the benchmark
times a contiguous weight while the graph runs a transposed one.
Why it matters
The two layouts are not interchangeable in the GEMM backends. On an Intel Arc Pro
B60 with oneDNN 3.14,
benchdnn --matmul --dt=f16:f16:f16 98304x200:200x200:wtag=ab(contiguous, what the benchmark times)wtag=ba(transposed, what the graph runs)A 2.4x gap, and the benchmark only ever sees the fast side of it.
timm/gmlp_s16_224f16 inference trips on this. Traced decision for the one mm itbenchmarks,
mat1=[98304, 196] stride=(196, 1),mat2=[196, 196] stride=(1, 196):The threshold is 1.1, so padding wins by measuring the wrong layout. The benchmark has always
measured the padded operand in the wrong layout; it only changes the outcome once
the two layouts' timings diverge far enough to cross the 1.1 threshold.
Fix
Pad through a permuted view in the benchmark so the timed operand keeps the stride
order the graph will produce:
The permutation is derived from the strides rather than special cased for 2D, so
bmmoperands and arbitrary stride orders are handled too. When the input isalready contiguous the helper returns
aten.constant_pad_ndunchanged, so modelswhose padded operands are contiguous see no behavior change at all.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo