Skip to content

Commit 2ad3ce7

Browse files
authored
Merge pull request #11 from graphcore-research/packaging
2 parents ea65ec4 + a58d9bd commit 2ad3ce7

32 files changed

+1807
-565
lines changed

.github/workflows/ci.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
name: unit tests
1+
# Copyright (c) 2024 Graphcore Ltd. All rights reserved.
2+
3+
name: CI
24
on:
35
pull_request:
46
push:
@@ -25,10 +27,18 @@ jobs:
2527
run: |
2628
python3 -m pip freeze
2729
30+
- name: Pre-commit all files
31+
run: |
32+
pre-commit run --all-files
33+
2834
- name: Run unit tests
2935
run: |
3036
pytest .
3137
38+
- name: MyPy
39+
run: |
40+
mypy --disallow-untyped-defs --enable-error-code redundant-expr src test
41+
3242
- name: Ensure that docs build
3343
run: |
3444
cd docs && make html

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) 2024 Graphcore Ltd. All rights reserved.
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]
@@ -159,3 +161,4 @@ cython_debug/
159161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160162
#.idea/
161163
.vscode/settings.json
164+
.vscode/launch.json

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
# Copyright (c) 2024 Graphcore Ltd. All rights reserved.
2+
13
repos:
24
- repo: https://github.com/pre-commit/pre-commit-hooks
35
rev: v4.6.0
46
hooks:
57
- id: check-yaml
68
- id: end-of-file-fixer
79
- id: trailing-whitespace
10+
811
- repo: https://github.com/psf/black
912
rev: 24.4.0
1013
hooks:
1114
- id: black
15+
16+
- repo: local
17+
hooks:
18+
- id: etc/check-copyright.sh
19+
name: check copyright
20+
entry: etc/check-copyright.sh
21+
language: script
22+
exclude: |
23+
(?x)^(
24+
docs/Makefile|
25+
docs/make.bat|
26+
.*\.md|
27+
(.*/|)requirements.*\.txt
28+
)$

.readthedocs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) 2024 Graphcore Ltd. All rights reserved.
2+
13
version: 2
24

35
build:

BUILDING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## BUILDING
2+
3+
```
4+
pip install -e .
5+
( cd docs && make html )
6+
```
7+
8+
#### Pushing
9+
```
10+
sh etc/package.sh
11+
```

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Andrew Fitzgibbon
3+
Copyright (c) 2023 Graphcore Ltd. All rights reserved.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,23 @@ See https://gfloat.readthedocs.io for documentation, or dive into the notebooks
1616

1717
For example, here's a table from the [02-value-stats](docs/source/02-value-stats.ipynb) notebook:
1818

19-
|name|B|P|E|T|lt1|gt1|rt16|maxFinite|minFinite|maxNormal|minNormal|minSubnormal|maxSubnormal|
20-
|--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |
21-
|ocp_e2m1|4|2|2|1|1|5|True|6|-6|6|1|0.5|0.5|
22-
|ocp_e2m3|6|4|2|3|7|23|True|7.5|-7.5|7.5|1|0.125|0.875|
23-
|ocp_e3m2|6|3|3|2|11|19|True|28|-28|28|0.25|0.0625|0.1875|
24-
|ocp_e4m3|8|4|4|3|55|70|True|448|-448|448|0.015625|1*2^-9|7/4*2^-7|
25-
|ocp_e5m2|8|3|5|2|59|63|True|57344|-57344|57344|1*2^-14|1*2^-16|3/2*2^-15|
26-
|p3109_p1|8|1|7|0|62|63|False|1*2^63|-1*2^63|1*2^63|1*2^-62|nan|nan|
27-
|p3109_p2|8|2|6|1|63|62|False|1*2^31|-1*2^31|1*2^31|1*2^-31|1*2^-32|1*2^-32|
28-
|p3109_p3|8|3|5|2|63|62|True|49152|-49152|49152|1*2^-15|1*2^-17|3/2*2^-16|
29-
|p3109_p4|8|4|4|3|63|62|True|224|-224|224|0.0078125|1*2^-10|7/4*2^-8|
30-
|p3109_p5|8|5|3|4|63|62|True|15|-15|15|0.125|0.0078125|15/8*2^-4|
31-
|p3109_p6|8|6|2|5|63|62|True|3.875|-3.875|3.875|0.5|0.015625|31/16*2^-2|
32-
|bfloat16|16|8|8|7|16255|16383|False|255/128*2^127|-255/128*2^127|255/128*2^127|1*2^-126|1*2^-133|127/64*2^-127|
33-
|ocp_int8|8|8|0|7|63|63|True|127/64*2^0|-2|nan|nan|0.015625|127/64*2^0|
34-
|ocp_e8m0|8|1|8|0|127|127|False|1*2^127|1*2^-127|1*2^127|1*2^-127|nan|nan|
19+
|name|B: Bits in the format|P: Precision in bits|E: Exponent field width in bits|0<x<1|1<x<Inf|Exact in float16?|maxFinite|minFinite|maxNormal|minNormal|minSubnormal|maxSubnormal|
20+
|--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |
21+
|ocp_e2m1|4|2|2|1|5|True|6|-6|6|1|0.5|0.5|
22+
|ocp_e2m3|6|4|2|7|23|True|7.5|-7.5|7.5|1|0.125|0.875|
23+
|ocp_e3m2|6|3|3|11|19|True|28|-28|28|0.25|0.0625|0.1875|
24+
|ocp_e4m3|8|4|4|55|70|True|448|-448|448|0.015625|1*2^-9|7/4*2^-7|
25+
|ocp_e5m2|8|3|5|59|63|True|57344|-57344|57344|1*2^-14|1*2^-16|3/2*2^-15|
26+
|p3109_p1|8|1|7|62|63|False|1*2^63|-1*2^63|1*2^63|1*2^-62|nan|nan|
27+
|p3109_p2|8|2|6|63|62|False|1*2^31|-1*2^31|1*2^31|1*2^-31|1*2^-32|1*2^-32|
28+
|p3109_p3|8|3|5|63|62|True|49152|-49152|49152|1*2^-15|1*2^-17|3/2*2^-16|
29+
|p3109_p4|8|4|4|63|62|True|224|-224|224|0.0078125|1*2^-10|7/4*2^-8|
30+
|p3109_p5|8|5|3|63|62|True|15|-15|15|0.125|0.0078125|15/8*2^-4|
31+
|p3109_p6|8|6|2|63|62|True|3.875|-3.875|3.875|0.5|0.015625|31/16*2^-2|
32+
|bfloat16|16|8|8|16255|16383|False|255/128*2^127|-255/128*2^127|255/128*2^127|1*2^-126|1*2^-133|127/64*2^-127|
33+
|ocp_int8|8|8|0|63|63|True|127/64*2^0|-2|nan|nan|0.015625|127/64*2^0|
34+
|ocp_e8m0|8|1|8|127|127|False|1*2^127|1*2^-127|1*2^127|1*2^-127|nan|nan|
3535

36-
Stats collected for each format are:
37-
- B: Bits in the format
38-
- P: Precision in bits
39-
- E: Exponent field width in bits
40-
- T: Trailing significand field width in bits
41-
- lt1: Number of values x such that `0 < x < 1`
42-
- gt1: Number of values x such that `1 < x < Inf`
43-
- rt16: True if all values are exactly representable in IEEE binary16
44-
- maxFinite: Largest finite value
45-
- minFinite: Smallest finite value
46-
- maxNormal: Largest finite normal value, NaN if all finite values are subnormal
47-
- minNormal: Smallest positive normal value, NaN if all finite values are subnormal
48-
- minSubnormal: Smallest positive subnormal value, NaN if no finite values are - subnormal
49-
- maxSubnormal: Largest subnormal value, NaN if no finite values are subnormal
50-
51-
52-
53-
## BUILDING
54-
55-
```
56-
pip install -e .
57-
cd docs
58-
make html
59-
cd ..
60-
```
61-
62-
#### Pushing
63-
```
64-
rm -rf dist
65-
pip install build twine
66-
python -m build
67-
echo __token__ | twine upload --repository pypi dist/* --verbose
68-
```
6936

7037
#### Notes
7138

docs/source/01-decode.ipynb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"<!-- # Copyright (c) 2024 Graphcore Ltd. All rights reserved. -->\n",
88
"\n",
9-
"## GFloat Basics\n",
9+
"# GFloat Basics\n",
1010
"\n",
1111
"This notebook shows the use of `decode_float` to explore properties of some float formats.\n"
1212
]
@@ -29,7 +29,7 @@
2929
"cell_type": "markdown",
3030
"metadata": {},
3131
"source": [
32-
"### List all the values in a format\n",
32+
"## List all the values in a format\n",
3333
"\n",
3434
"The first example shows how to list all values in a given format.\n",
3535
"We will choose the [OCP](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1) E5M2 format.\n",
@@ -273,7 +273,7 @@
273273
"cell_type": "markdown",
274274
"metadata": {},
275275
"source": [
276-
"### Additional format info: special values, min, max, dynamic range\n",
276+
"## Additional format info: special values, min, max, dynamic range\n",
277277
"\n",
278278
"In addition, `FormatInfo` can tell us about other characteristics of each format.\n",
279279
"To reproduce some of the OCP spec's tables 1 and 2:"
@@ -316,14 +316,16 @@
316316
" (\"Min subnormal number \", lambda fi: fi.smallest_subnormal),\n",
317317
" (\"Dynamic range (binades)\", lambda x: round(compute_dynamic_range(x))),\n",
318318
"):\n",
319-
" print(f\"{prop} {probe(format_info_ocp_e4m3):<20} {probe(format_info_ocp_e5m2):<20} {probe(format_info_p3109(3))}\")"
319+
" print(\n",
320+
" f\"{prop} {probe(format_info_ocp_e4m3):<20} {probe(format_info_ocp_e5m2):<20} {probe(format_info_p3109(3))}\"\n",
321+
" )"
320322
]
321323
},
322324
{
323325
"cell_type": "markdown",
324326
"metadata": {},
325327
"source": [
326-
"### How do subnormals affect dynamic range?\n",
328+
"## How do subnormals affect dynamic range?\n",
327329
"\n",
328330
"Most, if not all, low-precision formats include subnormal numbers, as they increase the number of values near zero, and increase dynamic range.\n",
329331
"A natural question is \"by how much?\". To answer this, we can create a mythical new format, a copy of `e4m3`, but with `has_subnormals` set to true."

0 commit comments

Comments
 (0)