From 750ff4fc7dc32e020f7df2e40287a9d729da4688 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Fri, 17 Jul 2026 09:14:14 +0100 Subject: [PATCH] feat: default --xla_gpu_autotune_level=0 in jax_wrapper (env-respecting) GPU autotuning dominates cold JAX compiles (up to ~7min for one fusion, autolens_profiling#74: 17x cold probe, -40% cold full fit off) with no measured eval speed-up on PyAuto likelihoods. Appended to XLA_FLAGS unless the user already sets an autotune level. Stacks with the default compilation cache (#128): worst-case first-fit ~70min -> ~30s. Co-Authored-By: Claude Fable 5 --- autoconf/jax_wrapper.py | 19 ++++++++++++++++++ test_autoconf/test_jax_wrapper.py | 32 +++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/autoconf/jax_wrapper.py b/autoconf/jax_wrapper.py index 17ece83..0777513 100644 --- a/autoconf/jax_wrapper.py +++ b/autoconf/jax_wrapper.py @@ -39,6 +39,25 @@ else: os.environ["XLA_FLAGS"] = "--xla_disable_hlo_passes=constant_folding" +if "--xla_gpu_autotune_level" not in os.environ.get("XLA_FLAGS", ""): + + os.environ["XLA_FLAGS"] = ( + f"{os.environ['XLA_FLAGS']} --xla_gpu_autotune_level=0" + ) + + logger.info( + """ + XLA GPU autotuning has been disabled by default (--xla_gpu_autotune_level=0): + it dominates cold JAX compile times on GPU (measured up to ~7 minutes for a + single fusion) while giving no measurable evaluation speed-up on PyAuto + likelihoods. + + To re-enable autotuning, include an explicit --xla_gpu_autotune_level= + in the XLA_FLAGS environment variable before running your script — a + pre-set level is always respected. + """ + ) + jax_enable_x64 = os.environ.get("JAX_ENABLE_X64") if jax_enable_x64 is None: diff --git a/test_autoconf/test_jax_wrapper.py b/test_autoconf/test_jax_wrapper.py index 74c8f9c..00fc714 100644 --- a/test_autoconf/test_jax_wrapper.py +++ b/test_autoconf/test_jax_wrapper.py @@ -35,7 +35,7 @@ def reload_wrapper(): def test_xla_flags_set_when_unset(clean_env): reload_wrapper() - assert os.environ["XLA_FLAGS"] == CONSTANT_FOLDING + assert os.environ["XLA_FLAGS"].startswith(CONSTANT_FOLDING) def test_xla_flags_appended_not_clobbered(clean_env): @@ -51,7 +51,9 @@ def test_xla_flags_unchanged_when_already_present(clean_env): preset = f"--xla_dump_to=/tmp/foo {CONSTANT_FOLDING}" clean_env.setenv("XLA_FLAGS", preset) reload_wrapper() - assert os.environ["XLA_FLAGS"] == preset + # constant_folding is not re-appended; only the autotune default is added. + assert os.environ["XLA_FLAGS"].startswith(preset) + assert os.environ["XLA_FLAGS"].count(CONSTANT_FOLDING) == 1 def test_cache_dir_defaulted_when_unset(clean_env): @@ -92,3 +94,29 @@ def test_min_compile_time_respects_preset_value(clean_env): def test_x64_enabled_by_default(clean_env): reload_wrapper() assert os.environ["JAX_ENABLE_X64"] == "True" + + +AUTOTUNE_OFF = "--xla_gpu_autotune_level=0" + + +def test_autotune_disabled_by_default(clean_env): + reload_wrapper() + assert AUTOTUNE_OFF in os.environ["XLA_FLAGS"] + + +def test_autotune_preset_level_respected(clean_env): + clean_env.setenv("XLA_FLAGS", "--xla_gpu_autotune_level=3") + reload_wrapper() + flags = os.environ["XLA_FLAGS"] + assert "--xla_gpu_autotune_level=3" in flags + assert AUTOTUNE_OFF not in flags + assert CONSTANT_FOLDING in flags + + +def test_autotune_composes_with_user_flags(clean_env): + clean_env.setenv("XLA_FLAGS", "--xla_dump_to=/tmp/foo") + reload_wrapper() + flags = os.environ["XLA_FLAGS"] + assert "--xla_dump_to=/tmp/foo" in flags + assert CONSTANT_FOLDING in flags + assert AUTOTUNE_OFF in flags