patrick-kidger / lineax

Linear solvers in JAX and Equinox. https://docs.kidger.site/lineax
Apache License 2.0
344 stars 22 forks source link

New solvers #3

Open patrick-kidger opened 1 year ago

patrick-kidger commented 1 year ago
joglekara commented 1 year ago

Thanks for the library. As they said, and another one...

Do you have any intuition whether it would be useful to swap in the cusparse kernels for, say, a tridiagonal solve, and add a custom_linear_solve for the gradient or is that more trouble than worth the performance boost (if any!)?

At the moment, I have a custom written broadcast-based function similar to the one in here but with a, b, c, d being 2D. I suppose I could've used vmap but I thought to trust broadcasting.

But would something like this be better than what XLA comes up with?

https://docs.nvidia.com/cuda/cusparse/index.html#cusparse-t-gtsv2stridedbatch

Thanks again

patrick-kidger commented 1 year ago

I think that would definitely be useful. Note that we actually already have the gradient via our custom primitive (linear_solve_p) so the only difficulty with using cusparse might be adding batch dimensions; off the top of my head I'm not sure if they support that.

But at least in the unbatched case, I reckon that probably would give a performance boost. (Plus I believe their tridiagonal algorithm is stabilised, whereas our current Thomas algorithm is unstablised.)

The only reason we haven't pursued this is that it's not straightforward to make this happen in JAX -- calling out to custom kernels like this isn't very well supported.

joglekara commented 1 year ago

Couple of disparate thoughts

patrick-kidger commented 1 year ago

Something like that! @packquickly may recall why we didn't use the built-in tridiagonal solve algorithm. IIRC it doesn't support batching, and that has to be patched in? (E.g. by vmap'ing jax._src.lax.linalg_tridiagonal_solve_jax.)

quattro commented 1 year ago

Would there be any interest in randomized solvers (e.g., via sketching or randomized trace estimation)?

patrick-kidger commented 1 year ago

Absolutely!