xla icon indicating copy to clipboard operation
xla copied to clipboard

Improve the accuracy of asin(x) and asinh(x) for complex x using modified Hull et al algorithm.

Open pearu opened this issue 1 year ago • 15 comments

As in the title.

~Fixes https://github.com/openxla/xla/issues/8553~ - PR https://github.com/openxla/xla/pull/9802 disabled the fix.

Update: the fix to https://github.com/openxla/xla/issues/8553 will be available via https://github.com/openxla/stablehlo/pull/2357

pearu avatar Jan 18 '24 14:01 pearu

Hi @pearu , any update on this PR, can you provide the information requested ? Thanks.

kamaljeeti avatar Feb 12 '24 18:02 kamaljeeti

Hi @pearu , gentle reminder! Thanks.

kamaljeeti avatar Mar 11 '24 11:03 kamaljeeti

Hi @pearu , gentle reminder! Thanks.

@kamaljeeti , thanks for the reminder! The reviewers request for the regression test has been addressed via https://github.com/google/jax/pull/19823 . This PR can be updated after https://github.com/google/jax/pull/20144 has landed.

pearu avatar Mar 11 '24 13:03 pearu

@pearu https://github.com/google/jax/pull/20144 has landed. Could you please help update the PR? :)

penpornk avatar Apr 04 '24 13:04 penpornk

@pearu google/jax#20144 has landed. Could you please help update the PR? :)

@penpornk, certainly :) Meanwhile, https://github.com/openxla/xla/pull/10503 introduced a testing framework for functions with complex inputs in the XLA side. We should use this framework in this PR for asinh as well.

pearu avatar Apr 04 '24 14:04 pearu

Thank you for the heads up! https://github.com/openxla/xla/pull/10503 is now merged. (Many thanks to @reedwm!)

penpornk avatar Apr 05 '24 14:04 penpornk

Hi @ddunl , there are a couple of checks failed on the Cl, can you have a look at them once? Thanks.

kamaljeeti avatar Apr 16 '24 08:04 kamaljeeti

While using asin from asinh for complex inputs is the right way to go (as implemented in this PR), asin itself on complex inputs has very poor accuracy. I am currently implementing complex asin based on https://dl.acm.org/doi/10.1145/275323.275324 and then update this PR accordingly. Meanwhile, I'll mark the PR as a draft.

pearu avatar Apr 16 '24 09:04 pearu

Hi @hawkinsp, can you have a look into this? Thanks.

kamaljeeti avatar May 07 '24 04:05 kamaljeeti

As it turns out, asin/asinh improvements in xla/client/lib/math.cc will not be available for JAX. Therefore, I am currently working on submitting the modified Hull algorithm to StableHLO so that asin/asinh fixes here will be eventually effective also for JAX.

So, this PR should be considered as an improvement to asin/asinh in xla/client math lib that has no effect to the asin/asinh state in JAX.

pearu avatar May 08 '24 14:05 pearu

https://github.com/openxla/stablehlo/pull/2357 implements the modified Hull et al algorithm for StableHLO.

The asin implementations for both XLA and StableHLO are now generated using https://github.com/pearu/functional_algorithms tool that includes the validation of the algorithm against mpmath with the correctness of ULP difference <= 3. While in this PR we are still using tolerance conditions for measuring the difference of asin results and its reference values, using ULP difference is better measure because it does not depend on the magnitude of compared values. https://github.com/openxla/stablehlo/pull/2357 uses ULP difference, doing the same in XLA is planned as a follow-up.

pearu avatar Jun 06 '24 18:06 pearu

@jakevdp Could you please help take another look?

penpornk avatar Jun 17 '24 11:06 penpornk

@hawkinsp @jakevdp Could you please have a look at this PR and approve if it looks good to you?

dimitar-asenov avatar Jul 10 '24 08:07 dimitar-asenov

@hawkinsp @jakevdp gentle ping

golechwierowicz avatar Jul 29 '24 09:07 golechwierowicz

@jakevdp Could you please help take another look at this PR? @pearu has addressed your initial comments.

Also, @GleasonK, would it make sense to request reviews from people who have reviewed https://github.com/openxla/stablehlo/pull/2357 ?

penpornk avatar Aug 06 '24 10:08 penpornk

I see that the function "static XlaOp Hypot(XlaOp x, XlaOp y)". Is it intended? if it is not, could you please remove it?

loislo avatar Aug 22 '24 08:08 loislo