Skip to content

Commit 179c605

Browse files
xadupresdpython
andauthored
Quantization with float 8 (#42)
* equations * add notebook * change alignment * remove unsupported option * update notebook * use black on notebook * requiremens * change the trigger --------- Co-authored-by: Xavier Dupré <xavier.dupre@gmail.com>
1 parent 99dbdbc commit 179c605

31 files changed

Lines changed: 28372 additions & 27637 deletions

.github/workflows/check_urls.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Check URLs
22

3-
on: [push]
3+
on:
4+
schedule:
5+
- cron: '0 0 0 * *'
46

57
jobs:
68
build:
@@ -15,8 +17,8 @@ jobs:
1517
subfolder: mlstatpy
1618
file_types: .md,.py,.rst,.ipynb
1719
print_all: false
18-
timeout: 2
19-
retry_count# : 2
20+
timeout: 5
21+
retry_count# : 3
2022
# exclude_urls: https://dumps.wikimedia.org/other/pageviews/%Y/%Y-%m/pageviews-%Y%m%d-%H0000.gz,https://dumps.wikimedia.org/frwiki/latest/latest-all-titles-in-ns0.gz
2123
exclude_patterns: https://dumps.wikimedia.org/
2224
# force_pass : true
@@ -27,8 +29,8 @@ jobs:
2729
subfolder: _doc
2830
file_types: .md,.py,.rst,.ipynb
2931
print_all: false
30-
timeout: 2
31-
retry_count# : 2
32-
exclude_urls: https://hal.archives-ouvertes.fr/hal-00990252/document
33-
exclude_patterns: https://www.data.gouv.fr/fr/datasets/r/e3d83ab3-dc52-4c99-abaf-8a38050cc68c
32+
timeout: 5
33+
retry_count# : 3
34+
exclude_urls: https://hal.archives-ouvertes.fr/hal-00990252/document,https://github.com/onnx/models/raw/main/vision/classification/mobilenet/model/mobilenetv2-12.onnx
35+
exclude_patterns: https://www.data.gouv.fr/fr/datasets/r/e3d83ab3-dc52-4c99-abaf-8a38050cc68c,https://github.com/onnx/models/raw/main/vision/classification/mobilenet/model/mobilenetv2-12.onnx
3436
# force_pass : true

.gitignore

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
*.dot
2+
*.dylib
3+
*.prof
14
*.pyc
25
*.pyd
3-
*.dylib
46
*.so
5-
coverage.html/*
6-
_cache/*
77
.coverage
8-
dist/*
9-
build/*
108
.eggs/*
9+
_cache/*
10+
build/*
11+
dist/*
1112
*egg-info/*
1213
onnxruntime_profile*
1314
prof
1415
temp_*
16+
.ipynb_checkpoints
1517
_doc/CHANGELOGS.rst
1618
_doc/LICENSE.txt
1719
_doc/auto_examples/*
@@ -27,3 +29,5 @@ _unittests/ut__main/*.png
2729
_unittests/ut__main/_cache/*
2830
_unittests/ut__main/*.html
2931
_unittests/.hypothesis/*
32+
_doc/notebooks/ml/*.onnx
33+
_doc/notebooks/dsgarden/*.onnx

CHANGELOGS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Change Logs
44
0.4.0
55
+++++
66

7+
* :pr:`42`: quantization
78
* :pr:`39`: refactoring, use black, better documentation

_doc/c_garden/quantization.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pour :math:`\lambda` et *z* en faisant tendre *h* vers 0.
140140
On commence par le plus simple, le cas float 8 pour lequel on impose :math:`z=0`.
141141

142142
.. math::
143+
:label: eq-qua-1
143144
144145
f(B,\lambda,h) = \frac{1}{h} \sum_{k=1}^{n} \sum_{ij} \pa{b_{ij} - \lambda d_k - z }^2
145146
K\pa{\frac{b_{ij} - \lambda d_k - z}{h}}
@@ -154,3 +155,43 @@ ce calcul devient une somme d'espérence.
154155
155156
Résolution
156157
==========
158+
159+
If :math:`K(u)=\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}u^2}` then
160+
:math:`K'(u) = -u \frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}u^2} = -u K(x)`.
161+
Let's denote :math:`g(b,x) = (b-xd)^2 K\pa{\frac{b-xd}{h}}`. Then:
162+
163+
.. math::
164+
165+
\begin{array}{rcl}
166+
g(b,x) &=& \frac{1}{h} (b-xd)^2 K\pa{\frac{b-xd}{h}} \\
167+
\frac{\partial g}{\partial x}(b,x) &=&
168+
\frac{1}{h}\cro{ -2d(b-xd)K\pa{\frac{b-xd}{h}} -\frac{d}{h} (b-xd)^2 K'\pa{\frac{b-xd}{h}} } \\
169+
&=& -\frac{d(b-xd)}{h}\cro{2 K\pa{\frac{b-xd}{h}} + \frac{b-xd}{h} K'\pa{\frac{b-xd}{h}} }
170+
\end{array}
171+
172+
Applied to :eq:`eq-qua-1`:
173+
174+
.. math::
175+
176+
\begin{array}{rcl}
177+
f(B,\lambda,h) &=& \frac{1}{h} \sum_{k=1}^{n} \sum_{ij} \pa{b_{ij} - \lambda d_k}^2
178+
K\pa{\frac{b_{ij} - \lambda d_k}{h}} \\
179+
&=& \sum_{k=1}^{n} \sum_{ij} g(b_{ij}, \lambda)
180+
\end{array}
181+
182+
Then:
183+
184+
.. math::
185+
186+
\begin{array}{rcl}
187+
\frac{\partial f}{\partial \lambda} &=& \sum_{k=1}^{n} \sum_{ij}
188+
\frac{\partial g}{\partial \lambda}(b_{ij}, \lambda)
189+
\end{array}
190+
191+
Notebooks
192+
=========
193+
194+
.. toctree::
195+
:maxdepth: 1
196+
197+
../notebooks/dsgarden/quantization_f8

_doc/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
"title": project,
7676
}
7777

78+
mathjax3_config = {"chtml": {"displayAlign": "left"}}
79+
7880
intersphinx_mapping = {
7981
"onnx": ("https://onnx.ai/onnx/", None),
8082
"matplotlib": ("https://matplotlib.org/", None),

0 commit comments

Comments
 (0)