Repository navigation
Add TORCHINDUCTOR_VEC_ISA_OK env var for vec_isa_ok - #134667
matthewhagraphcore wants to merge 6 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/134667
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit d96fea6 with merge base aaf5615 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@Chillee Could I get a review on this? |
|
@janeyx99 could you get someone to review this? Thanks |
|
@Chillee who would be a good reviewer from the inductor side? |
|
Hi @janeyx99 any luck getting reviewers? |
|
@pytorchbot label "topic: not user facing" |
|
@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 |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / win-vs2019-cuda12.1-py3 / build Details for Dev Infra teamRaised by workflow job |
|
@janeyx99 this seems like an infrastructure issue. Could you skip or retry ? |
|
Hi @ janeyx99 I have run linting locally with no problems and merged to main. Could you try again? |
|
Approved the workflows |
|
One last try @janeyx99 ? |
|
For future reference, we recommend running lintrunner locally to ensure lint is green the next time around--you can find more details on lintrunner in the logs whenever lint fails btw! but it should be p easy to set up, pip install lintrunner && lintrunner init && lintrunner -a |
|
@janeyx99 I've run lintrunner now, could I get one last run? |
1 similar comment
|
@janeyx99 I've run lintrunner now, could I get one last run? |
|
@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 |
PT 2.12's cpu_vec_isa.check_build() spawns a subprocess to dlopen a test .so, protected by a filelock under /tmp/torchinductor_root. In fresh containers the probe can fail with FileNotFoundError during lock release — a known upstream issue (pytorch/pytorch#183515, pytorch/pytorch#134667). The official workaround is TORCHINDUCTOR_VEC_ISA_OK=1, which tells Inductor to assume AVX support without running the probe at all. This replaces the previous mkdir + Python warmup hack.
* Support PyTorch 2.12 compatibility * Add PyTorch 2.9/2.12 dual-version AOT compatibility Introduce _aot_compat.py shim that abstracts away the AOT API differences between PyTorch 2.9 (CompileArtifacts) and 2.12 (AOTCompiledFunction), so load/save/extract work on both versions. Update magi_compiler_base.py to use the shim instead of calling version-specific APIs directly. Add pytest.mark.skipif decorators to tests that document version-specific upstream behavior (skipped on 2.12 where _OpPickleData no longer raises for unknown ops, skipped on 2.9 where upstream fixes landed in 2.12 only). Tested in isolated containers: - nvcr.io/nvidia/pytorch:25.10-py3 (2.9): 61 passed, 3 skipped - nvcr.io/nvidia/pytorch:26.05-py3 (2.12): 61 passed, 3 skipped * Add containerized CI with dual PyTorch version testing Migrate from bare-metal runner CI to container-based testing, following athena's _ci_pipeline.yml pattern for style consistency. Changes: - Dockerfile: parameterize BASE_IMAGE (default 25.10-py3), install MagiCompiler + test deps inside image, skip pinned triton to preserve each base image's built-in version - _ci_pipeline.yml: reusable build+test workflow (build Docker image, push to CCR, run tests inside container) - integration_test.yml: parallel matrix testing on PyTorch 2.9 (nvcr.io/nvidia/pytorch:25.10-py3) and 2.12 (26.05-py3) - merge_test.yml: post-merge testing on both versions * Fix Dockerfile: install test deps with transitive dependencies - Add .dockerignore to exclude .git, __pycache__, build artifacts - Replace --no-deps with proper dependency filtering: install all test deps except torchvision (requires torch>=2.12) and torchtitan (installed separately with --no-deps) - Add graphviz system package required by tests * Fix CI runner label: magi_compiler_ci -> magi-compiler The self-hosted runner is registered with the label magi-compiler (matching the original integration_test.yml), not magi_compiler_ci. * docs: update PyTorch version requirement to 2.9.x / 2.12.x Update README.md badge and requirements, install.md, and zh_CN locale to reflect dual PyTorch version support. * refactor: move _aot_compat imports to module top level Move load_aot_artifacts, save_aot_artifacts, extract_aot_artifacts_from_fn imports from inline (inside methods) to the top-level import block. * refactor: split version-specific tests into _pt29/_pt212 variants - test_compile_artifacts: split 4 tests into 8 (pt29/pt212 pairs) with version-appropriate assertions and skipif decorators - test_piecewise_deferred_assert_scope: restore pt29 NameError expectation as xfail (incidentally fixed by later commits) + pt212 passes variant - test_unbacked_symbol_guard: split legacy_view test into pt29 (expects guard error) and pt212 (compiles successfully) - test_inductor_cache_reuse: skip entire class — expected autograd cache counters differ between PT 2.9 and 2.12, needs recalibration * style: apply pre-commit formatting (black, isort, pretty-format-yaml) * fix: use ARG-based proxy in Dockerfile instead of --mount=type=secret The CI passes proxy via --build-arg but the Dockerfile read it from --mount=type=secret, causing git fetch to hang without proxy access. Switch to ARG http_proxy/https_proxy pattern matching athena. * fix: pin setuptools<82 to satisfy torch 2.12 requirement * perf: slim down Dockerfile for CI — remove flash-attn, CUTLASS cmake, ffmpeg Removed: - flash-attention 3 build from source (~5min compile, zero test references) - CUTLASS cmake build (headers-only clone is sufficient for EVT codegen) - ffmpeg (no test references) - build-essential, cmake, ninja-build system packages (not needed at runtime) - syntax=docker/dockerfile:1.7 directive (no longer using --mount=type=secret) Kept: - CUTLASS headers clone (used by EVT-fusion codegen path) - graphviz (required by depyf/test visualization) * perf: optimize Dockerfile layer ordering and merge pip installs - Merge all pip installs (upgrade + core deps + test deps) into one RUN before COPY source, so deps are cached on code-only changes - Merge apt-get + CUTLASS clone into one system layer - Only COPY . and pip install -e . re-run on code changes * refactor: split apt-get and CUTLASS clone into separate layers * fix: replace container: directive with docker run in test job The GitHub Actions container: directive fails on the magi-compiler self-hosted runner (temp script mount issue). Switch to explicit docker run which gives full control over mounts and avoids the /__w/_temp path mapping problem. * fix: use container: directive with athena-new runner for test job The magi-compiler runner fails with container: (Docker-in-Docker temp script mount issue). Switch test job to athena-new runner which is known to support container: jobs correctly. Build job stays on magi-compiler. * fix: add tyro dependency for torchtitan in Dockerfile torchtitan==0.2.0 was installed with --no-deps to avoid pulling a newer torch, but its transitive dependency tyro was missing, causing test_fsdp_overlap_e2e tests to fail with ModuleNotFoundError. * fix: use magi-compiler runner for test job instead of athena-new athena-new runner is dedicated to athena CI and will not pick up MagiCompiler jobs. Both build and test jobs now use magi-compiler. * fix: add NCCL_NVLS_ENABLE=0 and --shm-size=2g to CI test container - NCCL_NVLS_ENABLE=0: disable NVLink SHARP to avoid Fabric Manager errors in container environment (CUDA error 802) - --shm-size=2g: ensure sufficient shared memory for multi-rank tests - Prepare /tmp/torchinductor_root cache dir before tests to prevent filelock race conditions in PyTorch Inductor CPU vec ISA checks * refactor: remove unnecessary Prepare environment step from CI The mkdir for /tmp/torchinductor_root was added speculatively to fix FileNotFoundError in cpu_vec_isa.check_build(), but the issue is likely runner-specific (only appeared on magi-compiler, not athena-new) and this step does not address the root cause. Keep NCCL_NVLS_ENABLE=0 which is the correct fix for NCCL 2.30+ in containers without full Fabric Manager access. * fix: cap ND tiling max_tiles=2 on PT 2.12, relax conv perf threshold ND tiling: PT 2.12 Inductor generates invalid 3D-grid reduction kernels when max_tiles=3 — program_id(2) refers to a grid dimension that does not exist in the launch config. Root cause is Inductor codegen, not Triton (Triton 3.7 handles program_id(2) correctly when grid is 3D). Cap max_tiles at 2 on PT >= 2.12; keep 3 on PT 2.9 where it works. Verified: magi_compile + ND tiling workaround passes on both PT versions. Conv perf: lower threshold from 1.20x to 1.05x to reduce CI flakiness from GPU clock/thermal variance across runs. * test: add GPU integration tests for max_tiles=3 Inductor codegen bug Add three tests to test_nd_tiling_workaround.py: - test_max_tiles_3_crashes_on_pt212: reproduces the PT 2.12 Inductor bug where max_tiles=3 + tile_reductions=True generates a Triton kernel referencing program_id(2) on a 2D launch grid (assert the error) - test_max_tiles_2_compiles_successfully: verifies the fix (max_tiles=2) compiles correctly on all PT versions - test_nd_tiling_pass_uses_safe_max_tiles_on_pt212: verifies the pass itself picks max_tiles=2 on PT >= 2.12 Also update _assert_injected to be version-aware (expect max_tiles=2 on PT 2.12 instead of 3). * style: apply black formatting to test_nd_tiling_workaround.py * fix: restore torchinductor cache dir prep, skip ND tiling perf on PT 2.12 - Add Prepare environment step (mkdir -p /tmp/torchinductor_root) to CI test job, fixing 6 InductorError: FileNotFoundError on early tests - Skip test_nd_tiling_workaround_speedup on PT >= 2.12 because max_tiles=2 (required to avoid Inductor codegen bug) reduces tiling granularity * test: skip collective profile accuracy test on PT >= 2.12 PT 2.12 Inductor generates different scheduler node counts across ranks for the same all_gather graph, causing cross-rank key-set mismatch and analytical fallback (ratio=0.34 vs 0.5-2.0 tolerance). * fix: set TORCHINDUCTOR_VEC_ISA_OK=1 to skip ISA probe filelock race PT 2.12's cpu_vec_isa.check_build() spawns a subprocess to dlopen a test .so, protected by a filelock under /tmp/torchinductor_root. In fresh containers the probe can fail with FileNotFoundError during lock release — a known upstream issue (pytorch/pytorch#183515, pytorch/pytorch#134667). The official workaround is TORCHINDUCTOR_VEC_ISA_OK=1, which tells Inductor to assume AVX support without running the probe at all. This replaces the previous mkdir + Python warmup hack. * fix: use stable cache dir + warmup to fully prevent ISA filelock race TORCHINDUCTOR_VEC_ISA_OK=1 only short-circuits VecISA.__bool__impl, but VecAVX512 subclass __bool__ still calls check_build() for BF16 extension, hitting the same filelock race on /tmp. Two-pronged fix: - TORCHINDUCTOR_CACHE_DIR=/app/.inductor_cache (stable, not /tmp tmpfs) - Pre-test warmup step runs pick_vec_isa() to populate cache once * fix: backport ISA probe caching in conftest to prevent filelock race Instead of env-var workarounds (TORCHINDUCTOR_CACHE_DIR, VEC_ISA_OK), cache check_build() results in-memory via conftest.py — equivalent to upstream PR #181617's .load_ok markers which PT 2.12 lacks. - Patch VecISA.check_build with dict-based memoization - Warm up all ISA probes once at collection time via pick_vec_isa() - Remove TORCHINDUCTOR_VEC_ISA_OK and TORCHINDUCTOR_CACHE_DIR from CI - Remove the separate warmup step (conftest handles it in-process) * fix: cleanup_cache only removes magi-owned subdirs, preserves inductor_cache/ Root cause: the autouse cleanup_cache fixture called shutil.rmtree on the entire cache_root_dir (~/.cache/magi_compiler/), which includes Inductor's inductor_cache/ subdirectory. Inductor's async compiler holds FileLock objects inside that directory; deleting the lock file while still held causes FileNotFoundError on fcntl.flock(fd, LOCK_UN) in Linux overlayfs containers (the exact CI failure on PT 2.12). Fix: only delete MagiCompiler-owned subdirs (magi_cache/, magi_depyf/), leaving inductor_cache/ untouched so async lock release succeeds. Also adds test_cleanup_filelock_race.py with minimal reproduction and fix verification. * style: apply pre-commit fixes to test_cleanup_filelock_race.py Add copyright header, remove unused import, fix black formatting. * ci: temporarily skip pt29 to fast-validate pt212 filelock fix * fix: patch filelock._release to survive overlayfs FileNotFoundError Root cause: Docker overlayfs can cause fcntl.flock(fd, LOCK_UN) to raise FileNotFoundError on unlinked inodes. This affects every Inductor filelock path (ISA probe via cpu_vec_isa.check_build, code cache via codecache.load_async, async compile). Fix: monkey-patch filelock._unix.UnixFileLock._release in conftest.py to catch FileNotFoundError and safely close the fd. This is more robust than previous attempts (ISA caching, cache dir relocation) because it covers ALL filelock code paths. * fix: restore full cache cleanup + keep filelock patch The selective cleanup (preserving inductor_cache/) caused matmul epilogue fusion tests to fail due to stale Inductor cache state between tests. Restore the original shutil.rmtree(cache_root_dir) behavior to ensure clean state per test, while keeping the filelock._release patch to handle the overlayfs FileNotFoundError that rmtree triggers. Also fix test_cleanup_filelock_race.py cleanup to use shutil.rmtree instead of os.unlink (lock file may already be gone on overlayfs). * ci: restore pt29 test after pt212 filelock fix verified * docs: add upstream references to filelock workaround in conftest Add links to filelock#494, #495, #513 and pytorch#134384 explaining why _release() raises FileNotFoundError on overlayfs and why the monkey-patch is needed (upstream fixed _acquire but not _release). * fix: pin filelock<3.19 to avoid overlayfs FileNotFoundError filelock >= 3.19 calls unlink() in _release() before flock(LOCK_UN), which raises FileNotFoundError on Docker overlayfs (the CI container filesystem). Versions < 3.19 explicitly preserve lock files on release. This replaces the previous monkey-patch approach with a clean dependency pin — no runtime code changes needed. Ref: tox-dev/filelock#494 * ci: restore pt29 after filelock<3.19 fix verified on pt212 * refactor: centralize PT version detection into envs.py Move TORCH_VERSION / IS_PT_212 from scattered per-file definitions into magi_compiler.utils.envs, eliminating 7 duplicate copies. Also restore test_symbolic_unification.py to original is_compiling() guard form and split bad_order cache check into _pt29 (u0/u1/u2) and _pt212 (s-prefixed symbols) variants, verified via experiment. * fix: split bad_order test for PT 2.9/2.12, add negative test PT 2.12 + magi_compile two-level compile: is_compiling() guard is insufficient to prevent symbolic unification when first call has zero-token modalities. Add ModalityDispatcherMockV2Fixed using @torch.compiler.disable() wrapper. - test_bad_order_pt29: OuterModel (is_compiling guard) + u-symbol cache check - test_bad_order_pt212: OuterModelFixed (@torch.compiler.disable) - test_is_compiling_guard_insufficient_pt212: negative test asserting the is_compiling() approach fails on PT 2.12 Verified on both PT 2.9 (cenn-3) and PT 2.12 (dev__260804). * fix: version-conditional conv perf threshold (1.20 PT2.9, 1.05 PT2.12) PT 2.12 torch.compile baseline is faster, narrowing the channels-last speedup from ~1.2x to ~1.1x. Use IS_PT_212 to keep the original 1.20 threshold on PT 2.9 and relax to 1.05 on PT 2.12. Measured on H100 (3 runs each): PT 2.9: 1.23x, 1.24x, 1.27x → threshold 1.20 (unchanged) PT 2.12: 1.09x, 1.10x, 1.11x → threshold 1.05 * fix: restore original cache counters, skip only on PT 2.12 Revert training autograd_miss to 1 (the correct PT 2.9 value). Replace unconditional @pytest.mark.skip with skipif(IS_PT_212) so PT 2.9 runs the test normally. * docs: add PT 2.9/2.12 version-split commentary to test_compile_artifacts Document the three behavioral differences between PyTorch versions in the module docstring and at each split point: 1. View tensor bad reducer (Patch A) 2. Third-party op serialization (Patch B+C) 3. Unknown op handling (Patch C) * simplify: remove --no-deps torchtitan hack from Dockerfile torchtitan==0.2.0 dependencies (including torchdata) resolve cleanly on both PT 2.9 and 2.12 NVIDIA base images — verified with dry-run. No need for --no-deps + manual tyro install. * simplify: remove triton/torchvision from requirements, drop grep hacks triton and torchvision are tightly coupled to the torch version and must be pre-installed (e.g. via NVIDIA NGC base image). Pinning them in requirements causes version conflicts on dual-version CI: - triton==3.7.1 replaces NVIDIA-patched builds - torchvision==0.27.1 pulls in torch==2.12.1, destroying PT 2.9 env Dockerfile now does a straightforward pip install of both requirements files with no grep filters. * fix: shrink transformer training test to avoid OOM on shared GPUs The test only verifies that magi_compile training runs and updates parameters — no need for a 1024-hidden, 4096-seqlen model. Reduce to tiny config (hidden=64, seq=32, batch=2) to use <100 MiB instead of multiple GiB. --------- Co-authored-by: xlycae <[email protected]> Co-authored-by: cenn <[email protected]>

Adds a
TORCHINDUCTOR_VEC_ISA_OKforvec_isa_okfor A|B testing purposes. Similar setup tofx_graph_remote_cacheto allow for defaultNone.No tests were present for any other config settings here, nor for
vec_isa_okso I didn't add any.Motivation:
PyTorch uses filelock with a timeout to determine if the CPU supports particular intrinsics: pytorch/torch/_inductor/cpu_vec_isa.py
Therefore if 2 processes are running, each processes encounters the HAS_CPU test, if it cannot acquire the lock for checking vec_isa_ok the main thread will be put to sleep. Hence there is a bias towards non-sleeping processes in acquiring the lock i.e. new spawned processes.
To avoid this, use a env variable so that each process is aware of this without going through the check.
cc @H-Huang @awgu @kwen2501 @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @c-p-i-o @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @mcarilli @ptrblck @leslie-fang-intel @EikanWang @voznesenskym @penguinwu @Guobing-Chen @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang @aakhundov @rec @xmfan