Skip to content

Commit 48e16f4

Browse files
committed
Docs tidy
1 parent f24ca8e commit 48e16f4

File tree

6 files changed

+941
-515
lines changed

6 files changed

+941
-515
lines changed

docs/source/01-decode.ipynb

Lines changed: 63 additions & 3 deletions
Large diffs are not rendered by default.

docs/source/02-value-stats.ipynb

Lines changed: 797 additions & 508 deletions
Large diffs are not rendered by default.

docs/source/index.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,72 @@ handling various current and proposed floating point types:
3535
- `IEEE WG P3109 <https://github.com/awf/P3109-Public/blob/main/Shared%20Reports/P3109%20WG%20Interim%20report.pdf>`_: P{p} for p in 1..7
3636
- Types from the `OCP MX <https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf>`_ spec: E8M0, INT8, and FP4, FP6 types
3737

38+
Example
39+
-------
40+
This table (from example notebook :doc:`value-stats <02-value-stats>`) shows how
41+
gfloat has been used to tabulate properties of various floating point formats.
42+
43+
- name: Format
44+
- B: Bits in the format
45+
- P: Precision in bits
46+
- E: Exponent field width in bits
47+
- smallest: Smallest positive value
48+
- smallest_normal: Smallest positive normal value, NaN if no finite values are normal
49+
- max: Largest finite normal value, NaN if all finite values are subnormal
50+
- num_nans: Number of NaN values
51+
- num_infs: Number of infinities (2 or 0)
52+
53+
======== === === === =========== ================= ============ =========== ======
54+
name B P E smallest smallest_normal max num_nans infs
55+
======== === === === =========== ================= ============ =========== ======
56+
ocp_e2m1 4 2 2 0.5 1 6 0 0
57+
ocp_e2m3 6 4 2 0.125 1 7.5 0 0
58+
ocp_e3m2 6 3 3 0.0625 0.25 28 0 0
59+
ocp_e4m3 8 4 4 ≈0.0019531 0.015625 448 2 0
60+
ocp_e5m2 8 3 5 ≈1.5259e-05 ≈6.1035e-05 57344 6 2
61+
p3109_p1 8 1 7 ≈2.1684e-19 ≈2.1684e-19 ≈9.2234e+18 1 2
62+
p3109_p2 8 2 6 ≈2.3283e-10 ≈4.6566e-10 ≈2.1475e+09 1 2
63+
p3109_p3 8 3 5 ≈7.6294e-06 ≈3.0518e-05 49152 1 2
64+
p3109_p4 8 4 4 ≈0.00097656 0.0078125 224 1 2
65+
p3109_p5 8 5 3 0.0078125 0.125 15 1 2
66+
p3109_p6 8 6 2 0.015625 0.5 3.875 1 2
67+
binary16 16 11 5 ≈5.9605e-08 ≈6.1035e-05 65504 2046 2
68+
bfloat16 16 8 8 ≈9.1835e-41 ≈1.1755e-38 ≈3.3895e+38 254 2
69+
binary32 32 24 8 ≈1.4013e-45 ≈1.1755e-38 ≈3.4028e+38 ≈1.6777e+07 2
70+
binary64 64 53 11 4.9407e-324 ≈2.2251e-308 ≈1.7977e+308 ≈9.0072e+15 2
71+
ocp_e8m0 8 1 8 ≈5.8775e-39 ≈5.8775e-39 ≈1.7014e+38 1 0
72+
ocp_int8 8 8 0 0.015625 n/a ≈ 1.9844 0 0
73+
======== === === === =========== ================= ============ =========== ======
74+
75+
In the above table, values which are not exact are indicated with the "≈" symbol.
76+
And here's the same table, but with values which don't render exactly as short floats
77+
printed as rationals times powers of 2:
78+
79+
======== === === === =========== ================= ======================================== ====================================== ======
80+
name B P E smallest smallest_normal max num_nans infs
81+
======== === === === =========== ================= ======================================== ====================================== ======
82+
ocp_e2m1 4 2 2 0.5 1 6 0 0
83+
ocp_e2m3 6 4 2 0.125 1 7.5 0 0
84+
ocp_e3m2 6 3 3 0.0625 0.25 28 0 0
85+
ocp_e4m3 8 4 4 2^-9 0.015625 448 2 0
86+
ocp_e5m2 8 3 5 2^-16 2^-14 57344 6 2
87+
p3109_p1 8 1 7 2^-62 2^-62 2^63 1 2
88+
p3109_p2 8 2 6 2^-32 2^-31 2^31 1 2
89+
p3109_p3 8 3 5 2^-17 2^-15 49152 1 2
90+
p3109_p4 8 4 4 2^-10 0.0078125 224 1 2
91+
p3109_p5 8 5 3 0.0078125 0.125 15 1 2
92+
p3109_p6 8 6 2 0.015625 0.5 3.875 1 2
93+
binary16 16 11 5 2^-24 2^-14 65504 2046 2
94+
bfloat16 16 8 8 2^-133 2^-126 255/128*2^127 254 2
95+
binary32 32 24 8 2^-149 2^-126 16777215/8388608*2^127 8388607/4194304*2^23 2
96+
binary64 64 53 11 4.9407e-324 2^-1022 9007199254740991/9007199254740992*2^1024 4503599627370495/4503599627370496*2^53 2
97+
ocp_e8m0 8 1 8 2^-127 2^-127 2^127 1 0
98+
ocp_int8 8 8 0 0.015625 n/a 127/64*2^0 0 0
99+
======== === === === =========== ================= ======================================== ====================================== ======
100+
101+
102+
See Also
103+
--------
38104

39105
GFloat, being a pure Python library, favours readability and extensibility over speed
40106
(although the `*_ndarray` functions are reasonably fast for large arrays).
@@ -47,6 +113,9 @@ For fast implementations of these datatypes see, for example,
47113
To get started with the library, we recommend perusing the notebooks,
48114
otherwise you may wish to jump straight into the API.
49115

116+
Contents
117+
========
118+
50119
.. toctree::
51120
:hidden:
52121

docs/source/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# Copyright (c) 2024 Graphcore Ltd. All rights reserved.
22

33
import pandas
4+
from typing import Callable
45
from IPython.display import HTML
56

67

7-
def pandas_render(df: pandas.DataFrame) -> HTML:
8+
def pandas_render(df: pandas.DataFrame, **kwargs) -> HTML:
89
"""
910
Render a dataframe, hiding the index,
1011
and set ID to minimize diffs for notebook regression tests
1112
"""
12-
return HTML(df.style.hide().set_uuid("my_id").to_html())
13+
s = df.style.hide().set_uuid("my_id")
14+
for f, v in kwargs.items():
15+
if isinstance(getattr(s, f, None), Callable):
16+
s = getattr(s, f)(v)
17+
else:
18+
s = s.format(**{f: v})
19+
return HTML(s.to_html())

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jaxlib
66
jax
77
airium
88
pandas
9+
matplotlib
910

1011
# Requirements for development
1112
pre-commit

src/gfloat/formats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ def format_info_p3109(precision: int) -> FormatInfo:
212212
]
213213

214214
all_formats = [
215-
format_info_ocp_e8m0,
216-
format_info_ocp_int8,
217215
*_tiny_formats,
218216
*_fp8_formats,
219217
*_fp16_formats,
220218
format_info_binary32,
221219
format_info_binary64,
220+
format_info_ocp_e8m0,
221+
format_info_ocp_int8,
222222
]
223223

224224
# ------

0 commit comments

Comments
 (0)