diff --git a/autonerves/jax_wrapper.py b/autonerves/jax_wrapper.py index 72db1cd..05bc675 100644 --- a/autonerves/jax_wrapper.py +++ b/autonerves/jax_wrapper.py @@ -48,8 +48,8 @@ # Append rather than overwrite: replacing the value silently discarded any # flags the user or a batch script had set (e.g. --xla_dump_to=..., - # --xla_gpu_autotune_level=0), which is indistinguishable from those flags - # having no effect. + # --xla_gpu_autotune_level=0, --xla_gpu_enable_triton_gemm=false), which is + # indistinguishable from those flags having no effect. if xla_env: os.environ["XLA_FLAGS"] = f"{xla_env} --xla_disable_hlo_passes=constant_folding" else: @@ -61,16 +61,27 @@ f"{os.environ['XLA_FLAGS']} --xla_gpu_autotune_level=0" ) + if "--xla_gpu_enable_triton_gemm" not in os.environ["XLA_FLAGS"]: + os.environ["XLA_FLAGS"] = ( + f"{os.environ['XLA_FLAGS']} --xla_gpu_enable_triton_gemm=false" + ) + 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. + single fusion on an A100, autolens_profiling jax_compile finding 6). Because + with autotuning off XLA otherwise lowers dense float64 matrix products to an + un-tuned Triton kernel that is ~5x slower than cuBLAS (curvature matrix + 25.5 ms vs 4.8 ms on an A100, autolens_profiling job 342333), Triton GEMM + emission is also disabled (--xla_gpu_enable_triton_gemm=false) so those + products go to cuBLAS. + + To change either, include an explicit --xla_gpu_autotune_level= and/or + --xla_gpu_enable_triton_gemm= in the XLA_FLAGS environment + variable before running your script — pre-set flags are always respected, + and with an explicit autotune level Triton GEMM is left to XLA (it is + autotuned against cuBLAS there). """ ) diff --git a/test_autonerves/test_jax_wrapper.py b/test_autonerves/test_jax_wrapper.py index 7eb8437..3063682 100644 --- a/test_autonerves/test_jax_wrapper.py +++ b/test_autonerves/test_jax_wrapper.py @@ -97,11 +97,26 @@ def test_x64_enabled_by_default(clean_env): AUTOTUNE_OFF = "--xla_gpu_autotune_level=0" +TRITON_OFF = "--xla_gpu_enable_triton_gemm=false" def test_autotune_disabled_by_default(clean_env): reload_wrapper() - assert AUTOTUNE_OFF in os.environ["XLA_FLAGS"] + flags = os.environ["XLA_FLAGS"] + assert AUTOTUNE_OFF in flags + # With autotuning off, XLA would otherwise emit an un-tuned Triton kernel + # for dense float64 GEMMs (~5x slower than cuBLAS on an A100). + assert TRITON_OFF in flags + + +def test_triton_gemm_preset_respected(clean_env): + clean_env.setenv("XLA_FLAGS", "--xla_gpu_enable_triton_gemm=true") + reload_wrapper() + flags = os.environ["XLA_FLAGS"] + assert AUTOTUNE_OFF in flags + assert "--xla_gpu_enable_triton_gemm=true" in flags + assert TRITON_OFF not in flags + assert flags.count("--xla_gpu_enable_triton_gemm") == 1 def test_autotune_preset_level_respected(clean_env): @@ -111,6 +126,8 @@ def test_autotune_preset_level_respected(clean_env): assert "--xla_gpu_autotune_level=3" in flags assert AUTOTUNE_OFF not in flags assert CONSTANT_FOLDING in flags + # An explicit level means XLA's own Triton GEMM behaviour is left alone. + assert TRITON_OFF not in flags def test_autotune_composes_with_user_flags(clean_env): @@ -120,3 +137,4 @@ def test_autotune_composes_with_user_flags(clean_env): assert "--xla_dump_to=/tmp/foo" in flags assert CONSTANT_FOLDING in flags assert AUTOTUNE_OFF in flags + assert TRITON_OFF in flags