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 (7): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201767
Note: Links to docs will display an error until the docs builds have been completed. ⏳ 3 Pending, 1 Unrelated FailureAs of commit aff7b6b with merge base 836c141 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
This PR needs a
|
Pull Request resolved: #201767 Infrastructure shared by the two compile-time TunableOp passes that follow in this stack. Nothing calls it yet. `aten_tunableop_mode` is a single tri-state config rather than a pair of booleans because the passes are mutually exclusive: "tune" builds the results file, "reuse" consumes it. An enum makes that structural instead of an invariant every call site has to re-assert. The names follow the vocabulary already used in `TuningResultsManager::Lookup`, which distinguishes the reuse path from an actual tuning pass. Both passes benchmark GEMMs in a worker process rather than in the compiling process, because hipBLASLt tuning can abort the process with an uncatchable fault or hang indefinitely. Neither is survivable inline. The worker is a dedicated `TuningProcess`, not Inductor's shared `TuningProcessPool`. TunableOp's enable/tuning flags are process-global, so leaving them set in a worker that also benchmarks triton candidates would tune unrelated GEMMs, distort their timings and append their signatures to the results file. It is also one worker per compile rather than one per GEMM. Process startup dominates this work otherwise, and `TuningProcess` launches a bare interpreter over a pipe instead of re-running the parent binary's bootstrap the way a multiprocessing spawn does for every launch. A hang leaves the worker killed by `get()` and a crash leaves it closed; either way the next submission restarts it, and the restarted process re-reads the results file, so solutions recorded before the fault survive. `submit` reports faults as an `Outcome` status rather than raising, since a compile has to continue even when a GEMM cannot be benchmarked. ghstack-source-id: 454857423 @exported-using-ghexport Differential Revision: [D116493592](https://our.internmc.facebook.com/intern/diff/D116493592/)
Withdrawn: the automated review of d702e05 found nothing blocking.
Withdrawn: the automated review of 90958c7 found nothing blocking.
There was a problem hiding this comment.
Automated review of 61b524e: nothing blocking; ready for human review.
This PR adds the cuda.autotune_tunableop_mode and cuda.autotune_tunableop_timeout configs and a dedicated, long-lived TuningProcess worker (torch/_inductor/tunableop.py) that compile-time TunableOp passes will use to benchmark GEMMs. Recommendation: Approve. Every remaining point is non-blocking, and none of the earlier blocking findings is still present.
⚪ 7 non-blocking findings
pytorch/torch/_inductor/config.py
Line 3071 in 61b524e
Non-blocking: invalid timeout values make every GEMM fail and restart the worker. TORCHINDUCTOR_AUTOTUNE_TUNABLEOP_TIMEOUT is parsed with a bare float(), and submit passes it straight to TuningProcess.get selector.select(timeout). With inf, EpollSelector.select raises OverflowError from math.ceil(timeout * 1e3) (NaN raises ValueError). get() then kills the child, and submit returns "error" from the except Exception branch at tunableop.py:503. With 0 or a negative value the wait becomes a non-blocking poll, so every GEMM comes back "timeout". In each case every GEMM pays a spawn plus a kill, and only the first fault of each kind reaches WARNING. Fix: reject values that are not positive and finite, or map inf/<= 0 to None for an unbounded wait.
pytorch/torch/_inductor/tunableop.py
Line 258 in 61b524e
Non-blocking: _kill_and_reap logs a spurious ERROR on every faulting GEMM. When the job raised, or a generic exception or BaseException came through, worker.running is still True. process.kill() sends SIGKILL. Then worker.kill() checks alive(), sees poll() still returning None because the child hasn't died yet, logs "Sending SIGKILL to autotune subprocess" at ERROR, and signals again. Fix: call process.kill() directly only when not worker.running, or follow it with worker.close() instead of worker.kill().
Non-blocking: the real-worker teardown never runs. TunableOpRealWorkerTest.setUp (719-721) and test_real_job_tunes_and_appends_to_shared_file (865-867) register addCleanup(tunableop.shutdown_worker) before the setattr(tunableop, "_worker"/"_worker_key", None) cleanups. Cleanups run in reverse order, so _worker is already None when shutdown_worker runs, and _shutdown_locked does nothing. Each test ends on an "ok" submission, so a live child is left behind with no sentinel and no bounded wait. It exits only after GC closes its pipes, with a "subprocess is still running" ResourceWarning. In the GPU test the child keeps its CUDA context past the end of the test. Fix: drop the two setattr cleanups (_shutdown_locked already resets both globals), or register shutdown_worker last.
Non-blocking: the round-trip test can pass without testing the conversion. TunableOpSettingsRoundTripTest (839-845) sets the rotating buffer to 4 MB. On a GPU whose L2 is exactly 4 MiB (e.g. T4), _rotating_buffer_mb returns -1 ("use L2"). Setting -1 reads back as L2, which is also 4 MiB, so the assertion passes and the bytesMB path never runs. A broken conversion would pass there too. Fix: add self.assertEqual(stamped, 4), or pick a size different from the device's L2.
Non-blocking: the GENERIC classes (TunableOpWorkerTest, BenchmarkJobCallTest, TunableopModeValidationTest, TunableOpRealWorkerTest) break test/REVIEW.md Rule 3 ("No accelerator APIs: torch.cuda.*"). Besides the mock.patch("torch.cuda.") targets and the torch.device("cuda", N) metadata, some calls reach the real API. _submit/_submit_with_fault (94-99, 294-310) patch only current_device and get_filename, so snapshot_settings calls the real torch.cuda.tunable getters and torch.cuda.get_device_properties. On a GPU host, get_rotating_buffer_size goes through getCurrentDeviceProperties() in C++ and creates a CUDA context in the test process. test_valid_modes_do_not_warn (695-702) calls the real torch.cuda.is_available(), so on a GPU host its assertNoLogs depends on the PYTORCH_TUNABLEOP_* environment variables. Fix: patch snapshot_settings and is_available in the generic classes, or reclassify the classes that need real torch.cuda as CUDA.
Non-blocking, carried over from the last review: duplicate test. test_a_failure_before_the_worker_is_also_reported (337) is a subset of test_setup_failure_does_not_restart_worker (377). Both patch current_device to raise RuntimeError("no context") and assert "error", and 377 also checks that the existing worker survives. Fix: move the assertIsNone(outcome.time) into 377 and delete 337.
pytorch/torch/_inductor/config.py
Line 3071 in 61b524e
Non-blocking: the timeout config has no unit in its name. cuda.autotune_tunableop_timeout doesn't follow the _seconds suffix of the neighbouring autotune timeouts (max_autotune_subproc_result_timeout_seconds, precompilation_timeout_seconds). Renaming it and its env var costs nothing now but would be a BC change later.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
Stack from ghstack (oldest at bottom):
Infrastructure shared by the two compile-time TunableOp passes that follow in this
stack. Nothing calls it yet.
cuda.autotune_tunableop_modeis a single tri-state config rather than a pair ofbooleans
because the passes are mutually exclusive: "tune" builds the results file, "reuse"
consumes it. An enum makes that structural instead of an invariant every call site
has to re-assert. The names follow the vocabulary already used in
TuningResultsManager::Lookup, which distinguishes the reuse path from an actualtuning pass. It is set by
TORCHINDUCTOR_AUTOTUNE_TUNABLEOP_MODE, andcuda.autotune_tunableop_timeout(TORCHINDUCTOR_AUTOTUNE_TUNABLEOP_TIMEOUT,default 900s) bounds the wait per GEMM, since hipBLASLt tuning can hang. Both
share the prefix of the existing
cuda.autotune_tunableop_dynamic_dims_wildcard.Both passes benchmark GEMMs in a worker process rather than in the compiling
process, because hipBLASLt tuning can abort the process with an uncatchable fault
or hang indefinitely. Neither is survivable inline.
The worker is a dedicated
TuningProcess, not Inductor's sharedTuningProcessPool. TunableOp's enable/tuning flags are process-global, so leavingthem set in a worker that also benchmarks triton candidates would tune unrelated
GEMMs, distort their timings and append their signatures to the results file.
It is also one worker per compile rather than one per GEMM. Process startup
dominates this work otherwise, and
TuningProcesslaunches a bare interpreter overa pipe instead of re-running the parent binary's bootstrap the way a
multiprocessing spawn does for every launch. A hang leaves the worker killed by
get()and a crash leaves it closed; either way the next submission restarts it,and the restarted process re-reads the results file, so solutions recorded before
the fault survive.
submitreports faults as anOutcomestatus rather than raising, since a compilehas to continue even when a GEMM cannot be benchmarked.
@exported-using-ghexport
Differential Revision: D116493592
Differential Revision: D116493592