Repository navigation
Conversation
Several independent optimizations to reduce inductor test overhead: **ISA subprocess caching** (`cpu_vec_isa.py`): Cache the result of CPU vector ISA load-check subprocesses using `.load_ok` marker files. Each `check_build()` call spawns a Python subprocess that imports torch to verify a compiled .so can be loaded (~2s each, 6 checks per process). The compilation result was already cached on disk, but the load verification subprocess ran every time. **Lazy evaluation** (`inductor_utils.py`): Defer expensive module-level computations — `RUN_CPU` (triggers ISA checks), `HAS_PALLAS`/`HAS_TPU` (imports JAX), and heavy imports like `async_compile`, `codegen.wrapper`, `compile_fx`, `GraphLowering` — until actually needed. Most test files only need simple constants like `HAS_GPU` and `RUN_GPU`. **Shared Triton cache** (`utils.py`, `test_case.py`): Add `share_triton` parameter to `fresh_cache()`. When enabled, Triton compiled kernels are placed in a persistent shared directory instead of the per-test temp dir. Triton compilation is a pure function of the kernel source, so sharing is safe. `InductorTestCase` enables this by default; `test_codecache.py` classes that explicitly delete/inspect the Triton cache directory opt out via `_share_triton_cache = False`. **Autotune config limits** (`config.py`, `triton.py`, `flex_flash_attention.py`): Add `test_configs.max_flex_configs` (similar to existing `max_mm_configs`) and set both to 2 in `InductorTestCase`. This limits the number of Triton kernel variants compiled during autotuning in tests (e.g., flex attention fwd goes from 6 to 2 configs, bwd from 28 to 2), without affecting production behavior. ## Measured improvements | Metric | Before | After | Speedup | |---|---|---|---| | Import time | 19.0s | 4.4s | **4.3x** | | Collection (2106 tests) | 20.9s | 5.3s | **4.0x** | | 22 GPU tests e2e | 51.7s | 30.2s | **1.7x** | | flex LearnableBiases CUDA | 145s | 77s | **1.9x** | | max_autotune configs (flex fwd+bwd) | 19 | 4 | **4.8x fewer** | Estimated CI wall-clock savings: ~15 min across 157 inductor test files (3 parallel workers). ## Breakdown of import time savings | Bottleneck | Before | After | Savings | |---|---|---|---| | CPU ISA subprocess checks (6×) | ~13s | ~0s (cached) | 13s | | JAX import (has_pallas) | ~1s | deferred | 1s | | codegen.wrapper import | ~1s | deferred | 1s | | async_compile import | ~1.3s | removed | 1.3s | | compile_fx import | ~0.5s | deferred | 0.5s | Authored with Claude. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/181617
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 7498532 with merge base d55bda7 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…7x execution)" Several independent optimizations to reduce inductor test overhead: **ISA subprocess caching** (`cpu_vec_isa.py`): Cache the result of CPU vector ISA load-check subprocesses using `.load_ok` marker files. Each `check_build()` call spawns a Python subprocess that imports torch to verify a compiled .so can be loaded (~2s each, 6 checks per process). The compilation result was already cached on disk, but the load verification subprocess ran every time. **Lazy evaluation** (`inductor_utils.py`): Defer expensive module-level computations — `RUN_CPU` (triggers ISA checks), `HAS_PALLAS`/`HAS_TPU` (imports JAX), and heavy imports like `async_compile`, `codegen.wrapper`, `compile_fx`, `GraphLowering` — until actually needed. Most test files only need simple constants like `HAS_GPU` and `RUN_GPU`. **Shared Triton cache** (`utils.py`, `test_case.py`): Add `share_triton` parameter to `fresh_cache()`. When enabled, Triton compiled kernels are placed in a persistent shared directory instead of the per-test temp dir. Triton compilation is a pure function of the kernel source, so sharing is safe. `InductorTestCase` enables this by default; `test_codecache.py` classes that explicitly delete/inspect the Triton cache directory opt out via `_share_triton_cache = False`. **Autotune config limits** (`config.py`, `triton.py`, `flex_flash_attention.py`): Add `test_configs.max_flex_configs` (similar to existing `max_mm_configs`) and set both to 2 in `InductorTestCase`. This limits the number of Triton kernel variants compiled during autotuning in tests (e.g., flex attention fwd goes from 6 to 2 configs, bwd from 28 to 2), without affecting production behavior. ## Measured improvements | Metric | Before | After | Speedup | |---|---|---|---| | Import time | 19.0s | 4.4s | **4.3x** | | Collection (2106 tests) | 20.9s | 5.3s | **4.0x** | | 22 GPU tests e2e | 51.7s | 30.2s | **1.7x** | | flex LearnableBiases CUDA | 145s | 77s | **1.9x** | | max_autotune configs (flex fwd+bwd) | 19 | 4 | **4.8x fewer** | Estimated CI wall-clock savings: ~15 min across 157 inductor test files (3 parallel workers). ## Breakdown of import time savings | Bottleneck | Before | After | Savings | |---|---|---|---| | CPU ISA subprocess checks (6×) | ~13s | ~0s (cached) | 13s | | JAX import (has_pallas) | ~1s | deferred | 1s | | codegen.wrapper import | ~1s | deferred | 1s | | async_compile import | ~1.3s | removed | 1.3s | | compile_fx import | ~0.5s | deferred | 0.5s | Authored with Claude. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo [ghstack-poisoned]
Several independent optimizations to reduce inductor test overhead: **ISA subprocess caching** (`cpu_vec_isa.py`): Cache the result of CPU vector ISA load-check subprocesses using `.load_ok` marker files. Each `check_build()` call spawns a Python subprocess that imports torch to verify a compiled .so can be loaded (~2s each, 6 checks per process). The compilation result was already cached on disk, but the load verification subprocess ran every time. **Lazy evaluation** (`inductor_utils.py`): Defer expensive module-level computations — `RUN_CPU` (triggers ISA checks), `HAS_PALLAS`/`HAS_TPU` (imports JAX), and heavy imports like `async_compile`, `codegen.wrapper`, `compile_fx`, `GraphLowering` — until actually needed. Most test files only need simple constants like `HAS_GPU` and `RUN_GPU`. **Shared Triton cache** (`utils.py`, `test_case.py`): Add `share_triton` parameter to `fresh_cache()`. When enabled, Triton compiled kernels are placed in a persistent shared directory instead of the per-test temp dir. Triton compilation is a pure function of the kernel source, so sharing is safe. `InductorTestCase` enables this by default; `test_codecache.py` classes that explicitly delete/inspect the Triton cache directory opt out via `_share_triton_cache = False`. **Autotune config limits** (`config.py`, `triton.py`, `flex_flash_attention.py`): Add `test_configs.max_flex_configs` (similar to existing `max_mm_configs`) and set both to 2 in `InductorTestCase`. This limits the number of Triton kernel variants compiled during autotuning in tests (e.g., flex attention fwd goes from 6 to 2 configs, bwd from 28 to 2), without affecting production behavior. | Metric | Before | After | Speedup | |---|---|---|---| | Import time | 19.0s | 4.4s | **4.3x** | | Collection (2106 tests) | 20.9s | 5.3s | **4.0x** | | 22 GPU tests e2e | 51.7s | 30.2s | **1.7x** | | flex LearnableBiases CUDA | 145s | 77s | **1.9x** | | max_autotune configs (flex fwd+bwd) | 19 | 4 | **4.8x fewer** | Estimated CI wall-clock savings: ~15 min across 157 inductor test files (3 parallel workers). | Bottleneck | Before | After | Savings | |---|---|---|---| | CPU ISA subprocess checks (6×) | ~13s | ~0s (cached) | 13s | | JAX import (has_pallas) | ~1s | deferred | 1s | | codegen.wrapper import | ~1s | deferred | 1s | | async_compile import | ~1.3s | removed | 1.3s | | compile_fx import | ~0.5s | deferred | 0.5s | Authored with Claude. ghstack-source-id: b6c1a11 Pull Request resolved: #181617
Several independent optimizations to reduce inductor test overhead: **ISA subprocess caching** (`cpu_vec_isa.py`): Cache the result of CPU vector ISA load-check subprocesses using `.load_ok` marker files. Each `check_build()` call spawns a Python subprocess that imports torch to verify a compiled .so can be loaded (~2s each, 6 checks per process). The compilation result was already cached on disk, but the load verification subprocess ran every time. **Lazy evaluation** (`inductor_utils.py`): Defer expensive module-level computations — `RUN_CPU` (triggers ISA checks), `HAS_PALLAS`/`HAS_TPU` (imports JAX), and heavy imports like `async_compile`, `codegen.wrapper`, `compile_fx`, `GraphLowering` — until actually needed. Most test files only need simple constants like `HAS_GPU` and `RUN_GPU`. **Shared Triton cache** (`utils.py`, `test_case.py`): Add `share_triton` parameter to `fresh_cache()`. When enabled, Triton compiled kernels are placed in a persistent shared directory instead of the per-test temp dir. Triton compilation is a pure function of the kernel source, so sharing is safe. `InductorTestCase` enables this by default; `test_codecache.py` classes that explicitly delete/inspect the Triton cache directory opt out via `_share_triton_cache = False`. **Autotune config limits** (`config.py`, `triton.py`, `flex_flash_attention.py`): Add `test_configs.max_flex_configs` (similar to existing `max_mm_configs`) and set both to 2 in `InductorTestCase`. This limits the number of Triton kernel variants compiled during autotuning in tests (e.g., flex attention fwd goes from 6 to 2 configs, bwd from 28 to 2), without affecting production behavior. | Metric | Before | After | Speedup | |---|---|---|---| | Import time | 19.0s | 4.4s | **4.3x** | | Collection (2106 tests) | 20.9s | 5.3s | **4.0x** | | 22 GPU tests e2e | 51.7s | 30.2s | **1.7x** | | flex LearnableBiases CUDA | 145s | 77s | **1.9x** | | max_autotune configs (flex fwd+bwd) | 19 | 4 | **4.8x fewer** | Estimated CI wall-clock savings: ~15 min across 157 inductor test files (3 parallel workers). | Bottleneck | Before | After | Savings | |---|---|---|---| | CPU ISA subprocess checks (6×) | ~13s | ~0s (cached) | 13s | | JAX import (has_pallas) | ~1s | deferred | 1s | | codegen.wrapper import | ~1s | deferred | 1s | | async_compile import | ~1.3s | removed | 1.3s | | compile_fx import | ~0.5s | deferred | 0.5s | Authored with Claude. ghstack-source-id: 7b3c27b Pull Request resolved: #181617
Several independent optimizations to reduce inductor test overhead: **ISA subprocess caching** (`cpu_vec_isa.py`): Cache the result of CPU vector ISA load-check subprocesses using `.load_ok` marker files. Each `check_build()` call spawns a Python subprocess that imports torch to verify a compiled .so can be loaded (~2s each, 6 checks per process). The compilation result was already cached on disk, but the load verification subprocess ran every time. **Lazy evaluation** (`inductor_utils.py`): Defer expensive module-level computations — `RUN_CPU` (triggers ISA checks), `HAS_PALLAS`/`HAS_TPU` (imports JAX), and heavy imports like `async_compile`, `codegen.wrapper`, `compile_fx`, `GraphLowering` — until actually needed. Most test files only need simple constants like `HAS_GPU` and `RUN_GPU`. **Shared Triton cache** (`utils.py`, `test_case.py`): Add `share_triton` parameter to `fresh_cache()`. When enabled, Triton compiled kernels are placed in a persistent shared directory instead of the per-test temp dir. Triton compilation is a pure function of the kernel source, so sharing is safe. `InductorTestCase` enables this by default; `test_codecache.py` classes that explicitly delete/inspect the Triton cache directory opt out via `_share_triton_cache = False`. **Autotune config limits** (`config.py`, `triton.py`, `flex_flash_attention.py`): Add `test_configs.max_flex_configs` (similar to existing `max_mm_configs`) and set both to 2 in `InductorTestCase`. This limits the number of Triton kernel variants compiled during autotuning in tests (e.g., flex attention fwd goes from 6 to 2 configs, bwd from 28 to 2), without affecting production behavior. | Metric | Before | After | Speedup | |---|---|---|---| | Import time | 19.0s | 4.4s | **4.3x** | | Collection (2106 tests) | 20.9s | 5.3s | **4.0x** | | 22 GPU tests e2e | 51.7s | 30.2s | **1.7x** | | flex LearnableBiases CUDA | 145s | 77s | **1.9x** | | max_autotune configs (flex fwd+bwd) | 19 | 4 | **4.8x fewer** | Estimated CI wall-clock savings: ~15 min across 157 inductor test files (3 parallel workers). | Bottleneck | Before | After | Savings | |---|---|---|---| | CPU ISA subprocess checks (6×) | ~13s | ~0s (cached) | 13s | | JAX import (has_pallas) | ~1s | deferred | 1s | | codegen.wrapper import | ~1s | deferred | 1s | | async_compile import | ~1.3s | removed | 1.3s | | compile_fx import | ~0.5s | deferred | 0.5s | Authored with Claude. ghstack-source-id: 8cabf54 Pull Request resolved: #181617
Several independent optimizations to reduce inductor test overhead: **ISA subprocess caching** (`cpu_vec_isa.py`): Cache the result of CPU vector ISA load-check subprocesses using `.load_ok` marker files. Each `check_build()` call spawns a Python subprocess that imports torch to verify a compiled .so can be loaded (~2s each, 6 checks per process). The compilation result was already cached on disk, but the load verification subprocess ran every time. **Lazy evaluation** (`inductor_utils.py`): Defer expensive module-level computations — `RUN_CPU` (triggers ISA checks), `HAS_PALLAS`/`HAS_TPU` (imports JAX), and heavy imports like `async_compile`, `codegen.wrapper`, `compile_fx`, `GraphLowering` — until actually needed. Most test files only need simple constants like `HAS_GPU` and `RUN_GPU`. **Shared Triton cache** (`utils.py`, `test_case.py`): Add `share_triton` parameter to `fresh_cache()`. When enabled, Triton compiled kernels are placed in a persistent shared directory instead of the per-test temp dir. Triton compilation is a pure function of the kernel source, so sharing is safe. `InductorTestCase` enables this by default; `test_codecache.py` classes that explicitly delete/inspect the Triton cache directory opt out via `_share_triton_cache = False`. **Autotune config limits** (`config.py`, `triton.py`, `flex_flash_attention.py`): Add `test_configs.max_flex_configs` (similar to existing `max_mm_configs`) and set both to 2 in `InductorTestCase`. This limits the number of Triton kernel variants compiled during autotuning in tests (e.g., flex attention fwd goes from 6 to 2 configs, bwd from 28 to 2), without affecting production behavior. | Metric | Before | After | Speedup | |---|---|---|---| | Import time | 19.0s | 4.4s | **4.3x** | | Collection (2106 tests) | 20.9s | 5.3s | **4.0x** | | 22 GPU tests e2e | 51.7s | 30.2s | **1.7x** | | flex LearnableBiases CUDA | 145s | 77s | **1.9x** | | max_autotune configs (flex fwd+bwd) | 19 | 4 | **4.8x fewer** | Estimated CI wall-clock savings: ~15 min across 157 inductor test files (3 parallel workers). | Bottleneck | Before | After | Savings | |---|---|---|---| | CPU ISA subprocess checks (6×) | ~13s | ~0s (cached) | 13s | | JAX import (has_pallas) | ~1s | deferred | 1s | | codegen.wrapper import | ~1s | deferred | 1s | | async_compile import | ~1.3s | removed | 1.3s | | compile_fx import | ~0.5s | deferred | 0.5s | Authored with Claude. ghstack-source-id: b691345 Pull Request resolved: #181617
Several independent optimizations to reduce inductor test overhead: **ISA subprocess caching** (`cpu_vec_isa.py`): Cache the result of CPU vector ISA load-check subprocesses using `.load_ok` marker files. Each `check_build()` call spawns a Python subprocess that imports torch to verify a compiled .so can be loaded (~2s each, 6 checks per process). The compilation result was already cached on disk, but the load verification subprocess ran every time. **Lazy evaluation** (`inductor_utils.py`): Defer expensive module-level computations — `RUN_CPU` (triggers ISA checks), `HAS_PALLAS`/`HAS_TPU` (imports JAX), and heavy imports like `async_compile`, `codegen.wrapper`, `compile_fx`, `GraphLowering` — until actually needed. Most test files only need simple constants like `HAS_GPU` and `RUN_GPU`. **Shared Triton cache** (`utils.py`, `test_case.py`): Add `share_triton` parameter to `fresh_cache()`. When enabled, Triton compiled kernels are placed in a persistent shared directory instead of the per-test temp dir. Triton compilation is a pure function of the kernel source, so sharing is safe. `InductorTestCase` enables this by default; `test_codecache.py` classes that explicitly delete/inspect the Triton cache directory opt out via `_share_triton_cache = False`. **Autotune config limits** (`config.py`, `triton.py`, `flex_flash_attention.py`): Add `test_configs.max_flex_configs` (similar to existing `max_mm_configs`) and set both to 2 in `InductorTestCase`. This limits the number of Triton kernel variants compiled during autotuning in tests (e.g., flex attention fwd goes from 6 to 2 configs, bwd from 28 to 2), without affecting production behavior. | Metric | Before | After | Speedup | |---|---|---|---| | Import time | 19.0s | 4.4s | **4.3x** | | Collection (2106 tests) | 20.9s | 5.3s | **4.0x** | | 22 GPU tests e2e | 51.7s | 30.2s | **1.7x** | | flex LearnableBiases CUDA | 145s | 77s | **1.9x** | | max_autotune configs (flex fwd+bwd) | 19 | 4 | **4.8x fewer** | Estimated CI wall-clock savings: ~15 min across 157 inductor test files (3 parallel workers). | Bottleneck | Before | After | Savings | |---|---|---|---| | CPU ISA subprocess checks (6×) | ~13s | ~0s (cached) | 13s | | JAX import (has_pallas) | ~1s | deferred | 1s | | codegen.wrapper import | ~1s | deferred | 1s | | async_compile import | ~1.3s | removed | 1.3s | | compile_fx import | ~0.5s | deferred | 0.5s | Authored with Claude. ghstack-source-id: e1be1ef Pull Request resolved: #181617
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
The probe child was paying multi-second `import torch` startup on every spawn and hung under load on ROCm MI355 CI. Drop the import: on Linux/macOS the parent prepends torch's lib dir to LD_LIBRARY_PATH / DYLD_LIBRARY_PATH so the dynamic linker resolves libtorch_cpu automatically; on Windows the child self-discovers the lib dir via importlib.util.find_spec (which does not execute torch/__init__.py) and registers it via os.add_dll_directory before LoadLibrary. The 60s timeout, one retry, and kill-on-timeout from the earlier commit on this branch are kept as defense in depth for any future child hang (e.g. a static initializer in the .so itself). Also drops the .loadok sentinel cache from the earlier commit on this branch. PR #181617 has since landed an equivalent .load_ok marker on main, so the warm-path concern is handled upstream and the rebase will keep that outer guard. Adds regression tests in test_codecache.py covering the timeout-retry exhaustion path and the LD/DYLD prepend behavior. Authored by Claude.
|
This broke a ROCm test. Instead of revert, attempting a forward-fix quickly. |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
The base commit is too old, plz help rebase to get the latest workflows change |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
Inductor test collection pays avoidable startup cost in two places. CPU vector ISA availability already caches the dry-compile artifact on disk, but every process still spawned Python subprocesses to verify the compiled shared objects could be loaded. The test utility module also performed CPU ISA checks, JAX/Pallas checks, and several heavy Inductor imports at module import time even when callers only needed simple constants.
Cache successful ISA load probes with `.load_ok` marker files next to the compiled shared object, and leave failed probes uncached so they can be retried. Defer the expensive `inductor_utils` checks and imports until the corresponding helper or lazy value is actually used.
This intentionally keeps the change scoped to ISA probe caching and lazy test utility initialization. The shared Triton cache and autotune config-limit changes from the original version are left out.
Test Plan:
```
python -m py_compile torch/_inductor/cpu_vec_isa.py torch/testing/_internal/inductor_utils.py
```
```
TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY'
from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA
isa = pick_vec_isa()
print("check_build", isa.check_build(VecISA._avx_code))
PY
```
```
TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY'
from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA
isa = pick_vec_isa()
def fail_probe(output_path):
raise AssertionError("marker cache was not used")
isa._probe_load = fail_probe
print("cached_check_build", isa.check_build(VecISA._avx_code))
PY
```
```
python - <<'PY'
from torch.testing._internal.inductor_utils import dummy_graph, patch_custom_fallback_pass
g = dummy_graph()
print(type(g).__name__)
ctx = patch_custom_fallback_pass(lambda node: False)
print(type(ctx).__name__)
PY
```
```
https_proxy=http://fwdproxy:8080 HTTPS_PROXY=http://fwdproxy:8080 lintrunner -a
```
Authored with an AI assistant.
ghstack-source-id: 874e37e
Pull-Request: #181617
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…81617) Inductor test collection pays avoidable startup cost in two places. CPU vector ISA availability already caches the dry-compile artifact on disk, but every process still spawned Python subprocesses to verify the compiled shared objects could be loaded. The test utility module also performed CPU ISA checks, JAX/Pallas checks, and several heavy Inductor imports at module import time even when callers only needed simple constants. Cache successful ISA load probes with `.load_ok` marker files next to the compiled shared object, and leave failed probes uncached so they can be retried. Defer the expensive `inductor_utils` checks and imports until the corresponding helper or lazy value is actually used. This intentionally keeps the change scoped to ISA probe caching and lazy test utility initialization. The shared Triton cache and autotune config-limit changes from the original version are left out. Test Plan: ``` python -m py_compile torch/_inductor/cpu_vec_isa.py torch/testing/_internal/inductor_utils.py ``` ``` TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY' from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA isa = pick_vec_isa() print("check_build", isa.check_build(VecISA._avx_code)) PY ``` ``` TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY' from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA isa = pick_vec_isa() def fail_probe(output_path): raise AssertionError("marker cache was not used") isa._probe_load = fail_probe print("cached_check_build", isa.check_build(VecISA._avx_code)) PY ``` ``` python - <<'PY' from torch.testing._internal.inductor_utils import dummy_graph, patch_custom_fallback_pass g = dummy_graph() print(type(g).__name__) ctx = patch_custom_fallback_pass(lambda node: False) print(type(ctx).__name__) PY ``` ``` https_proxy=http://fwdproxy:8080 HTTPS_PROXY=http://fwdproxy:8080 lintrunner -a ``` Authored with an AI assistant. Pull Request resolved: pytorch#181617 Approved by: https://github.com/drisspg
…81617) Inductor test collection pays avoidable startup cost in two places. CPU vector ISA availability already caches the dry-compile artifact on disk, but every process still spawned Python subprocesses to verify the compiled shared objects could be loaded. The test utility module also performed CPU ISA checks, JAX/Pallas checks, and several heavy Inductor imports at module import time even when callers only needed simple constants. Cache successful ISA load probes with `.load_ok` marker files next to the compiled shared object, and leave failed probes uncached so they can be retried. Defer the expensive `inductor_utils` checks and imports until the corresponding helper or lazy value is actually used. This intentionally keeps the change scoped to ISA probe caching and lazy test utility initialization. The shared Triton cache and autotune config-limit changes from the original version are left out. Test Plan: ``` python -m py_compile torch/_inductor/cpu_vec_isa.py torch/testing/_internal/inductor_utils.py ``` ``` TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY' from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA isa = pick_vec_isa() print("check_build", isa.check_build(VecISA._avx_code)) PY ``` ``` TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY' from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA isa = pick_vec_isa() def fail_probe(output_path): raise AssertionError("marker cache was not used") isa._probe_load = fail_probe print("cached_check_build", isa.check_build(VecISA._avx_code)) PY ``` ``` python - <<'PY' from torch.testing._internal.inductor_utils import dummy_graph, patch_custom_fallback_pass g = dummy_graph() print(type(g).__name__) ctx = patch_custom_fallback_pass(lambda node: False) print(type(ctx).__name__) PY ``` ``` https_proxy=http://fwdproxy:8080 HTTPS_PROXY=http://fwdproxy:8080 lintrunner -a ``` Authored with an AI assistant. Pull Request resolved: pytorch#181617 Approved by: https://github.com/drisspg
…n) (pytorch#181617) Several independent optimizations to reduce inductor test overhead: **ISA subprocess caching** (`cpu_vec_isa.py`): Cache the result of CPU vector ISA load-check subprocesses using `.load_ok` marker files. Each `check_build()` call spawns a Python subprocess that imports torch to verify a compiled .so can be loaded (~2s each, 6 checks per process). The compilation result was already cached on disk, but the load verification subprocess ran every time. **Lazy evaluation** (`inductor_utils.py`): Defer expensive module-level computations — `RUN_CPU` (triggers ISA checks), `HAS_PALLAS`/`HAS_TPU` (imports JAX), and heavy imports like `async_compile`, `codegen.wrapper`, `compile_fx`, `GraphLowering` — until actually needed. Most test files only need simple constants like `HAS_GPU` and `RUN_GPU`. **Shared Triton cache** (`utils.py`, `test_case.py`): Add `share_triton` parameter to `fresh_cache()`. When enabled, Triton compiled kernels are placed in a persistent shared directory instead of the per-test temp dir. Triton compilation is a pure function of the kernel source, so sharing is safe. `InductorTestCase` enables this by default; `test_codecache.py` classes that explicitly delete/inspect the Triton cache directory opt out via `_share_triton_cache = False`. **Autotune config limits** (`config.py`, `triton.py`, `flex_flash_attention.py`): Add `test_configs.max_flex_configs` (similar to existing `max_mm_configs`) and set both to 2 in `InductorTestCase`. This limits the number of Triton kernel variants compiled during autotuning in tests (e.g., flex attention fwd goes from 6 to 2 configs, bwd from 28 to 2), without affecting production behavior. ## Measured improvements | Metric | Before | After | Speedup | |---|---|---|---| | Import time | 19.0s | 4.4s | **4.3x** | | Collection (2106 tests) | 20.9s | 5.3s | **4.0x** | | 22 GPU tests e2e | 51.7s | 30.2s | **1.7x** | | flex LearnableBiases CUDA | 145s | 77s | **1.9x** | | max_autotune configs (flex fwd+bwd) | 19 | 4 | **4.8x fewer** | Estimated CI wall-clock savings: ~15 min across 157 inductor test files (3 parallel workers). ## Breakdown of import time savings | Bottleneck | Before | After | Savings | |---|---|---|---| | CPU ISA subprocess checks (6×) | ~13s | ~0s (cached) | 13s | | JAX import (has_pallas) | ~1s | deferred | 1s | | codegen.wrapper import | ~1s | deferred | 1s | | async_compile import | ~1.3s | removed | 1.3s | | compile_fx import | ~0.5s | deferred | 0.5s | Authored with Claude. Pull Request resolved: pytorch#181617 Approved by: https://github.com/drisspg
…ap (pytorch#184389) PR pytorch#181617 added a global test_configs.max_mm_configs=2 cap in InductorTestCase. test_origami_reduces_compile_work_vs_regular_max_autotune compares benchmark_gpu_calls between origami (topk-limited) and regular max_autotune; with both paths capped at 2 candidates the autotuner short-circuits in both branches and produces 0 vs 0, failing assertLess. Only the linux-noble-rocm-py3.12-mi355 workflow surfaces this since it is the only runner with the origami package installed; everywhere else HAS_ORIGAMI=False and the class is skipped. Restore unlimited max_mm_configs for this test via config.patch so the differential comparison is meaningful again. Authored with Claude. Pull Request resolved: pytorch#184389 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
…181617 cap (pytorch#184389)" This reverts commit bf86b86. Reverted pytorch#184389 on behalf of https://github.com/izaitsevfb due to need to revert pytorch#181617 ([comment](pytorch#184389 (comment)))
…execution) (pytorch#181617)" This reverts commit b102368. Reverted pytorch#181617 on behalf of https://github.com/izaitsevfb due to breaking internal tests ([comment](pytorch#181617 (comment)))
…orch#183515) The dlopen probe in `cpu_vec_isa.check_build` runs `python -c <script>; cdll.LoadLibrary(<.so>)` to verify the compiler+runtime can load a tiny vec-ISA test library. Two problems: 1. The `subprocess.check_call` had no timeout, so a stuck child hung the parent test process for the full 30-minute CI budget. Saw it twice on ROCm MI355 in `test_torchinductor_opinfo_properties` (shards 5/15 and 9/15). 2. The script did `import torch` inside the child to bring `libtorch_cpu` into the process, paying multi-second startup per spawn. That import is what was hanging under load. Fix the root cause and add defense in depth: - Drop `import torch` from the probe script. On Linux/macOS the parent prepends `<torch>/lib` to `LD_LIBRARY_PATH` / `DYLD_LIBRARY_PATH` so the dynamic linker resolves `libtorch_cpu` automatically. On Windows `ctypes.cdll.LoadLibrary` ignores those vars, so the child self-discovers torch via `importlib.util.find_spec` (which does not execute `torch/__init__.py`) and registers the lib dir via `os.add_dll_directory` before `LoadLibrary`. - Switch `subprocess.check_call` to `subprocess.run(timeout=60, check=True)` so the child is killed on `TimeoutExpired` (`check_call` leaks it). `TimeoutExpired` returns `False` with a warning; `CalledProcessError` still fails fast. The probe drops from ~2.1s to ~0.3s per spawn locally. An earlier revision of this PR also cached the result in a `.load_ok` marker, but that marker belonged to pytorch#181617, which has since been reverted on `main`; this PR no longer carries it, so the probe runs once per process (cached in-process by the existing `@functools.cache` on `__bool__impl`). Two regression tests in `test_codecache.py` cover the timeout path (returns False, emits warning) and the LD/DYLD prepend behavior. Authored by Claude. Pull Request resolved: pytorch#183515 Approved by: https://github.com/jansel
…orch#183515) The dlopen probe in `cpu_vec_isa.check_build` runs `python -c <script>; cdll.LoadLibrary(<.so>)` to verify the compiler+runtime can load a tiny vec-ISA test library. Two problems: 1. The `subprocess.check_call` had no timeout, so a stuck child hung the parent test process for the full 30-minute CI budget. Saw it twice on ROCm MI355 in `test_torchinductor_opinfo_properties` (shards 5/15 and 9/15). 2. The script did `import torch` inside the child to bring `libtorch_cpu` into the process, paying multi-second startup per spawn. That import is what was hanging under load. Fix the root cause and add defense in depth: - Skip `import torch` in the child **on Linux only**, where it is both the fix for the observed hang and safe to validate: the parent prepends `<torch>/lib` to `LD_LIBRARY_PATH` so the dynamic linker resolves `libtorch_cpu` for the test `.so` automatically. macOS and Windows keep `import torch` in the child (the pre-rework behavior): - **macOS**: the env approach cannot work -- SIP strips `DYLD_LIBRARY_PATH` from spawned children and the test `.so`'s `@rpath` dependency on `libtorch_cpu.dylib` is unresolvable from the parent env. - **Windows**: a `find_spec` + `os.add_dll_directory` scheme is plausible, but the Windows CI build is currently red on an unrelated pip/`requirements-ci` infra flake, so that path cannot actually be exercised. Rather than ship an unvalidated loader change (which is how the macOS breakage slipped in), keep Windows on the proven import until it can be tested. - Switch `subprocess.check_call` to `subprocess.run(timeout=60, check=True)` so the child is killed on `TimeoutExpired` (`check_call` leaks it). `TimeoutExpired` returns `False` with a warning; `CalledProcessError` still fails fast. On Linux the probe drops from ~2.1s to ~0.3s per spawn locally; macOS/Windows keep the import. An earlier revision of this PR also cached the result in a `.load_ok` marker, but that marker belonged to pytorch#181617, which has since been reverted on `main`; this PR no longer carries it, so the probe runs once per process (cached in-process by the existing `@functools.cache` on `__bool__impl`). Two regression tests in `test_codecache.py` cover the timeout path (returns False, emits warning) and the `LD_LIBRARY_PATH` prepend behavior. Note: an earlier landing of this PR was auto-reverted because dropping `import torch` on macOS broke CPU vectorized codegen (`test_neg_index_cpu` on `macos-py3-arm64`): the `DYLD_LIBRARY_PATH` / preload-by-path approach does not work under SIP. macOS now imports torch in the child, and -- since Windows CI can't currently validate a loader change -- Windows does too, making the no-import path a Linux-only optimization. Authored by Claude. Pull Request resolved: pytorch#183515 Approved by: https://github.com/jansel
…81617) Inductor test collection pays avoidable startup cost in two places. CPU vector ISA availability already caches the dry-compile artifact on disk, but every process still spawned Python subprocesses to verify the compiled shared objects could be loaded. The test utility module also performed CPU ISA checks, JAX/Pallas checks, and several heavy Inductor imports at module import time even when callers only needed simple constants. Cache successful ISA load probes with `.load_ok` marker files next to the compiled shared object, and leave failed probes uncached so they can be retried. Defer the expensive `inductor_utils` checks and imports until the corresponding helper or lazy value is actually used. This intentionally keeps the change scoped to ISA probe caching and lazy test utility initialization. The shared Triton cache and autotune config-limit changes from the original version are left out. Test Plan: ``` python -m py_compile torch/_inductor/cpu_vec_isa.py torch/testing/_internal/inductor_utils.py ``` ``` TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY' from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA isa = pick_vec_isa() print("check_build", isa.check_build(VecISA._avx_code)) PY ``` ``` TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY' from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA isa = pick_vec_isa() def fail_probe(output_path): raise AssertionError("marker cache was not used") isa._probe_load = fail_probe print("cached_check_build", isa.check_build(VecISA._avx_code)) PY ``` ``` python - <<'PY' from torch.testing._internal.inductor_utils import dummy_graph, patch_custom_fallback_pass g = dummy_graph() print(type(g).__name__) ctx = patch_custom_fallback_pass(lambda node: False) print(type(ctx).__name__) PY ``` ``` https_proxy=http://fwdproxy:8080 HTTPS_PROXY=http://fwdproxy:8080 lintrunner -a ``` Authored with an AI assistant. Pull Request resolved: pytorch#181617 Approved by: https://github.com/drisspg
…81617) Inductor test collection pays avoidable startup cost in two places. CPU vector ISA availability already caches the dry-compile artifact on disk, but every process still spawned Python subprocesses to verify the compiled shared objects could be loaded. The test utility module also performed CPU ISA checks, JAX/Pallas checks, and several heavy Inductor imports at module import time even when callers only needed simple constants. Cache successful ISA load probes with `.load_ok` marker files next to the compiled shared object, and leave failed probes uncached so they can be retried. Defer the expensive `inductor_utils` checks and imports until the corresponding helper or lazy value is actually used. This intentionally keeps the change scoped to ISA probe caching and lazy test utility initialization. The shared Triton cache and autotune config-limit changes from the original version are left out. Test Plan: ``` python -m py_compile torch/_inductor/cpu_vec_isa.py torch/testing/_internal/inductor_utils.py ``` ``` TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY' from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA isa = pick_vec_isa() print("check_build", isa.check_build(VecISA._avx_code)) PY ``` ``` TORCHINDUCTOR_CACHE_DIR=/data/users/eellison/pytorch/agent_space/isa_load_ok_cache python - <<'PY' from torch._inductor.cpu_vec_isa import pick_vec_isa, VecISA isa = pick_vec_isa() def fail_probe(output_path): raise AssertionError("marker cache was not used") isa._probe_load = fail_probe print("cached_check_build", isa.check_build(VecISA._avx_code)) PY ``` ``` python - <<'PY' from torch.testing._internal.inductor_utils import dummy_graph, patch_custom_fallback_pass g = dummy_graph() print(type(g).__name__) ctx = patch_custom_fallback_pass(lambda node: False) print(type(ctx).__name__) PY ``` ``` https_proxy=http://fwdproxy:8080 HTTPS_PROXY=http://fwdproxy:8080 lintrunner -a ``` Authored with an AI assistant. Pull Request resolved: pytorch#181617 Approved by: https://github.com/drisspg
Stack from ghstack (oldest at bottom):
Inductor test collection pays avoidable startup cost in two places. CPU vector ISA availability already caches the dry-compile artifact on disk, but every process still spawned Python subprocesses to verify the compiled shared objects could be loaded. The test utility module also performed CPU ISA checks, JAX/Pallas checks, and several heavy Inductor imports at module import time even when callers only needed simple constants.
Cache successful ISA load probes with
.load_okmarker files next to the compiled shared object, and leave failed probes uncached so they can be retried. Defer the expensiveinductor_utilschecks and imports until the corresponding helper or lazy value is actually used.This intentionally keeps the change scoped to ISA probe caching and lazy test utility initialization. The shared Triton cache and autotune config-limit changes from the original version are left out.
Test Plan:
Authored with an AI assistant.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo