keras-nightly 3.12.0.dev2025092403__py3-none-any.whl → 3.14.0.dev2026010104__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 (133) 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/layers/__init__.py +21 -0
  7. keras/_tf_keras/keras/ops/__init__.py +13 -0
  8. keras/_tf_keras/keras/ops/image/__init__.py +1 -0
  9. keras/_tf_keras/keras/ops/linalg/__init__.py +1 -0
  10. keras/_tf_keras/keras/ops/nn/__init__.py +3 -0
  11. keras/_tf_keras/keras/ops/numpy/__init__.py +9 -0
  12. keras/_tf_keras/keras/quantizers/__init__.py +12 -0
  13. keras/callbacks/__init__.py +3 -0
  14. keras/distillation/__init__.py +16 -0
  15. keras/distribution/__init__.py +3 -0
  16. keras/layers/__init__.py +21 -0
  17. keras/ops/__init__.py +13 -0
  18. keras/ops/image/__init__.py +1 -0
  19. keras/ops/linalg/__init__.py +1 -0
  20. keras/ops/nn/__init__.py +3 -0
  21. keras/ops/numpy/__init__.py +9 -0
  22. keras/quantizers/__init__.py +12 -0
  23. keras/src/applications/imagenet_utils.py +4 -1
  24. keras/src/backend/common/backend_utils.py +30 -6
  25. keras/src/backend/common/dtypes.py +1 -1
  26. keras/src/backend/common/name_scope.py +2 -1
  27. keras/src/backend/common/variables.py +33 -16
  28. keras/src/backend/jax/core.py +92 -3
  29. keras/src/backend/jax/distribution_lib.py +16 -2
  30. keras/src/backend/jax/linalg.py +4 -0
  31. keras/src/backend/jax/nn.py +485 -20
  32. keras/src/backend/jax/numpy.py +92 -23
  33. keras/src/backend/jax/optimizer.py +3 -2
  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 +313 -2
  37. keras/src/backend/numpy/numpy.py +76 -7
  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 +1030 -185
  43. keras/src/backend/openvino/random.py +7 -14
  44. keras/src/backend/tensorflow/layer.py +43 -9
  45. keras/src/backend/tensorflow/linalg.py +24 -0
  46. keras/src/backend/tensorflow/nn.py +545 -1
  47. keras/src/backend/tensorflow/numpy.py +264 -54
  48. keras/src/backend/torch/core.py +3 -1
  49. keras/src/backend/torch/linalg.py +4 -0
  50. keras/src/backend/torch/nn.py +125 -0
  51. keras/src/backend/torch/numpy.py +84 -8
  52. keras/src/callbacks/__init__.py +1 -0
  53. keras/src/callbacks/callback_list.py +45 -11
  54. keras/src/callbacks/model_checkpoint.py +5 -0
  55. keras/src/callbacks/orbax_checkpoint.py +299 -0
  56. keras/src/callbacks/terminate_on_nan.py +54 -5
  57. keras/src/datasets/cifar10.py +5 -0
  58. keras/src/distillation/__init__.py +1 -0
  59. keras/src/distillation/distillation_loss.py +390 -0
  60. keras/src/distillation/distiller.py +598 -0
  61. keras/src/distribution/distribution_lib.py +14 -0
  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/attention.py +1 -1
  70. keras/src/layers/attention/multi_head_attention.py +4 -1
  71. keras/src/layers/core/dense.py +191 -172
  72. keras/src/layers/core/einsum_dense.py +235 -186
  73. keras/src/layers/core/embedding.py +83 -93
  74. keras/src/layers/core/input_layer.py +1 -0
  75. keras/src/layers/core/reversible_embedding.py +390 -0
  76. keras/src/layers/input_spec.py +17 -17
  77. keras/src/layers/layer.py +40 -15
  78. keras/src/layers/merging/dot.py +4 -1
  79. keras/src/layers/pooling/adaptive_average_pooling1d.py +65 -0
  80. keras/src/layers/pooling/adaptive_average_pooling2d.py +62 -0
  81. keras/src/layers/pooling/adaptive_average_pooling3d.py +63 -0
  82. keras/src/layers/pooling/adaptive_max_pooling1d.py +65 -0
  83. keras/src/layers/pooling/adaptive_max_pooling2d.py +62 -0
  84. keras/src/layers/pooling/adaptive_max_pooling3d.py +63 -0
  85. keras/src/layers/pooling/base_adaptive_pooling.py +63 -0
  86. keras/src/layers/preprocessing/discretization.py +6 -5
  87. keras/src/layers/preprocessing/index_lookup.py +19 -1
  88. keras/src/layers/preprocessing/normalization.py +16 -1
  89. keras/src/layers/regularization/dropout.py +43 -1
  90. keras/src/layers/rnn/gru.py +1 -1
  91. keras/src/layers/rnn/lstm.py +2 -2
  92. keras/src/layers/rnn/rnn.py +19 -0
  93. keras/src/layers/rnn/simple_rnn.py +1 -1
  94. keras/src/losses/loss.py +1 -1
  95. keras/src/metrics/confusion_metrics.py +7 -6
  96. keras/src/models/cloning.py +4 -0
  97. keras/src/models/functional.py +11 -3
  98. keras/src/models/model.py +156 -27
  99. keras/src/ops/image.py +184 -3
  100. keras/src/ops/linalg.py +93 -0
  101. keras/src/ops/nn.py +268 -2
  102. keras/src/ops/numpy.py +541 -43
  103. keras/src/optimizers/adafactor.py +29 -10
  104. keras/src/optimizers/base_optimizer.py +22 -3
  105. keras/src/optimizers/loss_scale_optimizer.py +51 -18
  106. keras/src/optimizers/muon.py +65 -31
  107. keras/src/optimizers/schedules/learning_rate_schedule.py +4 -3
  108. keras/src/quantizers/__init__.py +12 -1
  109. keras/src/quantizers/gptq.py +8 -6
  110. keras/src/quantizers/gptq_config.py +36 -1
  111. keras/src/quantizers/gptq_core.py +150 -78
  112. keras/src/quantizers/quantization_config.py +232 -0
  113. keras/src/quantizers/quantizers.py +114 -38
  114. keras/src/quantizers/utils.py +23 -0
  115. keras/src/random/seed_generator.py +4 -2
  116. keras/src/saving/file_editor.py +81 -6
  117. keras/src/saving/saving_lib.py +1 -1
  118. keras/src/testing/__init__.py +1 -0
  119. keras/src/testing/test_case.py +45 -5
  120. keras/src/trainers/compile_utils.py +14 -5
  121. keras/src/utils/backend_utils.py +31 -4
  122. keras/src/utils/dataset_utils.py +234 -35
  123. keras/src/utils/file_utils.py +49 -11
  124. keras/src/utils/image_utils.py +14 -2
  125. keras/src/utils/jax_layer.py +187 -36
  126. keras/src/utils/module_utils.py +18 -0
  127. keras/src/utils/progbar.py +10 -12
  128. keras/src/utils/rng_utils.py +9 -1
  129. keras/src/version.py +1 -1
  130. {keras_nightly-3.12.0.dev2025092403.dist-info → keras_nightly-3.14.0.dev2026010104.dist-info}/METADATA +16 -6
  131. {keras_nightly-3.12.0.dev2025092403.dist-info → keras_nightly-3.14.0.dev2026010104.dist-info}/RECORD +133 -116
  132. {keras_nightly-3.12.0.dev2025092403.dist-info → keras_nightly-3.14.0.dev2026010104.dist-info}/WHEEL +0 -0
  133. {keras_nightly-3.12.0.dev2025092403.dist-info → keras_nightly-3.14.0.dev2026010104.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,
@@ -704,7 +705,15 @@ class Glu(Operation):
704
705
  return backend.nn.glu(x, axis=self.axis)
705
706
 
706
707
  def compute_output_spec(self, x):
707
- return KerasTensor(x.shape, dtype=x.dtype)
708
+ output_shape = list(x.shape)
709
+ if output_shape[self.axis] is not None:
710
+ if output_shape[self.axis] % 2 != 0:
711
+ raise ValueError(
712
+ "axis size must be divisible by 2. "
713
+ f"Received: x.shape={x.shape} with axis={self.axis}"
714
+ )
715
+ output_shape[self.axis] = output_shape[self.axis] // 2
716
+ return KerasTensor(output_shape, dtype=x.dtype)
708
717
 
709
718
 
710
719
  @keras_export(["keras.ops.glu", "keras.ops.nn.glu"])
@@ -1154,6 +1163,87 @@ def max_pool(
1154
1163
  return backend.nn.max_pool(inputs, pool_size, strides, padding, data_format)
1155
1164
 
1156
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
+
1157
1247
  class AveragePool(Operation):
1158
1248
  def __init__(
1159
1249
  self,
@@ -1249,6 +1339,92 @@ def average_pool(
1249
1339
  )
1250
1340
 
1251
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
+
1252
1428
  class Conv(Operation):
1253
1429
  def __init__(
1254
1430
  self,
@@ -1435,7 +1611,7 @@ def depthwise_conv(
1435
1611
  """
1436
1612
  data_format = standardize_data_format(data_format)
1437
1613
  padding = padding.lower()
1438
- if any_symbolic_tensors((inputs,)):
1614
+ if any_symbolic_tensors((inputs, kernel)):
1439
1615
  return DepthwiseConv(
1440
1616
  strides, padding, data_format, dilation_rate
1441
1617
  ).symbolic_call(inputs, kernel)
@@ -3047,3 +3223,93 @@ def _polar(abs_, angle):
3047
3223
  result = backend.math._get_complex_tensor_from_tuple((real, imaginary))
3048
3224
 
3049
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
+ )