-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reduce one multiplication in tosa to arith sigmoid #982
Comments
I think we will ultimately do a lot better by just handling polynomial approximation and evaluation more generally. My rough plan is to add a polynomial.evaluate op, which can then be lowered via horner (or better!), and would replace this hard coded lowering. Mostly we have this implemented so that we could start collecting some basic benchmarks of neural network lowering. And then, even later, the hard coded approximation would be replaced by a remez solver so the accuracy and domain may vary as inputs. |
In other words, while I wouldn't object to a patch for this, we may as well focus our efforts on the longer term plan. |
Sounds good. Just it was a bit obvious so I had to go and say it. Your plan sounds great
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Jeremy Kun ***@***.***>
Sent: Saturday, September 21, 2024 11:58:11 AM
To: google/heir ***@***.***>
Cc: Muthu Annamalai ***@***.***>; Author ***@***.***>
Subject: [EXTERNAL] Re: [google/heir] reduce one multiplication in tosa to arith sigmoid (Issue #982)
In other words, while I wouldn't object to a patch for this, we may as well focus our efforts on the longer term plan.
—
Reply to this email directly, view it on GitHub<#982 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/APGLTDEON5PTRDUJFCLZESLZXW6UHAVCNFSM6AAAAABOTZ7FLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRVGI4DQMRXGQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
The operation balancer pass rebalances this multiplication btw - 704df21 In generality, Horner's method is really cool though! I think integrating that into a generic solver would be great. |
In recent implementation of lib/Conversion/TosaToSecretArith/TosaToSecretArith.cpp we lower Tosa::sigmoid() to degree-3 polynomial approximation as$-0.004x^3 + 0.197 * x + 0.5$ . It could have used Horner's rule instead of direct computation.
Further, while current implementation computes the polynomial directly a better way would be to compute it as,
$x *(0.197 - 0.004 x^2) + 0.5 $ where the number of arith::mulop is fewer by 1.
If we had easy ability to compute complex numbers we can further break down the compute as 2 products from applying the fundamental theorem of algebra.
The text was updated successfully, but these errors were encountered: