keras-nightly 3.12.0.dev2025100503__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.
Files changed (136) hide show
  1. keras/__init__.py +1 -0
  2. keras/_tf_keras/keras/__init__.py +1 -0
  3. keras/_tf_keras/keras/callbacks/__init__.py +3 -0
  4. keras/_tf_keras/keras/distillation/__init__.py +16 -0
  5. keras/_tf_keras/keras/distribution/__init__.py +3 -0
  6. keras/_tf_keras/keras/dtype_policies/__init__.py +3 -0
  7. keras/_tf_keras/keras/layers/__init__.py +21 -0
  8. keras/_tf_keras/keras/ops/__init__.py +13 -0
  9. keras/_tf_keras/keras/ops/image/__init__.py +1 -0
  10. keras/_tf_keras/keras/ops/linalg/__init__.py +1 -0
  11. keras/_tf_keras/keras/ops/nn/__init__.py +3 -0
  12. keras/_tf_keras/keras/ops/numpy/__init__.py +9 -0
  13. keras/_tf_keras/keras/quantizers/__init__.py +13 -0
  14. keras/callbacks/__init__.py +3 -0
  15. keras/distillation/__init__.py +16 -0
  16. keras/distribution/__init__.py +3 -0
  17. keras/dtype_policies/__init__.py +3 -0
  18. keras/layers/__init__.py +21 -0
  19. keras/ops/__init__.py +13 -0
  20. keras/ops/image/__init__.py +1 -0
  21. keras/ops/linalg/__init__.py +1 -0
  22. keras/ops/nn/__init__.py +3 -0
  23. keras/ops/numpy/__init__.py +9 -0
  24. keras/quantizers/__init__.py +13 -0
  25. keras/src/applications/imagenet_utils.py +4 -1
  26. keras/src/backend/common/backend_utils.py +30 -6
  27. keras/src/backend/common/name_scope.py +2 -1
  28. keras/src/backend/common/variables.py +30 -15
  29. keras/src/backend/jax/core.py +92 -3
  30. keras/src/backend/jax/distribution_lib.py +16 -2
  31. keras/src/backend/jax/linalg.py +4 -0
  32. keras/src/backend/jax/nn.py +509 -29
  33. keras/src/backend/jax/numpy.py +59 -8
  34. keras/src/backend/jax/trainer.py +14 -2
  35. keras/src/backend/numpy/linalg.py +4 -0
  36. keras/src/backend/numpy/nn.py +311 -1
  37. keras/src/backend/numpy/numpy.py +65 -2
  38. keras/src/backend/openvino/__init__.py +1 -0
  39. keras/src/backend/openvino/core.py +2 -23
  40. keras/src/backend/openvino/linalg.py +4 -0
  41. keras/src/backend/openvino/nn.py +271 -20
  42. keras/src/backend/openvino/numpy.py +943 -189
  43. keras/src/backend/tensorflow/layer.py +43 -9
  44. keras/src/backend/tensorflow/linalg.py +24 -0
  45. keras/src/backend/tensorflow/nn.py +545 -1
  46. keras/src/backend/tensorflow/numpy.py +250 -50
  47. keras/src/backend/torch/core.py +3 -1
  48. keras/src/backend/torch/linalg.py +4 -0
  49. keras/src/backend/torch/nn.py +125 -0
  50. keras/src/backend/torch/numpy.py +80 -2
  51. keras/src/callbacks/__init__.py +1 -0
  52. keras/src/callbacks/model_checkpoint.py +5 -0
  53. keras/src/callbacks/orbax_checkpoint.py +332 -0
  54. keras/src/callbacks/terminate_on_nan.py +54 -5
  55. keras/src/datasets/cifar10.py +5 -0
  56. keras/src/distillation/__init__.py +1 -0
  57. keras/src/distillation/distillation_loss.py +390 -0
  58. keras/src/distillation/distiller.py +598 -0
  59. keras/src/distribution/distribution_lib.py +14 -0
  60. keras/src/dtype_policies/__init__.py +2 -0
  61. keras/src/dtype_policies/dtype_policy.py +90 -1
  62. keras/src/export/__init__.py +2 -0
  63. keras/src/export/export_utils.py +39 -2
  64. keras/src/export/litert.py +248 -0
  65. keras/src/export/openvino.py +1 -1
  66. keras/src/export/tf2onnx_lib.py +3 -0
  67. keras/src/layers/__init__.py +13 -0
  68. keras/src/layers/activations/softmax.py +9 -4
  69. keras/src/layers/attention/multi_head_attention.py +4 -1
  70. keras/src/layers/core/dense.py +241 -111
  71. keras/src/layers/core/einsum_dense.py +316 -131
  72. keras/src/layers/core/embedding.py +84 -94
  73. keras/src/layers/core/input_layer.py +1 -0
  74. keras/src/layers/core/reversible_embedding.py +399 -0
  75. keras/src/layers/input_spec.py +17 -17
  76. keras/src/layers/layer.py +45 -15
  77. keras/src/layers/merging/dot.py +4 -1
  78. keras/src/layers/pooling/adaptive_average_pooling1d.py +65 -0
  79. keras/src/layers/pooling/adaptive_average_pooling2d.py +62 -0
  80. keras/src/layers/pooling/adaptive_average_pooling3d.py +63 -0
  81. keras/src/layers/pooling/adaptive_max_pooling1d.py +65 -0
  82. keras/src/layers/pooling/adaptive_max_pooling2d.py +62 -0
  83. keras/src/layers/pooling/adaptive_max_pooling3d.py +63 -0
  84. keras/src/layers/pooling/base_adaptive_pooling.py +63 -0
  85. keras/src/layers/preprocessing/discretization.py +6 -5
  86. keras/src/layers/preprocessing/feature_space.py +8 -4
  87. keras/src/layers/preprocessing/image_preprocessing/aug_mix.py +2 -2
  88. keras/src/layers/preprocessing/image_preprocessing/random_contrast.py +3 -3
  89. keras/src/layers/preprocessing/image_preprocessing/resizing.py +10 -0
  90. keras/src/layers/preprocessing/index_lookup.py +19 -1
  91. keras/src/layers/preprocessing/normalization.py +14 -1
  92. keras/src/layers/regularization/dropout.py +43 -1
  93. keras/src/layers/rnn/rnn.py +19 -0
  94. keras/src/losses/loss.py +1 -1
  95. keras/src/losses/losses.py +24 -0
  96. keras/src/metrics/confusion_metrics.py +7 -6
  97. keras/src/models/cloning.py +4 -0
  98. keras/src/models/functional.py +11 -3
  99. keras/src/models/model.py +172 -34
  100. keras/src/ops/image.py +257 -20
  101. keras/src/ops/linalg.py +93 -0
  102. keras/src/ops/nn.py +258 -0
  103. keras/src/ops/numpy.py +569 -36
  104. keras/src/optimizers/muon.py +65 -31
  105. keras/src/optimizers/schedules/learning_rate_schedule.py +4 -3
  106. keras/src/quantizers/__init__.py +14 -1
  107. keras/src/quantizers/awq.py +361 -0
  108. keras/src/quantizers/awq_config.py +140 -0
  109. keras/src/quantizers/awq_core.py +217 -0
  110. keras/src/quantizers/gptq.py +2 -8
  111. keras/src/quantizers/gptq_config.py +36 -1
  112. keras/src/quantizers/gptq_core.py +65 -79
  113. keras/src/quantizers/quantization_config.py +246 -0
  114. keras/src/quantizers/quantizers.py +127 -61
  115. keras/src/quantizers/utils.py +23 -0
  116. keras/src/random/seed_generator.py +6 -4
  117. keras/src/saving/file_editor.py +81 -6
  118. keras/src/saving/orbax_util.py +26 -0
  119. keras/src/saving/saving_api.py +37 -14
  120. keras/src/saving/saving_lib.py +1 -1
  121. keras/src/testing/__init__.py +1 -0
  122. keras/src/testing/test_case.py +45 -5
  123. keras/src/utils/backend_utils.py +31 -4
  124. keras/src/utils/dataset_utils.py +234 -35
  125. keras/src/utils/file_utils.py +49 -11
  126. keras/src/utils/image_utils.py +14 -2
  127. keras/src/utils/jax_layer.py +244 -55
  128. keras/src/utils/module_utils.py +29 -0
  129. keras/src/utils/progbar.py +10 -2
  130. keras/src/utils/rng_utils.py +9 -1
  131. keras/src/utils/tracking.py +5 -5
  132. keras/src/version.py +1 -1
  133. {keras_nightly-3.12.0.dev2025100503.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/METADATA +16 -6
  134. {keras_nightly-3.12.0.dev2025100503.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/RECORD +136 -115
  135. {keras_nightly-3.12.0.dev2025100503.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/WHEEL +0 -0
  136. {keras_nightly-3.12.0.dev2025100503.dist-info → keras_nightly-3.14.0.dev2026011604.dist-info}/top_level.txt +0 -0
keras/src/ops/nn.py CHANGED
@@ -6,6 +6,7 @@ from keras.src import backend
6
6
  from keras.src.api_export import keras_export
7
7
  from keras.src.backend import KerasTensor
8
8
  from keras.src.backend import any_symbolic_tensors
9
+ from keras.src.backend import config
9
10
  from keras.src.backend import standardize_data_format
10
11
  from keras.src.backend.common.backend_utils import (
11
12
  compute_conv_transpose_output_shape,
@@ -1162,6 +1163,87 @@ def max_pool(
1162
1163
  return backend.nn.max_pool(inputs, pool_size, strides, padding, data_format)
1163
1164
 
1164
1165
 
1166
+ class AdaptiveMaxPool(Operation):
1167
+ """Adaptive max pooling operation."""
1168
+
1169
+ def __init__(self, output_size, data_format=None, *, name=None):
1170
+ super().__init__(name=name)
1171
+ self.output_size = output_size
1172
+ self.data_format = data_format
1173
+
1174
+ def call(self, inputs):
1175
+ return backend.nn.adaptive_max_pool(
1176
+ inputs, output_size=self.output_size, data_format=self.data_format
1177
+ )
1178
+
1179
+ def compute_output_spec(self, inputs):
1180
+ if self.data_format == "channels_last":
1181
+ spatial_dims = self.output_size
1182
+ output_shape = (
1183
+ inputs.shape[: -len(self.output_size)]
1184
+ + spatial_dims
1185
+ + (inputs.shape[-1],)
1186
+ )
1187
+ else:
1188
+ spatial_dims = self.output_size
1189
+ output_shape = (inputs.shape[0], inputs.shape[1]) + spatial_dims
1190
+ return backend.KerasTensor(output_shape, dtype=inputs.dtype)
1191
+
1192
+
1193
+ @keras_export(["keras.ops.adaptive_max_pool", "keras.ops.nn.adaptive_max_pool"])
1194
+ def adaptive_max_pool(
1195
+ inputs,
1196
+ output_size,
1197
+ data_format=None,
1198
+ ):
1199
+ """Adaptive max pooling operation.
1200
+
1201
+ Applies an adaptive max pooling operation that automatically computes the
1202
+ kernel size and stride to pool the input to the specified `output_size`.
1203
+ This operation is useful when you want a fixed output size regardless of
1204
+ input size, commonly used in models like ResNet for global feature
1205
+ extraction.
1206
+ Args:
1207
+ inputs: Tensor of rank 4. Input tensor of shape:
1208
+ - If `data_format="channels_last"`:
1209
+ `(batch_size, height, width, channels)`.
1210
+ - If `data_format="channels_first"`:
1211
+ `(batch_size, channels, height, width)`.
1212
+ output_size: Integer or tuple/list of 2 integers, specifying the target
1213
+ output spatial dimensions `(output_height, output_width)`. If a
1214
+ single
1215
+ integer is provided, the same value is used for both dimensions.
1216
+ data_format: string, either `"channels_last"` or `"channels_first"`.
1217
+ Defaults to the value found in your Keras config file at
1218
+ `~/.keras/keras.json`. If never set, defaults to `"channels_last"`.
1219
+
1220
+ Returns:
1221
+ A tensor of rank 4 representing the adaptive max pooled result.
1222
+
1223
+ Example:
1224
+
1225
+ >>> x = np.random.rand(2, 64, 64, 3)
1226
+ >>> y = keras.ops.adaptive_max_pool(x, output_size=(32, 32))
1227
+ >>> y.shape
1228
+ (2, 32, 32, 3)
1229
+
1230
+ >>> # Works with any input size
1231
+ >>> x = np.random.rand(2, 100, 80, 3)
1232
+ >>> y = keras.ops.adaptive_max_pool(x, output_size=7)
1233
+ >>> y.shape
1234
+ (2, 7, 7, 3)
1235
+ """
1236
+ if data_format is None:
1237
+ data_format = config.image_data_format()
1238
+
1239
+ if any_symbolic_tensors((inputs,)):
1240
+ return AdaptiveMaxPool(output_size, data_format).symbolic_call(inputs)
1241
+
1242
+ return backend.nn.adaptive_max_pool(
1243
+ inputs, output_size=output_size, data_format=data_format
1244
+ )
1245
+
1246
+
1165
1247
  class AveragePool(Operation):
1166
1248
  def __init__(
1167
1249
  self,
@@ -1257,6 +1339,92 @@ def average_pool(
1257
1339
  )
1258
1340
 
1259
1341
 
1342
+ class AdaptiveAveragePool(Operation):
1343
+ """Adaptive average pooling operation."""
1344
+
1345
+ def __init__(self, output_size, data_format=None, *, name=None):
1346
+ super().__init__(name=name)
1347
+ self.output_size = output_size
1348
+ self.data_format = data_format
1349
+
1350
+ def call(self, inputs):
1351
+ return backend.nn.adaptive_average_pool(
1352
+ inputs, output_size=self.output_size, data_format=self.data_format
1353
+ )
1354
+
1355
+ def compute_output_spec(self, inputs):
1356
+ if self.data_format == "channels_last":
1357
+ spatial_dims = self.output_size
1358
+ output_shape = (
1359
+ inputs.shape[: -len(self.output_size)]
1360
+ + spatial_dims
1361
+ + (inputs.shape[-1],)
1362
+ )
1363
+ else:
1364
+ spatial_dims = self.output_size
1365
+ output_shape = (inputs.shape[0], inputs.shape[1]) + spatial_dims
1366
+ return backend.KerasTensor(output_shape, dtype=inputs.dtype)
1367
+
1368
+
1369
+ @keras_export(
1370
+ ["keras.ops.adaptive_average_pool", "keras.ops.nn.adaptive_average_pool"]
1371
+ )
1372
+ def adaptive_average_pool(
1373
+ inputs,
1374
+ output_size,
1375
+ data_format=None,
1376
+ ):
1377
+ """Adaptive average pooling operation.
1378
+
1379
+ Applies an adaptive average pooling operation that automatically
1380
+ computes the kernel size and stride to pool the input to the
1381
+ specified `output_size`. This operation is useful when you want a
1382
+ fixed output size regardless of input size, commonly used in models
1383
+ like ResNet for global feature extraction.
1384
+
1385
+ Args:
1386
+ inputs: Tensor of rank 4. Input tensor of shape:
1387
+ - If `data_format="channels_last"`:
1388
+ `(batch_size, height, width, channels)`.
1389
+ - If `data_format="channels_first"`:
1390
+ `(batch_size, channels, height, width)`.
1391
+ output_size: Integer or tuple/list of 2 integers, specifying the target
1392
+ output spatial dimensions `(output_height, output_width)`. If a
1393
+ single
1394
+ integer is provided, the same value is used for both dimensions.
1395
+ data_format: string, either `"channels_last"` or `"channels_first"`.
1396
+ Defaults to the value found in your Keras config file at
1397
+ `~/.keras/keras.json`. If never set, defaults to `"channels_last"`.
1398
+
1399
+ Returns:
1400
+ A tensor of rank 4 representing the adaptive average pooled result.
1401
+
1402
+ Example:
1403
+
1404
+ >>> x = np.random.rand(2, 64, 64, 3)
1405
+ >>> y = keras.ops.adaptive_average_pool(x, output_size=(32, 32))
1406
+ >>> y.shape
1407
+ (2, 32, 32, 3)
1408
+
1409
+ >>> # Works with any input size
1410
+ >>> x = np.random.rand(2, 100, 80, 3)
1411
+ >>> y = keras.ops.adaptive_average_pool(x, output_size=7)
1412
+ >>> y.shape
1413
+ (2, 7, 7, 3)
1414
+ """
1415
+ if data_format is None:
1416
+ data_format = config.image_data_format()
1417
+
1418
+ if any_symbolic_tensors((inputs,)):
1419
+ return AdaptiveAveragePool(output_size, data_format).symbolic_call(
1420
+ inputs
1421
+ )
1422
+
1423
+ return backend.nn.adaptive_average_pool(
1424
+ inputs, output_size=output_size, data_format=data_format
1425
+ )
1426
+
1427
+
1260
1428
  class Conv(Operation):
1261
1429
  def __init__(
1262
1430
  self,
@@ -3055,3 +3223,93 @@ def _polar(abs_, angle):
3055
3223
  result = backend.math._get_complex_tensor_from_tuple((real, imaginary))
3056
3224
 
3057
3225
  return result
3226
+
3227
+
3228
+ class Unfold(Operation):
3229
+ def __init__(
3230
+ self, kernel_size, dilation=1, padding=0, stride=1, *, name=None
3231
+ ):
3232
+ super().__init__(name=name)
3233
+ self.kernel_size = kernel_size
3234
+ self.dilation = dilation
3235
+ self.padding = padding
3236
+ self.stride = stride
3237
+
3238
+ def compute_output_spec(self, x):
3239
+ N, C, H, W = x.shape
3240
+
3241
+ def _pair(x):
3242
+ return (x, x) if isinstance(x, int) else x
3243
+
3244
+ kH, kW = _pair(self.kernel_size)
3245
+ dH, dW = _pair(self.dilation)
3246
+ pH, pW = _pair(self.padding)
3247
+ sH, sW = _pair(self.stride)
3248
+
3249
+ def out_size(L, k, d, p, s):
3250
+ return (L + 2 * p - d * (k - 1) - 1) // s + 1
3251
+
3252
+ outH = out_size(H, kH, dH, pH, sH)
3253
+ outW = out_size(W, kW, dW, pW, sW)
3254
+ return KerasTensor(shape=(N, C * kH * kW, outH * outW), dtype=x.dtype)
3255
+
3256
+ def call(self, x):
3257
+ return _unfold(
3258
+ x, self.kernel_size, self.dilation, self.padding, self.stride
3259
+ )
3260
+
3261
+
3262
+ @keras_export(["keras.ops.unfold", "keras.ops.nn.unfold"])
3263
+ def unfold(x, kernel_size, dilation=1, padding=0, stride=1):
3264
+ """Extract sliding local blocks from a 4-D input (batched image).
3265
+
3266
+ This operation is known as **im2col** when used with convolution.
3267
+ It rearranges the image into overlapping or non-overlapping patches
3268
+ and returns a tensor whose *depth* (last axis) contains the flattened
3269
+ patches.
3270
+
3271
+ Args:
3272
+ x: A 4-D tensor of shape `(N, C, H, W)` (**channels-first** format).
3273
+ kernel_size: int or tuple of two ints, the size of the sliding window
3274
+ `(kH, kW)`. If a single int is given, it is used for both
3275
+ dimensions.
3276
+ dilation: int or tuple of two ints, the spacing between kernel points
3277
+ (a.k.a. **dilation** or **atrous** convolution). Default: 1.
3278
+ padding: int or tuple of two ints, the amount of zero-padding to apply
3279
+ to both spatial dimensions. Default: 0.
3280
+ stride: int or tuple of two ints, the step size of the sliding window.
3281
+ Default: 1.
3282
+
3283
+ Returns:
3284
+ A 3-D tensor of shape `(N, C * kH * kW, L)` where
3285
+ `L = num_patches_H * num_patches_W` is the total number of patches
3286
+ extracted.
3287
+
3288
+ Example:
3289
+
3290
+ >>> x = keras.ops.ones((1, 2, 4, 4))
3291
+ >>> patches = keras.ops.unfold(x, kernel_size=2, stride=2)
3292
+ >>> patches.shape
3293
+ (1, 8, 4)
3294
+
3295
+ """
3296
+ input_shape = x.shape
3297
+ ndims = len(input_shape)
3298
+ if ndims != 4:
3299
+ raise ValueError(
3300
+ f"Input must be a 4D tensor. Received: input.shape={input_shape}"
3301
+ )
3302
+ if any_symbolic_tensors((x,)):
3303
+ return Unfold(kernel_size, dilation, padding, stride).symbolic_call(x)
3304
+ return _unfold(x, kernel_size, dilation, padding, stride)
3305
+
3306
+
3307
+ def _unfold(x, kernel_size, dilation=1, padding=0, stride=1):
3308
+ """Internal implementation of unfold."""
3309
+ return backend.nn.unfold(
3310
+ x,
3311
+ kernel_size=kernel_size,
3312
+ dilation=dilation,
3313
+ padding=padding,
3314
+ stride=stride,
3315
+ )