-
Notifications
You must be signed in to change notification settings - Fork 74
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
dialects: (builtin) mimic mlir floating point precision for printing and parsing #3607
Conversation
float_str = f"{value:.6e}" | ||
if float(float_str) == value: | ||
float_str = f"{value:.5e}" | ||
index = float_str.find("e") | ||
float_str = float_str[:index] + "0" + float_str[index:] | ||
|
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.
mlir does this interesting thing where it rounds to 5 digits after the comma but still prints the 6th 0
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.
this could hurt performance for a large amount of floats, which can possibly be resolved by just dumping the hex value of the bytes representation as it is done for arrays > ~100ish elements in MLIR:
module {
%cst = arith.constant dense<"0xC3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43C3F508409EEF0842F5DBC141E73B6A43C76B6A43"> : tensor<180xf32>
}
Before I start fixing the all the filechecks that are affected by this, could I get your opinion on whether this should be implemented like this? @superlopuh @alexarice @compor @math-fehr |
My understanding is that the current float parsing/printing was changed recently so that it always roundtripped correctly. Was there a bug in this implementation? I'm not 100% it's worth changing how all the floats are represented. (As a side note I'm not exactly sure if it's even desirable to use scientific notation everywhere for floats, but it's possible I'm missing something.) |
Not really a bug, just diverging between behaviour between mlir/xdsl: for an input
xdsl right now returns:
and mlir (and xdsl with this PR):
The main problem with the current version of xDSL i have right now is when things are backed with bytes storage vs as FloatAttr, for example for
|
I don't have any argument to shoot this down ATM, and I'm in general in favor of such convergence. |
Yep this seems like a great change |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3607 +/- ##
==========================================
- Coverage 90.48% 90.15% -0.33%
==========================================
Files 472 463 -9
Lines 59276 58737 -539
Branches 5637 5631 -6
==========================================
- Hits 53633 52952 -681
- Misses 4205 4346 +141
- Partials 1438 1439 +1 ☔ View full report in Codecov by Sentry. |
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.
Would be good to double-check with @math-fehr
…and parsing format fix filecheck update tests fixing filechecks remaining non-mlir filechecks small x formatting fix pytest remaining lowercase x another remaining lowercase x remove try/except list to tuple
2c7c783
to
9c247d5
Compare
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.
Looks good to me!
I'm running into some precision issues when printing and parsing floats after they have been packed/unpacked.
This PR tries to resolve the issues with printing and parsing, trying to mimic MLIR behaviour as much as possible.