quantizers 1.0.0__tar.gz → 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quantizers-1.0.1/.github/workflows/python-publish.yml +33 -0
- quantizers-1.0.1/.github/workflows/python-test.yml +32 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/PKG-INFO +8 -2
- {quantizers-1.0.0 → quantizers-1.0.1}/README.md +3 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/pyproject.toml +10 -2
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/_version.py +2 -2
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/fixed_point/fixed_point_ops.py +9 -9
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/fixed_point/fixed_point_ops_np.py +8 -8
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/minifloat/float_point_ops.py +1 -1
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/minifloat/float_point_ops_np.py +1 -1
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers.egg-info/PKG-INFO +8 -2
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers.egg-info/SOURCES.txt +2 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers.egg-info/requires.txt +4 -1
- {quantizers-1.0.0 → quantizers-1.0.1}/test/test_quantizer_match.py +1 -1
- {quantizers-1.0.0 → quantizers-1.0.1}/test/test_stateless_quantizer.py +3 -3
- {quantizers-1.0.0 → quantizers-1.0.1}/.clang-format +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/.gitignore +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/.pre-commit-config.yaml +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/LICENSE +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/setup.cfg +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/__init__.py +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/binary/__init__.py +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/binary/binary_ops.py +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/binary/binary_ops_np.py +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/fixed_point/__init__.py +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/minifloat/__init__.py +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers/stateful_quantizers.py +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers.egg-info/dependency_links.txt +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/src/quantizers.egg-info/top_level.txt +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_binary.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_common.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_decl.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_fixed.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_fixed_base.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_fixed_ref.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_fixed_special.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_float.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_int.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_int_base.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_int_ref.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_int_special.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/ap_shift_reg.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/etc/ap_private.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/hls_math.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/hls_stream.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/test.cpp +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/ap_types/utils/x_hls_utils.h +0 -0
- {quantizers-1.0.0 → quantizers-1.0.1}/test/cpp_source/quantizers.h +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Upload Python Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
deploy:
|
|
12
|
+
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v3
|
|
21
|
+
with:
|
|
22
|
+
python-version: '3.x'
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: |
|
|
25
|
+
python -m pip install --upgrade pip
|
|
26
|
+
pip install build
|
|
27
|
+
- name: Build package
|
|
28
|
+
run: python -m build
|
|
29
|
+
- name: Publish package
|
|
30
|
+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
|
|
31
|
+
with:
|
|
32
|
+
user: __token__
|
|
33
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
test:
|
|
8
|
+
name: Run tests and collect coverage
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- name: Checkout
|
|
12
|
+
uses: actions/checkout@v4
|
|
13
|
+
with:
|
|
14
|
+
fetch-depth: 0
|
|
15
|
+
|
|
16
|
+
- name: Set up Python
|
|
17
|
+
uses: actions/setup-python@v4
|
|
18
|
+
with:
|
|
19
|
+
python-version: 3.x
|
|
20
|
+
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: |
|
|
23
|
+
cd $GITHUB_WORKSPACE
|
|
24
|
+
pip install -e '.[test]'
|
|
25
|
+
|
|
26
|
+
- name: Run tests
|
|
27
|
+
run: pytest --import-mode=importlib -n4 --cov --cov-report=xml --cov=src/quantizers
|
|
28
|
+
|
|
29
|
+
- name: Upload results to Codecov
|
|
30
|
+
uses: codecov/codecov-action@v4
|
|
31
|
+
with:
|
|
32
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: quantizers
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.1
|
|
4
4
|
Author-email: Chang Sun <chsun@cern.ch>
|
|
5
5
|
License: GNU Lesser General Public License v3 (LGPLv3)
|
|
6
6
|
Project-URL: repository, https://github.com/calad0i/quantizers
|
|
@@ -20,11 +20,17 @@ Provides-Extra: test
|
|
|
20
20
|
Requires-Dist: pytest; extra == "test"
|
|
21
21
|
Requires-Dist: pytest-cov; extra == "test"
|
|
22
22
|
Requires-Dist: pytest-xdist; extra == "test"
|
|
23
|
-
Requires-Dist:
|
|
23
|
+
Requires-Dist: pytest-env; extra == "test"
|
|
24
|
+
Requires-Dist: keras>=3.0; extra == "test"
|
|
25
|
+
Requires-Dist: cppyy; extra == "test"
|
|
26
|
+
Requires-Dist: jax; extra == "test"
|
|
24
27
|
|
|
25
28
|
# Quantizers
|
|
26
29
|
[](https://badge.fury.io/py/quantizers)
|
|
27
30
|
[](LICENSE)
|
|
31
|
+
[](https://github.com/calad0i/quantizers/actions/workflows/python-test.yml)
|
|
32
|
+
[](https://app.codecov.io/gh/calad0i/quantizers)
|
|
33
|
+
|
|
28
34
|
|
|
29
35
|
Hardware-oriented numerical quantizers for deep learning models, implemented in Keras v3 and NumPy. Provides bit-accurate precision matching with Vivado/Vitis HLS implementations.
|
|
30
36
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Quantizers
|
|
2
2
|
[](https://badge.fury.io/py/quantizers)
|
|
3
3
|
[](LICENSE)
|
|
4
|
+
[](https://github.com/calad0i/quantizers/actions/workflows/python-test.yml)
|
|
5
|
+
[](https://app.codecov.io/gh/calad0i/quantizers)
|
|
6
|
+
|
|
4
7
|
|
|
5
8
|
Hardware-oriented numerical quantizers for deep learning models, implemented in Keras v3 and NumPy. Provides bit-accurate precision matching with Vivado/Vitis HLS implementations.
|
|
6
9
|
|
|
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "quantizers"
|
|
8
|
-
version = "1.0.
|
|
8
|
+
version = "1.0.1"
|
|
9
9
|
authors = [{ name = "Chang Sun", email = "chsun@cern.ch" }]
|
|
10
10
|
description = ""
|
|
11
11
|
readme = "README.md"
|
|
@@ -37,7 +37,15 @@ write_to = "src/quantizers/_version.py"
|
|
|
37
37
|
dependencies = ["numpy"]
|
|
38
38
|
|
|
39
39
|
grad = ['keras>=3']
|
|
40
|
-
test = [
|
|
40
|
+
test = [
|
|
41
|
+
'pytest',
|
|
42
|
+
'pytest-cov',
|
|
43
|
+
'pytest-xdist',
|
|
44
|
+
'pytest-env',
|
|
45
|
+
'keras>=3.0',
|
|
46
|
+
'cppyy',
|
|
47
|
+
'jax',
|
|
48
|
+
]
|
|
41
49
|
|
|
42
50
|
[tool.pytest.ini_options]
|
|
43
51
|
filterwarnings = [
|
|
@@ -12,5 +12,5 @@ __version__: str
|
|
|
12
12
|
__version_tuple__: VERSION_TUPLE
|
|
13
13
|
version_tuple: VERSION_TUPLE
|
|
14
14
|
|
|
15
|
-
__version__ = version = '0.1
|
|
16
|
-
__version_tuple__ = version_tuple = (
|
|
15
|
+
__version__ = version = '1.0.1'
|
|
16
|
+
__version_tuple__ = version_tuple = (1, 0, 1)
|
|
@@ -146,14 +146,14 @@ def wrap(x, k, i, f, training=None):
|
|
|
146
146
|
|
|
147
147
|
xs = x
|
|
148
148
|
bk = i + k
|
|
149
|
-
bias = k * 2
|
|
150
|
-
return ((xs + bias) % (2
|
|
149
|
+
bias = k * 2.**(bk - 1)
|
|
150
|
+
return ((xs + bias) % (2.**bk) - bias)
|
|
151
151
|
|
|
152
152
|
|
|
153
153
|
@sat_mode('SAT')
|
|
154
154
|
def sat(x, k, i, f, training=None):
|
|
155
|
-
f_eps = 2
|
|
156
|
-
__max = 2
|
|
155
|
+
f_eps = 2.**(-f)
|
|
156
|
+
__max = 2.**i
|
|
157
157
|
_max = __max - f_eps
|
|
158
158
|
_min = -__max * k
|
|
159
159
|
r = _clip(x, _min, _max)
|
|
@@ -162,8 +162,8 @@ def sat(x, k, i, f, training=None):
|
|
|
162
162
|
|
|
163
163
|
@sat_mode('SAT_SYM')
|
|
164
164
|
def sat_sym(x, k, i, f, training=None):
|
|
165
|
-
f_eps = 2
|
|
166
|
-
_max = 2
|
|
165
|
+
f_eps = 2.**(-f)
|
|
166
|
+
_max = 2.**i - f_eps
|
|
167
167
|
_min = -_max * k
|
|
168
168
|
r = _clip(x, _min, _max)
|
|
169
169
|
return r
|
|
@@ -171,10 +171,10 @@ def sat_sym(x, k, i, f, training=None):
|
|
|
171
171
|
|
|
172
172
|
@sat_mode('WRAP_SM')
|
|
173
173
|
def wrap_sm_fn(x, k, i, f, training=None, quant_fn: Callable = lambda x: x):
|
|
174
|
-
# x=ops.round(x*2
|
|
174
|
+
# x=ops.round(x*2.**f)
|
|
175
175
|
# High and low bounds are reflective. When overflows, can be less trash than WARP but still more trash than SAT.
|
|
176
|
-
eps = 2
|
|
177
|
-
high = 2
|
|
176
|
+
eps = 2.**-f
|
|
177
|
+
high = 2.**i - eps
|
|
178
178
|
low = -(high + eps) * k
|
|
179
179
|
interval = 2 ** (i + k)
|
|
180
180
|
c1 = ((x) / interval) % 2 >= 1 # type: ignore
|
|
@@ -90,14 +90,14 @@ def sat_mode_np(name: str | list | tuple):
|
|
|
90
90
|
def wrap(x, k, i, f, training=None):
|
|
91
91
|
xs = x
|
|
92
92
|
bk = i + k
|
|
93
|
-
bias = k * 2
|
|
94
|
-
return ((xs + bias) % (2
|
|
93
|
+
bias = k * 2.**(bk - 1)
|
|
94
|
+
return ((xs + bias) % (2.**bk) - bias)
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
@sat_mode_np('SAT')
|
|
98
98
|
def sat(x, k, i, f, training=None):
|
|
99
|
-
f_eps = 2
|
|
100
|
-
__max = 2
|
|
99
|
+
f_eps = 2.**(-f)
|
|
100
|
+
__max = 2.**i
|
|
101
101
|
_max = __max - f_eps
|
|
102
102
|
_min = -__max * k
|
|
103
103
|
return np.clip(x, _min, _max)
|
|
@@ -105,16 +105,16 @@ def sat(x, k, i, f, training=None):
|
|
|
105
105
|
|
|
106
106
|
@sat_mode_np('SAT_SYM')
|
|
107
107
|
def sat_sym(x, k, i, f, training=None):
|
|
108
|
-
f_eps = 2
|
|
109
|
-
_max = 2
|
|
108
|
+
f_eps = 2.**(-f)
|
|
109
|
+
_max = 2.**i - f_eps
|
|
110
110
|
_min = -_max * k
|
|
111
111
|
return np.clip(x, _min, _max)
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
@sat_mode_np('WRAP_SM')
|
|
115
115
|
def wrap_sm_fn(x, k, i, f, training=None, quant_fn: Callable = lambda x: x):
|
|
116
|
-
eps = 2
|
|
117
|
-
high = 2
|
|
116
|
+
eps = 2.**-f
|
|
117
|
+
high = 2.**i - eps
|
|
118
118
|
low = -(high + eps) * k
|
|
119
119
|
interval = 2 ** (i + k)
|
|
120
120
|
c1 = ((x) / interval) % 2 >= 1
|
|
@@ -47,7 +47,7 @@ def float_decompose(x, m, e, e0=0):
|
|
|
47
47
|
scale = 2.**(e_act - m + 1)
|
|
48
48
|
sig = x / scale
|
|
49
49
|
qsig = ops.round(sig)
|
|
50
|
-
cond = (e_act != e_high) & (ops.abs(qsig) == 2
|
|
50
|
+
cond = (e_act != e_high) & (ops.abs(qsig) == 2.**m)
|
|
51
51
|
e_act = ops.where(cond, e_act + 1, e_act) # type: ignore
|
|
52
52
|
qsig = ops.where(cond, qsig / 2., qsig) # type: ignore
|
|
53
53
|
r_mantissa_bound = 2 - 2.**(-m + 1)
|
|
@@ -33,7 +33,7 @@ def float_decompose_np(x, m, e, e0=0):
|
|
|
33
33
|
scale = 2.**(e_act - m + 1)
|
|
34
34
|
sig = x / scale
|
|
35
35
|
qsig = np.round(sig)
|
|
36
|
-
cond = (e_act != e_high) & (np.abs(qsig) == 2
|
|
36
|
+
cond = (e_act != e_high) & (np.abs(qsig) == 2.**m)
|
|
37
37
|
e_act = np.where(cond, e_act + 1, e_act) # type: ignore
|
|
38
38
|
qsig = np.where(cond, qsig / 2., qsig) # type: ignore
|
|
39
39
|
r_mantissa_bound = 2 - 2.**(-m + 1)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: quantizers
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.1
|
|
4
4
|
Author-email: Chang Sun <chsun@cern.ch>
|
|
5
5
|
License: GNU Lesser General Public License v3 (LGPLv3)
|
|
6
6
|
Project-URL: repository, https://github.com/calad0i/quantizers
|
|
@@ -20,11 +20,17 @@ Provides-Extra: test
|
|
|
20
20
|
Requires-Dist: pytest; extra == "test"
|
|
21
21
|
Requires-Dist: pytest-cov; extra == "test"
|
|
22
22
|
Requires-Dist: pytest-xdist; extra == "test"
|
|
23
|
-
Requires-Dist:
|
|
23
|
+
Requires-Dist: pytest-env; extra == "test"
|
|
24
|
+
Requires-Dist: keras>=3.0; extra == "test"
|
|
25
|
+
Requires-Dist: cppyy; extra == "test"
|
|
26
|
+
Requires-Dist: jax; extra == "test"
|
|
24
27
|
|
|
25
28
|
# Quantizers
|
|
26
29
|
[](https://badge.fury.io/py/quantizers)
|
|
27
30
|
[](LICENSE)
|
|
31
|
+
[](https://github.com/calad0i/quantizers/actions/workflows/python-test.yml)
|
|
32
|
+
[](https://app.codecov.io/gh/calad0i/quantizers)
|
|
33
|
+
|
|
28
34
|
|
|
29
35
|
Hardware-oriented numerical quantizers for deep learning models, implemented in Keras v3 and NumPy. Provides bit-accurate precision matching with Vivado/Vitis HLS implementations.
|
|
30
36
|
|
|
@@ -35,9 +35,9 @@ def xxx_mee0():
|
|
|
35
35
|
sign = jnp.sign(x)
|
|
36
36
|
x = jnp.abs(x)
|
|
37
37
|
m_eps = 2.**-M
|
|
38
|
-
_max = (2 - m_eps) * 2.**(2
|
|
39
|
-
_min_pos_normal = 2.**(-2
|
|
40
|
-
_min_pos_subnormal = m_eps * 2.**(-2
|
|
38
|
+
_max = (2 - m_eps) * 2.**(2.**(E - 1) - 1 + E0)
|
|
39
|
+
_min_pos_normal = 2.**(-2.**(E - 1) + E0 + 1)
|
|
40
|
+
_min_pos_subnormal = m_eps * 2.**(-2.**(E - 1) + E0)
|
|
41
41
|
log_subnormal = jnp.log2(_min_pos_subnormal)
|
|
42
42
|
log_normal = jnp.log2(_min_pos_normal)
|
|
43
43
|
log_overflow = jnp.log2(_max)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|