Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (6): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201768
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Unclassified FailureAs of commit 60c457d with merge base 836c141 ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
This PR needs a
|
Withdrawn: the automated review of d51a80b found nothing blocking.
Stack from ghstack (oldest at bottom):
First consumer of the compile-time TunableOp worker, and the whole point of the
"tune" mode: widening what a tuning run records so runtime actually finds it.
A solution is keyed on an exact shape signature, so tuning only the traced shape
leaves runtime missing the moment the dynamic dim differs, which for these models
is almost always. When aten wins the autotune for a GEMM with a single dynamic dim,
this re-benchmarks it across a ladder of sizes of that dim so several signatures
land in the results file.
The ladder covers the GEMM variants TunableOp tunes:
mm,addmm,bmm,baddbmmand_scaled_mm.addmmandbaddbmmtake the bias first, so theoperands are read from a different position for those two.
The reduction dim K is never bucketed: a solution is only valid for the K it was
tuned at. That guard also rejects attention-style ops where one symbol spans both N
and K, where overriding the symbol would change two dims at once and fabricate
degenerate shapes.
The ladder walks the symbol, not the dim. A dim can be an expression such as
200*s, and stepping the dim itself through powers of two tunes sizes the dim cannever take, since no power of two is a multiple of 200. Walking
sand evaluatingthe expression yields 400, 800, 1600 ... instead, which are the values that actually
reach the kernel. For a bare-symbol dim the two are identical, so the common case is
unchanged.
The domain is the symbol's declared range, read via
shape_env.bound_sympy(s). Thatis what the symbol may take at runtime, unlike the traced hint.
bound_sympyreasonsover
var_to_rangealone and ignores guards and runtime asserts, so it can be looserthan the true bound; looser is the safe direction here, since under-covering means a
runtime miss.
The "too small to be worth a tuning job" threshold of 8 is applied to the resulting
dim, not to the symbol. The two are only the same for a bare-symbol dim: for
200*sthe smallest symbol values already give substantial GEMMs (s=2is a dim of400), so starting the walk at 8 would skip sizes runtime genuinely asks for.
Two ceilings, both anchored to what the model serves
A declared range reports what a symbol MAY take, not what it does, and on these nets
it carries almost no information: every symbol observed reports
[2, 2**31-1]. Sothe declared bound never binds, and whatever backstop sits behind it becomes the real
ceiling for every GEMM.
_TUNABLEOP_MAX_DYN_SYM = 16384is that backstop, replacinga pair of constants that each failed in a different direction.
In symbol space,
min(declared_hi, max(16384, sym_hint)). A genuinely narrowdeclared range still wins; the cap only stops an uninformative one running away. It
is raised to the traced hint so the walk can always reach the size actually served.
In dim space,
max(16384, served_dim). The symbol cap alone is not enough,because it cannot see a multiplier: with
sbounded at 16384, a96*sdim stillreaches 1572864. A flat dim cap is not enough either -- it truncates legitimate
coverage, cutting a GEMM served at 294912 down to 12288. Anchoring the dim ceiling to
the dim's value at the traced hint gives a bound that cannot fall below what the
model actually runs, while still bounding the runaway case.
Each bucket's benchmark request is built by copying the winner's request and
rebuilding its tensor metas at that size, reusing Inductor's meta machinery instead
of reconstructing the GEMM by hand. Substituting the symbol into each size expression
is also what keeps an expression dim on values it can take, and it scales every other
dim built from the same symbol consistently. Deriving the strides the same way is not
safe: a stride expression is not a size-product formula in the dynamic symbol, so
substituting into a bare-symbol batch stride collapses it to that value instead of
value * inner_dims, producing overlapping metas whose backing buffers are far smaller
than the kernel will address. Strides are therefore recomputed dense in the tensor's
own fill order, taken from the traced real-size strides where outer dims genuinely
have the largest strides; taking the order from the overridden strides could reorder
dims and silently turn a plain GEMM into a transposed one.
Each bucket is a separate worker job, so a fault costs one size and restarts the
worker rather than killing the compile. The whole GEMM shares one deadline and skips
the remainder once it is spent; each submission is given the entire remaining budget
rather than a per-bucket slot.
The traced shape goes first, then the rest largest-first. The per-GEMM budget is
spent in order, so whichever end is walked last is the end dropped when it runs out.
Ascending order sacrificed the sizes nearest the shape actually served while
faithfully keeping 8, 16 and 32 -- observed on a K=39160 GEMM whose ladder stopped at
256 with the traced dim at 3072. Pure largest-first has the opposite failure: it can
spend the whole budget on the biggest sizes -- the likeliest to fault -- before
reaching the one size runtime is known to ask for.
The ladder can be turned off.
TORCHINDUCTOR_AUTOTUNE_TUNABLEOP_LADDER=0stopsit. At this commit Inductor then submits no tuning at all: the traced shape is covered
only by TunableOp's own in-process path, which needs
PYTORCH_TUNABLEOP_ENABLEDset inthe compiling process. The ladder is nearly all of the tuning cost -- on the heavier
nets the difference between minutes and hours -- and it exists so that cost can be
skipped, and so what the ladder actually buys can be measured by diffing runtime
misses with and without it.
A
log.debugline per bucket records its wall time and status. It is the onlyrecord of what a bucket costs when it succeeds, since the existing logs report
failures only, and that curve is what any future per-bucket budget would have to be
sized against.
One behaviour change outside the ladder itself.
A ladder bucket that times out or crashes is retried at most
_TUNABLEOP_MAX_BUCKET_ATTEMPTS(2) times per process, then left alone. Without thecap a reproducibly hanging rung is never recorded, so every identical layer retries
it on a fresh per-GEMM budget and spends it before reaching the rungs that work.
Note that tuning happens while lowering, so a warm FxGraphCache serves the graph and
the ladder never runs: a tune pass has to start from a cold cache, or set
force_disable_caches. #201769 lifts that constraint with a tune-mode bypass inCacheabilityValidator.Inert unless
autotune_tunableop_modeis set to "tune"; it defaults to "off", so noexisting compile changes behaviour.
Differential Revision: D116493595
Differential Revision: D116493595