Repository navigation
Fix vmap of tri_inv ignoring the triangular flags - #4748
Merged
Merged
Conversation
zcbenz
approved these changes
Oct 25, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Inverse::vmapalways callslinalg::inv, so it ignores thetri_andupper_flags on the primitive. Undermx.vmap,tri_invreturns the full inverse instead of the triangular one, with no error.solve_triangularandcholesky_invgo through the same primitive, so they're affected too.It only shows up when the unused triangle is nonzero, which happens with packed LU factors or matrices where only one triangle is meaningful.
The vmap rule was added in #849, before #1307 gave
Inversethe triangular state, and it never picked up the new flags.Repro (CPU):
The fix calls
linalg::tri_inv(a, upper_, ...)whentri_is set and leaves the axis handling as it was.I added
test_vmap_tri_inverse, which checks upper and lower within_axes0 and 1 against the call without vmap. It fails before the fix and passes after.test_vmap,test_linalgandtest_autogradall pass locally, and pre-commit is clean. My local build is CPU only, so CI will cover Metal.