Skip to content
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

[BugFix] Print doubles with precision 17 in SaveJSON and TVM script printer #7846

Conversation

MasterJH5574
Copy link
Contributor

This PR fixes a bug in SaveLoad, which didn't save enough digits for double value and may cause precision loss when loading the value from JSON again. Besides, this PR adds a regression test for the precision loss case.

Before this PR, double value is saved with precision 16. However, actually we should save at least 17 digits to avoid precision loss, according to IEEE 754-1985 standard:

When rounding to nearest conversion from binary to decimal and back to binary shall be the identity as long as the
decimal string is carried to the maximum precision specified in Table 2, namely, 9 digits for single and 17 digits for
double.

Reference

  • "IEEE Standard for Binary Floating-Point Arithmetic," in ANSI/IEEE Std 754-1985 , vol., no., pp.1-20, 12 Oct. 1985, doi: 10.1109/IEEESTD.1985.82928.

cc @tqchen @junrushao1994

@junrushao
Copy link
Member

Thanks for fixing the subtle issue! BTW, would you like to also fix the TVM script printer?

@junrushao junrushao self-assigned this Apr 14, 2021
@MasterJH5574
Copy link
Contributor Author

Okay, I'm gonna to take a look soon.

@MasterJH5574 MasterJH5574 changed the title [BugFix] SaveJSON type double with precision 17 [BugFix] Print doubles with precision 17 in SaveJSON and TVM script printer Apr 14, 2021
@MasterJH5574
Copy link
Contributor Author

@junrushao1994 I've fixed the TVM script printer. Would you like to take another look? Thanks!

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. CC: @Hzfengsy

Copy link
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tqchen
Copy link
Member

tqchen commented Apr 14, 2021

Thanks @Hzfengsy @junrushao1994

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…rinter (apache#7846)

* [BugFix] SaveJSON type double with precision 17

* [BugFix] Fix for TVM script printer
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…rinter (apache#7846)

* [BugFix] SaveJSON type double with precision 17

* [BugFix] Fix for TVM script printer
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…rinter (apache#7846)

* [BugFix] SaveJSON type double with precision 17

* [BugFix] Fix for TVM script printer
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
…rinter (apache#7846)

* [BugFix] SaveJSON type double with precision 17

* [BugFix] Fix for TVM script printer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants