Skip to content

[inductor] Cache ISA probes and defer test utility imports - #181617

Closed
eellison wants to merge 8 commits into
gh/eellison/1001/basefrom
gh/eellison/1001/head
Closed

eellison wants to merge 8 commits into
gh/eellison/1001/basefrom
gh/eellison/1001/head

Conversation

@eellison

@eellison eellison commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

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_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.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

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]
@eellison
eellison requested a review from drisspg as a code owner April 27, 2026 17:58
@pytorch-bot

pytorch-bot Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

🔗 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 SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 7498532 with merge base d55bda7 (image):
💚 Looks good so far! There are no failures yet. 💚

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]
eellison added a commit that referenced this pull request Apr 28, 2026
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
[ghstack-poisoned]
eellison added a commit that referenced this pull request May 18, 2026
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
@eellison eellison added the topic: not user facing topic category label May 18, 2026
[ghstack-poisoned]
eellison added a commit that referenced this pull request May 18, 2026
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
[ghstack-poisoned]
eellison added a commit that referenced this pull request May 18, 2026
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
[ghstack-poisoned]
eellison added a commit that referenced this pull request May 18, 2026
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
@eellison

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 19, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

jeffdaily added a commit that referenced this pull request May 19, 2026
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.
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@huydhn

huydhn commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

The base commit is too old, plz help rebase to get the latest workflows change

@eellison

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased gh/eellison/1001/orig onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/181617)

pytorchmergebot pushed a commit that referenced this pull request Jul 20, 2026
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
@eellison

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

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
For more information see pytorch-bot wiki.

@eellison

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…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
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…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]>
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…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
MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
…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
@github-actions
github-actions Bot deleted the gh/eellison/1001/head branch August 21, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor Reverted topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants