keras-nightly 3.12.0.dev2025083103__py3-none-any.whl → 3.14.0.dev2026011604__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/__init__.py +1 -0
- keras/_tf_keras/keras/__init__.py +1 -0
- keras/_tf_keras/keras/callbacks/__init__.py +3 -0
- keras/_tf_keras/keras/distillation/__init__.py +16 -0
- keras/_tf_keras/keras/distribution/__init__.py +3 -0
- keras/_tf_keras/keras/dtype_policies/__init__.py +6 -0
- keras/_tf_keras/keras/layers/__init__.py +21 -0
- keras/_tf_keras/keras/ops/__init__.py +16 -0
- keras/_tf_keras/keras/ops/image/__init__.py +1 -0
- keras/_tf_keras/keras/ops/linalg/__init__.py +1 -0
- keras/_tf_keras/keras/ops/nn/__init__.py +3 -0
- keras/_tf_keras/keras/ops/numpy/__init__.py +12 -0
- keras/_tf_keras/keras/quantizers/__init__.py +13 -0
- keras/callbacks/__init__.py +3 -0
- keras/distillation/__init__.py +16 -0
- keras/distribution/__init__.py +3 -0
- keras/dtype_policies/__init__.py +6 -0
- keras/layers/__init__.py +21 -0
- keras/ops/__init__.py +16 -0
- keras/ops/image/__init__.py +1 -0
- keras/ops/linalg/__init__.py +1 -0
- keras/ops/nn/__init__.py +3 -0
- keras/ops/numpy/__init__.py +12 -0
- keras/quantizers/__init__.py +13 -0
- keras/src/applications/imagenet_utils.py +4 -1
- keras/src/backend/common/backend_utils.py +30 -6
- keras/src/backend/common/dtypes.py +6 -12
- keras/src/backend/common/name_scope.py +2 -1
- keras/src/backend/common/variables.py +38 -20
- keras/src/backend/jax/core.py +126 -78
- keras/src/backend/jax/distribution_lib.py +16 -2
- keras/src/backend/jax/layer.py +3 -1
- keras/src/backend/jax/linalg.py +4 -0
- keras/src/backend/jax/nn.py +511 -29
- keras/src/backend/jax/numpy.py +109 -23
- keras/src/backend/jax/optimizer.py +3 -2
- keras/src/backend/jax/trainer.py +18 -3
- keras/src/backend/numpy/linalg.py +4 -0
- keras/src/backend/numpy/nn.py +313 -2
- keras/src/backend/numpy/numpy.py +97 -8
- keras/src/backend/openvino/__init__.py +1 -0
- keras/src/backend/openvino/core.py +6 -23
- keras/src/backend/openvino/linalg.py +4 -0
- keras/src/backend/openvino/nn.py +271 -20
- keras/src/backend/openvino/numpy.py +1369 -195
- keras/src/backend/openvino/random.py +7 -14
- keras/src/backend/tensorflow/layer.py +43 -9
- keras/src/backend/tensorflow/linalg.py +24 -0
- keras/src/backend/tensorflow/nn.py +545 -1
- keras/src/backend/tensorflow/numpy.py +351 -56
- keras/src/backend/tensorflow/trainer.py +6 -2
- keras/src/backend/torch/core.py +3 -1
- keras/src/backend/torch/linalg.py +4 -0
- keras/src/backend/torch/nn.py +125 -0
- keras/src/backend/torch/numpy.py +109 -9
- keras/src/backend/torch/trainer.py +8 -2
- keras/src/callbacks/__init__.py +1 -0
- keras/src/callbacks/callback_list.py +45 -11
- keras/src/callbacks/model_checkpoint.py +5 -0
- keras/src/callbacks/orbax_checkpoint.py +332 -0
- keras/src/callbacks/terminate_on_nan.py +54 -5
- keras/src/datasets/cifar10.py +5 -0
- keras/src/distillation/__init__.py +1 -0
- keras/src/distillation/distillation_loss.py +390 -0
- keras/src/distillation/distiller.py +598 -0
- keras/src/distribution/distribution_lib.py +14 -0
- keras/src/dtype_policies/__init__.py +4 -0
- keras/src/dtype_policies/dtype_policy.py +180 -1
- keras/src/export/__init__.py +2 -0
- keras/src/export/export_utils.py +39 -2
- keras/src/export/litert.py +248 -0
- keras/src/export/onnx.py +6 -0
- keras/src/export/openvino.py +1 -1
- keras/src/export/tf2onnx_lib.py +3 -0
- keras/src/layers/__init__.py +13 -0
- keras/src/layers/activations/softmax.py +9 -4
- keras/src/layers/attention/attention.py +1 -1
- keras/src/layers/attention/multi_head_attention.py +4 -1
- keras/src/layers/core/dense.py +406 -102
- keras/src/layers/core/einsum_dense.py +521 -116
- keras/src/layers/core/embedding.py +257 -99
- keras/src/layers/core/input_layer.py +1 -0
- keras/src/layers/core/reversible_embedding.py +399 -0
- keras/src/layers/input_spec.py +17 -17
- keras/src/layers/layer.py +50 -15
- keras/src/layers/merging/concatenate.py +6 -5
- keras/src/layers/merging/dot.py +4 -1
- keras/src/layers/pooling/adaptive_average_pooling1d.py +65 -0
- keras/src/layers/pooling/adaptive_average_pooling2d.py +62 -0
- keras/src/layers/pooling/adaptive_average_pooling3d.py +63 -0
- keras/src/layers/pooling/adaptive_max_pooling1d.py +65 -0
- keras/src/layers/pooling/adaptive_max_pooling2d.py +62 -0
- keras/src/layers/pooling/adaptive_max_pooling3d.py +63 -0
- keras/src/layers/pooling/base_adaptive_pooling.py +63 -0
- keras/src/layers/preprocessing/discretization.py +6 -5
- keras/src/layers/preprocessing/feature_space.py +8 -4
- keras/src/layers/preprocessing/image_preprocessing/aug_mix.py +2 -2
- keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/validation.py +5 -5
- keras/src/layers/preprocessing/image_preprocessing/random_contrast.py +3 -3
- keras/src/layers/preprocessing/image_preprocessing/resizing.py +10 -0
- keras/src/layers/preprocessing/index_lookup.py +19 -1
- keras/src/layers/preprocessing/normalization.py +16 -1
- keras/src/layers/preprocessing/string_lookup.py +26 -28
- keras/src/layers/regularization/dropout.py +43 -1
- keras/src/layers/rnn/gru.py +1 -1
- keras/src/layers/rnn/lstm.py +2 -2
- keras/src/layers/rnn/rnn.py +19 -0
- keras/src/layers/rnn/simple_rnn.py +1 -1
- keras/src/legacy/preprocessing/image.py +4 -1
- keras/src/legacy/preprocessing/sequence.py +20 -12
- keras/src/losses/loss.py +1 -1
- keras/src/losses/losses.py +24 -0
- keras/src/metrics/confusion_metrics.py +7 -6
- keras/src/models/cloning.py +4 -0
- keras/src/models/functional.py +11 -3
- keras/src/models/model.py +195 -44
- keras/src/ops/image.py +257 -20
- keras/src/ops/linalg.py +93 -0
- keras/src/ops/nn.py +268 -2
- keras/src/ops/numpy.py +701 -44
- keras/src/ops/operation.py +90 -29
- keras/src/ops/operation_utils.py +2 -0
- keras/src/optimizers/adafactor.py +29 -10
- keras/src/optimizers/base_optimizer.py +22 -3
- keras/src/optimizers/loss_scale_optimizer.py +51 -18
- keras/src/optimizers/muon.py +65 -31
- keras/src/optimizers/schedules/learning_rate_schedule.py +4 -3
- keras/src/quantizers/__init__.py +14 -1
- keras/src/quantizers/awq.py +361 -0
- keras/src/quantizers/awq_config.py +140 -0
- keras/src/quantizers/awq_core.py +217 -0
- keras/src/quantizers/gptq.py +346 -207
- keras/src/quantizers/gptq_config.py +63 -13
- keras/src/quantizers/gptq_core.py +328 -215
- keras/src/quantizers/quantization_config.py +246 -0
- keras/src/quantizers/quantizers.py +407 -38
- keras/src/quantizers/utils.py +23 -0
- keras/src/random/seed_generator.py +6 -4
- keras/src/saving/file_editor.py +81 -6
- keras/src/saving/orbax_util.py +26 -0
- keras/src/saving/saving_api.py +37 -14
- keras/src/saving/saving_lib.py +1 -1
- keras/src/testing/__init__.py +1 -0
- keras/src/testing/test_case.py +45 -5
- keras/src/trainers/compile_utils.py +38 -17
- keras/src/trainers/data_adapters/grain_dataset_adapter.py +1 -5
- keras/src/tree/torchtree_impl.py +215 -0
- keras/src/tree/tree_api.py +6 -1
- keras/src/utils/backend_utils.py +31 -4
- keras/src/utils/dataset_utils.py +234 -35
- keras/src/utils/file_utils.py +49 -11
- keras/src/utils/image_utils.py +14 -2
- keras/src/utils/jax_layer.py +244 -55
- keras/src/utils/module_utils.py +29 -0
- keras/src/utils/progbar.py +10 -12
- keras/src/utils/python_utils.py +5 -0
- keras/src/utils/rng_utils.py +9 -1
- keras/src/utils/tracking.py +70 -5
- keras/src/version.py +1 -1
- {keras_nightly-3.12.0.dev2025083103.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/METADATA +16 -6
- {keras_nightly-3.12.0.dev2025083103.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/RECORD +163 -142
- keras/src/quantizers/gptq_quant.py +0 -133
- {keras_nightly-3.12.0.dev2025083103.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/WHEEL +0 -0
- {keras_nightly-3.12.0.dev2025083103.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/top_level.txt +0 -0
|
@@ -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.dev2025083103.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|