Skip to content

fix(jax_wrapper): disable Triton GEMM when autotuning is off (fp64 GEMM 5x slower) - #162

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/xla-triton-gemm-off
Sep 8, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/xla-triton-gemm-off

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

autonerves/jax_wrapper.py appends --xla_gpu_autotune_level=0 to XLA_FLAGS by default to keep cold GPU compile times short (up to ~7 min for one fusion on an A100 with autotuning on). With autotuning off, XLA lowers dense float64 matrix products to an un-tuned Triton GEMM kernel instead of cuBLAS: on the RAL A100 the pixelized-inversion curvature matrix F = A.T @ A (15361×1560, fp64) takes 25.5 ms versus 4.8 ms with cuBLASLt (autolens_profiling job 342333, fresh compilation cache per arm, HLO dumps confirm __triton_nested_gemm_fusion vs __cublas$lt$matmul).

This PR keeps the level-0 default and, in the same default block, also appends --xla_gpu_enable_triton_gemm=false unless --xla_gpu_enable_triton_gemm is already present in XLA_FLAGS. Measured effect: cuBLAS lowering, 0.07 s compile for that kernel, F back to 4.8 ms, results bit-identical to the current level-0 default. A user who sets an explicit --xla_gpu_autotune_level=<n> gets XLA's full behaviour (Triton candidates are then autotuned against cuBLAS), so the new flag is not added in that case.

Why this went unnoticed: JAX persists XLA's per-fusion autotune cache next to the compilation cache by default, keyed by fusion fingerprint rather than by flag. A single autotune-enabled run seeds the node's cache and every later level-0 run on that node reads the cuBLAS choice, so A/Bs on a shared node looked fine while fresh nodes and new shapes paid the slow kernel. Every A100 number produced with the level-0 default since 2026-07-17 on an unseeded node carries ~20 ms per likelihood evaluation of avoidable cost.

Closes #161.

API Changes

None — internal changes only. The default XLA_FLAGS string gains --xla_gpu_enable_triton_gemm=false when the wrapper is the one disabling autotuning; a pre-set --xla_gpu_enable_triton_gemm=<bool> or --xla_gpu_autotune_level=<n> is respected unchanged.
See full details below.

Test Plan

  • python -m pytest test_autonerves/ in the task worktree: 183 passed.
  • CPU-only jax accepts the new flag: XLA_FLAGS="--xla_disable_hlo_passes=constant_folding --xla_gpu_autotune_level=0 --xla_gpu_enable_triton_gemm=false" python -c "import jax, jax.numpy as jnp; print(jnp.ones(3).sum())" → 3.0.
  • Default string with XLA_FLAGS unset: --xla_disable_hlo_passes=constant_folding --xla_gpu_autotune_level=0 --xla_gpu_enable_triton_gemm=false.
  • Post-merge witness on RAL (after HPCPullPyAuto): fresh-cache A100 Delaunay breakdown run with library defaults reports "Curvature matrix (F)" under 6 ms, curvature_matrix_jit_compile under 0.2 s, and device.xla_flags containing --xla_gpu_enable_triton_gemm=false.
Full API Changes (for automation & release notes)

Changed Behaviour

  • autonerves.jax_wrapper (import-time env setup) — when no --xla_gpu_autotune_level is pre-set it still appends --xla_gpu_autotune_level=0, and now also appends --xla_gpu_enable_triton_gemm=false unless --xla_gpu_enable_triton_gemm is already in XLA_FLAGS. The accompanying log message documents both flags and how to override them.

Migration

  • None required. To restore XLA's default Triton GEMM behaviour at level 0, set XLA_FLAGS="... --xla_gpu_enable_triton_gemm=true" before running; to re-enable autotuning, set an explicit --xla_gpu_autotune_level=<n>.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Jbzb2yHwJn5ScwqxngKPqi

With the default --xla_gpu_autotune_level=0, XLA lowers dense float64
matrix products to an un-tuned Triton GEMM kernel instead of cuBLAS: on
the RAL A100 the pixelized-inversion curvature matrix (15361x1560, fp64)
takes 25.5 ms vs 4.8 ms with cuBLASLt (autolens_profiling job 342333,
fresh compilation cache per arm). Keep the level-0 default for compile
time and, in the same block, also append --xla_gpu_enable_triton_gemm=false
unless the user pre-set --xla_gpu_enable_triton_gemm; an explicit autotune
level leaves Triton GEMM to XLA, where it is autotuned against cuBLAS.
Rewrite the log message and extend the tests.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jbzb2yHwJn5ScwqxngKPqi
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_profiling#230

@Jammy2211
Jammy2211 merged commit 0e7163b into main Sep 8, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/xla-triton-gemm-off branch September 8, 2026 13:41
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(jax_wrapper): disable Triton GEMM when autotuning is off (fp64 GEMM 5x slower)

1 participant