Skip to content

Optimize chunked delta rule inversion.#4577

Open
h1t35h wants to merge 1 commit into
AI-Hypercomputer:mainfrom
h1t35h:qwen3-gdn-jax-optim
Open

Optimize chunked delta rule inversion.#4577
h1t35h wants to merge 1 commit into
AI-Hypercomputer:mainfrom
h1t35h:qwen3-gdn-jax-optim

Conversation

@h1t35h

@h1t35h h1t35h commented Jul 23, 2026

Copy link
Copy Markdown
  • Replaced jax.scipy.linalg.solve_triangular with invert_unit_lower_triangular_log_depth, a highly optimized log-depth Newton-Schulz iteration implementation with a custom VJP for computing (I+S)^-1.
  • Updated jax.lax.scan unroll parameters in the naive implementation.

Description

  1. Improves performance of triangular identity solver (adds a jax implementation).
  2. Unrolls jax.lax.scan given the small size of the loop XLA is able to optimize on the fly.

Tests

Tested manually attached xprof results.
Before Optimization
For chunk_size: 128
fwd : 96.96 ms
bwd: 127 ms
xprof:
image

After Optimization
fwd: 23 ms
bwd: 52 ms
xprof:
image

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@h1t35h
h1t35h force-pushed the qwen3-gdn-jax-optim branch from 46c0327 to 9478160 Compare July 23, 2026 17:40
def test_invert_unit_lower_triangular_log_depth(self):
"""Test for loss across chunk_size in the following range [16, 32, 64, 128, 256]."""
jax.config.update('jax_enable_x64', True) # Use float64 for precise testing
chunk_sizes = [16, 32, 64, 128, 256]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its valuable to protect multiple chunk sizes, I would just pick one for this test

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated.

@h1t35h
h1t35h force-pushed the qwen3-gdn-jax-optim branch from 9478160 to 88c8a4a Compare July 23, 2026 17:52
@h1t35h
h1t35h requested a review from gobbleturk July 23, 2026 17:53
- Replaced `jax.scipy.linalg.solve_triangular` with `invert_unit_lower_triangular_log_depth`, a highly optimized log-depth Newton-Schulz iteration implementation with a custom VJP for computing `(I+S)^-1`.
- Updated `jax.lax.scan` unroll parameters in the naive implementation.
@h1t35h
h1t35h force-pushed the qwen3-gdn-jax-optim branch from 88c8a4a to 6fd8896 Compare July 24, 2026 04:17
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.

2 participants