Skip to content

Honour unit_diagonal in the MLX SolveTriangular dispatch - #2396

Open
guillaume-osmo wants to merge 1 commit into
pymc-devs:mainfrom
guillaume-osmo:fix-mlx-unit-diagonal
Open

Honour unit_diagonal in the MLX SolveTriangular dispatch#2396
guillaume-osmo wants to merge 1 commit into
pymc-devs:mainfrom
guillaume-osmo:fix-mlx-unit-diagonal

Conversation

@guillaume-osmo

Copy link
Copy Markdown

Closes #2384.

Motivation

mlx_funcify_SolveTriangular read op.lower but never op.unit_diagonal, and mx.linalg.solve_triangular has no such argument, so the flag was dropped and the stored diagonal used instead of ones. Nothing raised.

As the issue notes, this also silently broke lu_solve, whose unit-triangular L is packed into the LU array with U's diagonal occupying those slots — so any graph where reuse_decomposition_multiple_solves collapses two solves onto one factorization returned wrong numbers.

Implementation

Overwrite the diagonal with ones before the solve when the flag is set. The helper broadcasts over leading batch dims, so the batched case is covered.

Tests

  • test_mlx_SolveTriangular now parametrizes over unit_diagonal (× the existing lower), so the four combinations are covered.
  • test_mlx_SolveTriangular_unit_diagonal_lu_solve pins the lu_factor + lu_solve path the issue calls out.

The batched lu_solve case is deliberately not covered here — it is blocked on #2385, and is added in that PR instead.

Full tests/link/mlx/ suite: no regressions.

)

`mlx_funcify_SolveTriangular` read `op.lower` but never `op.unit_diagonal`,
and `mx.linalg.solve_triangular` has no such argument, so the flag was
dropped and the stored diagonal used instead of ones. Nothing raised.

This also silently broke `lu_solve`, whose unit-triangular `L` is packed
into the LU array with `U`'s diagonal in those slots, so any graph where
`reuse_decomposition_multiple_solves` collapses two solves onto one
factorization returned wrong numbers on MLX.

Overwrite the diagonal with ones before the solve when the flag is set;
this broadcasts over leading batch dims, so the batched case is covered too.

`test_mlx_SolveTriangular` now parametrizes over `unit_diagonal`, and a new
test pins the `lu_factor` + `lu_solve` path.
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.

MLX backend silently ignores unit_diagonal in SolveTriangular

1 participant