-
Notifications
You must be signed in to change notification settings - Fork 515
9080 expose mat mul precision #9081
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
base: master
Are you sure you want to change the base?
Conversation
Do I need to reduce the verbosity of my unit test?
|
|
||
|
||
# Some of this description adapted from Jax documentation. | ||
def set_mat_mul_precision(precision: _PrecisionType) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should we move these functions to a separate precision.py
file and import these here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the suggestion - I expected it and mentioned in a comment to look at how torch.backends.mps and cpu is implemented. Trying to stay parallel to them.
|
||
# 22 bits is an estimate of precision in the | ||
# six pass technique. | ||
worst_atol = torch.tensor(1 - ((2**22 - 1) / 2**22)**2, dtype=torch.float64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have heard from an authoritative source (I'll share offline) that the correct error for 1 pass mode (default) is 1 - (255/256)**2. I did not get as Clear of guidance on 3 and 6 pass mode so I empirically derived tighter bounds. I believe that there's an argument that 6 rounds of bf16 basically gets you fp32, but that there could still be some delta on the final bit due to implementation details.
I added a binding to get the mat mul precision to the init_python_bindings.cpp
I exposed it as a brand new module, torch_xla.backends. This is an ackward name but the goal is to eventually migrate this to torch.backends.xla, to parallel torch.backends.{cuda, cpu, mps, etc}.
I got advice from on very exact numerics for default (1 pass). I made estimates on the 3 pass and 6 pass technique.
I was careful to ensure that there was a non-zero delta from the torch64 cpu calculation - it's easy to make a mistake and end up with your "reference" math also be rounded.
I have a detailed guide on this coming after this PR goes in.