keras-nightly 3.12.0.dev2025090303__py3-none-any.whl → 3.12.0.dev2025090403__py3-none-any.whl
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.
- keras/src/models/model.py +2 -2
- keras/src/quantizers/gptq.py +284 -192
- keras/src/quantizers/gptq_config.py +3 -13
- keras/src/quantizers/gptq_core.py +211 -158
- keras/src/quantizers/quantizers.py +200 -0
- keras/src/version.py +1 -1
- {keras_nightly-3.12.0.dev2025090303.dist-info → keras_nightly-3.12.0.dev2025090403.dist-info}/METADATA +1 -1
- {keras_nightly-3.12.0.dev2025090303.dist-info → keras_nightly-3.12.0.dev2025090403.dist-info}/RECORD +10 -11
- keras/src/quantizers/gptq_quant.py +0 -133
- {keras_nightly-3.12.0.dev2025090303.dist-info → keras_nightly-3.12.0.dev2025090403.dist-info}/WHEEL +0 -0
- {keras_nightly-3.12.0.dev2025090303.dist-info → keras_nightly-3.12.0.dev2025090403.dist-info}/top_level.txt +0 -0
keras/src/version.py
CHANGED
{keras_nightly-3.12.0.dev2025090303.dist-info → keras_nightly-3.12.0.dev2025090403.dist-info}/RECORD
RENAMED
@@ -126,7 +126,7 @@ keras/regularizers/__init__.py,sha256=542Shphw7W8h4Dyf2rmqMKUECVZ8IVBvN9g1LWhz-b
|
|
126
126
|
keras/saving/__init__.py,sha256=KvL2GZxjvgFgEhvEnkvqjIR9JSNHKz-NWZacXajsjLI,1298
|
127
127
|
keras/src/__init__.py,sha256=Gi4S7EiCMkE03PbdGNpFdaUYySWDs_FcAJ8Taz9Y1BE,684
|
128
128
|
keras/src/api_export.py,sha256=gXOkBOnmscV013WAc75lc4Up01-Kkg9EylIAT_QWctg,1173
|
129
|
-
keras/src/version.py,sha256=
|
129
|
+
keras/src/version.py,sha256=7vdIM9SpPYc0tR9Sx69WYreBdg5rhdqe-QcMNCO_39U,204
|
130
130
|
keras/src/activations/__init__.py,sha256=0nL3IFDB9unlrMz8ninKOWo-uCHasTUpTo1tXZb2u44,4433
|
131
131
|
keras/src/activations/activations.py,sha256=mogPggtp4CGldI3VOPNmesRxp6EbiR1_i4KLGaVwzL8,17614
|
132
132
|
keras/src/applications/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -477,7 +477,7 @@ keras/src/metrics/regression_metrics.py,sha256=eLacV_8CKtzA26BJDJuncUDATuL1x8O6S
|
|
477
477
|
keras/src/models/__init__.py,sha256=DPbBPSfIGgsufTfJH5U5xJOeN_Ef4FMadT7KKYg3Kjg,143
|
478
478
|
keras/src/models/cloning.py,sha256=jwVtVVVYVasFIrln2hrzJ8bR2Xhsx9wYgEqpF1AjSvE,15786
|
479
479
|
keras/src/models/functional.py,sha256=VqCbEAmUXdrrt2X_BdC8iUQmt-GOVtfgpTMoN8l3k-s,33667
|
480
|
-
keras/src/models/model.py,sha256=
|
480
|
+
keras/src/models/model.py,sha256=mqT7eOFF2BhL0VdhtsG85-hEB3k0vwSLXAYVzvgeiA4,36178
|
481
481
|
keras/src/models/sequential.py,sha256=CC9Q1BNB9m7TkgMHRyjOzhQvneng576wJpmdgHrACKY,14352
|
482
482
|
keras/src/models/variable_mapping.py,sha256=FVtcgjBRqOxtvkzOE6kjG9SpcB9keDg2gS5LOTlXvG0,2181
|
483
483
|
keras/src/ops/__init__.py,sha256=aORlvnrqY_eQl0EFLWdpHsXHnQ6JLSw1qhwJMr-VXJ0,644
|
@@ -513,11 +513,10 @@ keras/src/optimizers/sgd.py,sha256=_3xanWOI0s2dISxEVT7i_tehsWakQQz2y480Iwkonas,4
|
|
513
513
|
keras/src/optimizers/schedules/__init__.py,sha256=vuUuHNTev8sD2-swsuq7zqyYbmaOhDyiIE6F3dGGSZU,546
|
514
514
|
keras/src/optimizers/schedules/learning_rate_schedule.py,sha256=Sqvd0SRHLMilsBsVXuolElJR6z5tBTphlGJ99Yq8axw,35784
|
515
515
|
keras/src/quantizers/__init__.py,sha256=gxZQYNL-XyUYV1BQgC6V9qVH2MpqI-R1wqhM6o2Sywo,1967
|
516
|
-
keras/src/quantizers/gptq.py,sha256=
|
517
|
-
keras/src/quantizers/gptq_config.py,sha256=
|
518
|
-
keras/src/quantizers/gptq_core.py,sha256=
|
519
|
-
keras/src/quantizers/
|
520
|
-
keras/src/quantizers/quantizers.py,sha256=s-SXe9339RpcpPSIwRS-pi4HBqVpL7qr9bZnpLkDL_s,22413
|
516
|
+
keras/src/quantizers/gptq.py,sha256=PZur5-9UFu8hhH2U8nfdz27awdKEV1NWf4V81OpxWvE,17457
|
517
|
+
keras/src/quantizers/gptq_config.py,sha256=s_3ZCh4R-3E5l64JTuQFC13ZzqhpWFHy-tGZQa1CJxk,6382
|
518
|
+
keras/src/quantizers/gptq_core.py,sha256=o-48-UwH6lbACvWTazuqgYKBYV-_4a148zQaT3dLz1w,14782
|
519
|
+
keras/src/quantizers/quantizers.py,sha256=aljlsok9ISTLgn6QUfK9GJBKLqGshG6BZQTW62NzEus,29520
|
521
520
|
keras/src/random/__init__.py,sha256=BmXVYPzxbhADohoLtAEEzB3cesP7YBFDsp1qc6BWWlg,420
|
522
521
|
keras/src/random/random.py,sha256=bUADZIVDuCghwIWTk0qBxXTxUdiNGWIdsRi8QJ3ePg4,17581
|
523
522
|
keras/src/random/seed_generator.py,sha256=hQTFxKSGCkGdBJHMmJj-cSRfqI3AhHtVxYT0tfOU6Fw,5590
|
@@ -597,7 +596,7 @@ keras/utils/bounding_boxes/__init__.py,sha256=jtvQll4u8ZY0Z96HwNhP1nxWEG9FM3gI-6
|
|
597
596
|
keras/utils/legacy/__init__.py,sha256=oSYZz6uS8UxSElRaaJYWJEoweJ4GAasZjnn7fNaOlog,342
|
598
597
|
keras/visualization/__init__.py,sha256=UKWmiy6sps4SWlmQi9WX8_Z53cPpLlphz2zIeHdwJpQ,722
|
599
598
|
keras/wrappers/__init__.py,sha256=QkS-O5K8qGS7C3sytF8MpmO6PasATpNVGF8qtb7Ojsw,407
|
600
|
-
keras_nightly-3.12.0.
|
601
|
-
keras_nightly-3.12.0.
|
602
|
-
keras_nightly-3.12.0.
|
603
|
-
keras_nightly-3.12.0.
|
599
|
+
keras_nightly-3.12.0.dev2025090403.dist-info/METADATA,sha256=cEhICjKAML22jqL3yo9btobI1G2M9ARh1SpNDrIAniA,5970
|
600
|
+
keras_nightly-3.12.0.dev2025090403.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
601
|
+
keras_nightly-3.12.0.dev2025090403.dist-info/top_level.txt,sha256=ptcw_-QuGZ4ZDjMdwi_Z0clZm8QAqFdvzzFnDEOTs9o,6
|
602
|
+
keras_nightly-3.12.0.dev2025090403.dist-info/RECORD,,
|
@@ -1,133 +0,0 @@
|
|
1
|
-
from keras.src import ops
|
2
|
-
|
3
|
-
|
4
|
-
def dequantize(input_tensor, scale, zero, maxq):
|
5
|
-
"""The core quantization function."""
|
6
|
-
epsilon = ops.cast(1e-8, dtype=scale.dtype)
|
7
|
-
scale = ops.where(ops.equal(scale, 0), epsilon, scale)
|
8
|
-
|
9
|
-
quantized_tensor = ops.divide(input_tensor, scale)
|
10
|
-
quantized_tensor = ops.round(quantized_tensor)
|
11
|
-
q = ops.add(quantized_tensor, zero)
|
12
|
-
q = ops.clip(q, 0, maxq)
|
13
|
-
|
14
|
-
dequantized_tensor = ops.subtract(q, zero)
|
15
|
-
return ops.multiply(scale, dequantized_tensor)
|
16
|
-
|
17
|
-
|
18
|
-
class GPTQQuantization:
|
19
|
-
"""A class that handles the quantization of weights using GPTQ method.
|
20
|
-
|
21
|
-
This class provides methods to find quantization parameters (scale and zero)
|
22
|
-
for a given tensor and can be used to quantize weights in a GPTQ context.
|
23
|
-
|
24
|
-
Args:
|
25
|
-
weight_bits: (int) The number of bits to quantize to (e.g., 4).
|
26
|
-
per_channel: (bool) A flag indicating whether quantization is
|
27
|
-
applied per-channel (`True`) or per-tensor (`False`).
|
28
|
-
Defaults to `False`.
|
29
|
-
symmetric: (bool) A flag indicating whether symmetric (`True`) or
|
30
|
-
asymmetric (`False`) quantization is used. Defaults to `False`.
|
31
|
-
group_size: (int) The size of weight groups for quantization. A
|
32
|
-
value of -1 indicates that grouping is not used.
|
33
|
-
Defaults to -1.
|
34
|
-
"""
|
35
|
-
|
36
|
-
def __init__(
|
37
|
-
self, weight_bits, per_channel=True, symmetric=False, group_size=-1
|
38
|
-
):
|
39
|
-
self.weight_bits = weight_bits
|
40
|
-
self.maxq = ops.cast(
|
41
|
-
ops.subtract(ops.power(2, weight_bits), 1), "float32"
|
42
|
-
)
|
43
|
-
self.per_channel = per_channel
|
44
|
-
self.symmetric = symmetric
|
45
|
-
self.group_size = group_size
|
46
|
-
|
47
|
-
# These are now determined later by `find_params`
|
48
|
-
self.scale = None
|
49
|
-
self.zero = None
|
50
|
-
|
51
|
-
def find_params(self, input_tensor, weight=False):
|
52
|
-
"""Finds quantization parameters (scale and zero) for a given tensor."""
|
53
|
-
|
54
|
-
if input_tensor is None:
|
55
|
-
raise ValueError("Input tensor 'input_tensor' cannot be None.")
|
56
|
-
|
57
|
-
# For weights, we typically expect at least a 2D tensor.
|
58
|
-
if weight and len(input_tensor.shape) < 2:
|
59
|
-
raise ValueError(
|
60
|
-
f"Input weight tensor 'input_tensor' must have a rank of at "
|
61
|
-
f"least 2, but got rank {len(input_tensor.shape)}."
|
62
|
-
)
|
63
|
-
|
64
|
-
if ops.size(input_tensor) == 0:
|
65
|
-
raise ValueError("Input tensor 'input_tensor' cannot be empty.")
|
66
|
-
|
67
|
-
original_shape = input_tensor.shape
|
68
|
-
|
69
|
-
if self.per_channel:
|
70
|
-
if weight:
|
71
|
-
if self.group_size != -1:
|
72
|
-
input_reshaped = ops.reshape(
|
73
|
-
input_tensor, [-1, self.group_size]
|
74
|
-
)
|
75
|
-
else:
|
76
|
-
input_reshaped = ops.reshape(
|
77
|
-
input_tensor, [original_shape[0], -1]
|
78
|
-
)
|
79
|
-
else: # per-tensor
|
80
|
-
input_reshaped = ops.reshape(input_tensor, [1, -1])
|
81
|
-
|
82
|
-
# Find min/max values
|
83
|
-
min_values = ops.min(input_reshaped, axis=1)
|
84
|
-
max_values = ops.max(input_reshaped, axis=1)
|
85
|
-
|
86
|
-
# Apply symmetric quantization logic if enabled
|
87
|
-
if self.symmetric:
|
88
|
-
max_values = ops.maximum(ops.abs(min_values), max_values)
|
89
|
-
min_values = ops.where(
|
90
|
-
ops.less(min_values, 0), ops.negative(max_values), min_values
|
91
|
-
)
|
92
|
-
|
93
|
-
# Ensure range is not zero to avoid division errors
|
94
|
-
zero_range = ops.equal(min_values, max_values)
|
95
|
-
min_values = ops.where(
|
96
|
-
zero_range, ops.subtract(min_values, 1), min_values
|
97
|
-
)
|
98
|
-
max_values = ops.where(zero_range, ops.add(max_values, 1), max_values)
|
99
|
-
|
100
|
-
# Calculate scale and zero-point
|
101
|
-
self.scale = ops.divide(ops.subtract(max_values, min_values), self.maxq)
|
102
|
-
if self.symmetric:
|
103
|
-
self.zero = ops.full_like(
|
104
|
-
self.scale, ops.divide(ops.add(self.maxq, 1), 2)
|
105
|
-
)
|
106
|
-
else:
|
107
|
-
self.zero = ops.round(
|
108
|
-
ops.divide(ops.negative(min_values), self.scale)
|
109
|
-
)
|
110
|
-
|
111
|
-
# Ensure scale is non-zero
|
112
|
-
self.scale = ops.where(ops.less_equal(self.scale, 0), 1e-8, self.scale)
|
113
|
-
|
114
|
-
if weight:
|
115
|
-
# Per-channel, non-grouped case: simple reshape is correct.
|
116
|
-
if self.per_channel and self.group_size == -1:
|
117
|
-
self.scale = ops.reshape(self.scale, [-1, 1])
|
118
|
-
self.zero = ops.reshape(self.zero, [-1, 1])
|
119
|
-
elif not self.per_channel:
|
120
|
-
num_rows = original_shape[0]
|
121
|
-
self.scale = ops.tile(
|
122
|
-
ops.reshape(self.scale, (1, 1)), (num_rows, 1)
|
123
|
-
)
|
124
|
-
self.zero = ops.tile(
|
125
|
-
ops.reshape(self.zero, (1, 1)), (num_rows, 1)
|
126
|
-
)
|
127
|
-
if self.per_channel:
|
128
|
-
self.scale = ops.reshape(self.scale, [-1, 1])
|
129
|
-
self.zero = ops.reshape(self.zero, [-1, 1])
|
130
|
-
|
131
|
-
def ready(self):
|
132
|
-
"""Checks if the quantization parameters have been computed."""
|
133
|
-
return self.scale is not None and self.zero is not None
|
{keras_nightly-3.12.0.dev2025090303.dist-info → keras_nightly-3.12.0.dev2025090403.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|