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

Add block formats #8

Merged
merged 12 commits into from
May 1, 2024
Merged

Add block formats #8

merged 12 commits into from
May 1, 2024

Conversation

awf
Copy link
Collaborator

@awf awf commented Apr 24, 2024

Add block formats (e.g. OCP MX)

Add OCP E8M0 type. This is an unsigned format, so we add is_signed to FormatInfo.

Add OCP INT8 type. This represents the significand as twos-complement, so we add is_twos_complement to FormatInfo.

Docs preview at https://gfloat--8.org.readthedocs.build/en/8/

Base automatically changed from Add-MX-subformats to main April 25, 2024 16:25
@awf awf changed the title Add E8M0 Add block formats Apr 26, 2024
@awf awf marked this pull request as ready for review April 30, 2024 06:32
@awf awf requested a review from balancap April 30, 2024 06:32
@@ -201,7 +206,12 @@ def min(self) -> float:
"""
The smallest representable number, typically ``-max``.
"""
return -self.max
if self.is_signed:
return -self.max
Copy link
Collaborator

@scott-griffiths scott-griffiths Apr 30, 2024

Choose a reason for hiding this comment

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

Is this true for format_info_ocp_int8? I can't find a test for it, and it can be asymmetric (max == 1.0 + 63.0 / 64, min == -2.0).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a test that code_of_min decodes to min, and code_of_min is "self-evidently" 2**k-1, so it should be fine, but... I have now added a dense test to this PR which exhaustively enumerates all values and ensures min, max, etc are consistent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to mention: this PR does include OCP int8, but I let it decode 0x80 as a NaN, which is allowed by [at least one reading of] the spec...

"Integer data types use a 2’s complement encoding, but the maximum negative representation
(−2) may be left unused to maintain symmetry between the maximum positive and negative
representations and avoid introducing a negative bias."

But maybe that is to be read as "0x80 should decode to -2, and downstream users can choose not to use it...."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll do it that way, as the spec says "N/A" for NaN, but presumably means "not available" rather than "not applicable".

test/test_round.py Outdated Show resolved Hide resolved
@awf awf merged commit 6c13686 into main May 1, 2024
1 check passed
@awf awf deleted the Add-E8M0 branch May 1, 2024 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants