keras-nightly 3.12.0.dev2025082003__py3-none-any.whl → 3.12.0.dev2025082103__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.
@@ -778,7 +778,7 @@ def _cudnn_gru(
778
778
  return (
779
779
  last_output,
780
780
  outputs,
781
- state,
781
+ [state],
782
782
  )
783
783
 
784
784
 
@@ -176,6 +176,8 @@ class Attention(Layer):
176
176
  # Bias so padding positions do not contribute to attention
177
177
  # distribution. Note 65504. is the max float16 value.
178
178
  max_value = 65504.0 if scores.dtype == "float16" else 1.0e9
179
+ if len(padding_mask.shape) == 2:
180
+ padding_mask = ops.expand_dims(padding_mask, axis=-2)
179
181
  scores -= max_value * ops.cast(padding_mask, dtype=scores.dtype)
180
182
 
181
183
  weights = ops.softmax(scores, axis=-1)
@@ -167,14 +167,15 @@ class Lambda(Layer):
167
167
  )
168
168
 
169
169
  @staticmethod
170
- def _raise_for_lambda_deserialization(arg_name, safe_mode):
170
+ def _raise_for_lambda_deserialization(safe_mode):
171
171
  if safe_mode:
172
172
  raise ValueError(
173
- f"The `{arg_name}` of this `Lambda` layer is a Python lambda. "
174
- "Deserializing it is unsafe. If you trust the source of the "
175
- "config artifact, you can override this error "
176
- "by passing `safe_mode=False` "
177
- "to `from_config()`, or calling "
173
+ "Requested the deserialization of a `Lambda` layer whose "
174
+ "`function` is a Python lambda. This carries a potential risk "
175
+ "of arbitrary code execution and thus it is disallowed by "
176
+ "default. If you trust the source of the artifact, you can "
177
+ "override this error by passing `safe_mode=False` to the "
178
+ "loading function, or calling "
178
179
  "`keras.config.enable_unsafe_deserialization()."
179
180
  )
180
181
 
@@ -187,7 +188,7 @@ class Lambda(Layer):
187
188
  and "class_name" in fn_config
188
189
  and fn_config["class_name"] == "__lambda__"
189
190
  ):
190
- cls._raise_for_lambda_deserialization("function", safe_mode)
191
+ cls._raise_for_lambda_deserialization(safe_mode)
191
192
  inner_config = fn_config["config"]
192
193
  fn = python_utils.func_load(
193
194
  inner_config["code"],
@@ -206,7 +207,7 @@ class Lambda(Layer):
206
207
  and "class_name" in fn_config
207
208
  and fn_config["class_name"] == "__lambda__"
208
209
  ):
209
- cls._raise_for_lambda_deserialization("function", safe_mode)
210
+ cls._raise_for_lambda_deserialization(safe_mode)
210
211
  inner_config = fn_config["config"]
211
212
  fn = python_utils.func_load(
212
213
  inner_config["code"],
@@ -11,6 +11,7 @@ from keras.src.legacy.saving import json_utils
11
11
  from keras.src.legacy.saving import saving_options
12
12
  from keras.src.legacy.saving import saving_utils
13
13
  from keras.src.saving import object_registration
14
+ from keras.src.saving import serialization_lib
14
15
  from keras.src.utils import io_utils
15
16
 
16
17
  try:
@@ -72,7 +73,9 @@ def save_model_to_hdf5(model, filepath, overwrite=True, include_optimizer=True):
72
73
  f.close()
73
74
 
74
75
 
75
- def load_model_from_hdf5(filepath, custom_objects=None, compile=True):
76
+ def load_model_from_hdf5(
77
+ filepath, custom_objects=None, compile=True, safe_mode=True
78
+ ):
76
79
  """Loads a model saved via `save_model_to_hdf5`.
77
80
 
78
81
  Args:
@@ -128,7 +131,9 @@ def load_model_from_hdf5(filepath, custom_objects=None, compile=True):
128
131
  model_config = model_config.decode("utf-8")
129
132
  model_config = json_utils.decode(model_config)
130
133
 
131
- with saving_options.keras_option_scope(use_legacy_config=True):
134
+ legacy_scope = saving_options.keras_option_scope(use_legacy_config=True)
135
+ safe_mode_scope = serialization_lib.SafeModeScope(safe_mode)
136
+ with legacy_scope, safe_mode_scope:
132
137
  model = saving_utils.model_from_config(
133
138
  model_config, custom_objects=custom_objects
134
139
  )
@@ -1,4 +1,3 @@
1
- import json
2
1
  import threading
3
2
 
4
3
  from absl import logging
@@ -81,10 +80,6 @@ def model_from_config(config, custom_objects=None):
81
80
  function_dict["config"]["closure"] = function_config[2]
82
81
  config["config"]["function"] = function_dict
83
82
 
84
- # TODO(nkovela): Swap find and replace args during Keras 3.0 release
85
- # Replace keras refs with keras
86
- config = _find_replace_nested_dict(config, "keras.", "keras.")
87
-
88
83
  return serialization.deserialize_keras_object(
89
84
  config,
90
85
  module_objects=MODULE_OBJECTS.ALL_OBJECTS,
@@ -231,13 +226,6 @@ def _deserialize_metric(metric_config):
231
226
  return metrics_module.deserialize(metric_config)
232
227
 
233
228
 
234
- def _find_replace_nested_dict(config, find, replace):
235
- dict_str = json.dumps(config)
236
- dict_str = dict_str.replace(find, replace)
237
- config = json.loads(dict_str)
238
- return config
239
-
240
-
241
229
  def _resolve_compile_arguments_compat(obj, obj_config, module):
242
230
  """Resolves backwards compatibility issues with training config arguments.
243
231
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  import contextlib
4
4
  import inspect
5
- import json
6
5
  import threading
7
6
  import weakref
8
7
 
@@ -485,12 +484,6 @@ def deserialize_keras_object(
485
484
  arg_spec = inspect.getfullargspec(cls.from_config)
486
485
  custom_objects = custom_objects or {}
487
486
 
488
- # TODO(nkovela): Swap find and replace args during Keras 3.0 release
489
- # Replace keras refs with keras
490
- cls_config = _find_replace_nested_dict(
491
- cls_config, "keras.", "keras."
492
- )
493
-
494
487
  if "custom_objects" in arg_spec.args:
495
488
  deserialized_obj = cls.from_config(
496
489
  cls_config,
@@ -565,10 +558,3 @@ def validate_config(config):
565
558
  def is_default(method):
566
559
  """Check if a method is decorated with the `default` wrapper."""
567
560
  return getattr(method, "_is_default", False)
568
-
569
-
570
- def _find_replace_nested_dict(config, find, replace):
571
- dict_str = json.dumps(config)
572
- dict_str = dict_str.replace(find, replace)
573
- config = json.loads(dict_str)
574
- return config
@@ -194,7 +194,10 @@ def load_model(filepath, custom_objects=None, compile=True, safe_mode=True):
194
194
  )
195
195
  if str(filepath).endswith((".h5", ".hdf5")):
196
196
  return legacy_h5_format.load_model_from_hdf5(
197
- filepath, custom_objects=custom_objects, compile=compile
197
+ filepath,
198
+ custom_objects=custom_objects,
199
+ compile=compile,
200
+ safe_mode=safe_mode,
198
201
  )
199
202
  elif str(filepath).endswith(".keras"):
200
203
  raise ValueError(
@@ -656,12 +656,12 @@ def deserialize_keras_object(
656
656
  if config["class_name"] == "__lambda__":
657
657
  if safe_mode:
658
658
  raise ValueError(
659
- "Requested the deserialization of a `lambda` object. "
660
- "This carries a potential risk of arbitrary code execution "
661
- "and thus it is disallowed by default. If you trust the "
662
- "source of the saved model, you can pass `safe_mode=False` to "
663
- "the loading function in order to allow `lambda` loading, "
664
- "or call `keras.config.enable_unsafe_deserialization()`."
659
+ "Requested the deserialization of a Python lambda. This "
660
+ "carries a potential risk of arbitrary code execution and thus "
661
+ "it is disallowed by default. If you trust the source of the "
662
+ "artifact, you can override this error by passing "
663
+ "`safe_mode=False` to the loading function, or calling "
664
+ "`keras.config.enable_unsafe_deserialization()."
665
665
  )
666
666
  return python_utils.func_load(inner_config["value"])
667
667
  if tf is not None and config["class_name"] == "__typespec__":
@@ -172,10 +172,10 @@ class TorchModuleWrapper(Layer):
172
172
  "Requested the deserialization of a `torch.nn.Module` "
173
173
  "object via `torch.load()`. This carries a potential risk "
174
174
  "of arbitrary code execution and thus it is disallowed by "
175
- "default. If you trust the source of the saved model, you "
176
- "can pass `safe_mode=False` to the loading function in "
177
- "order to allow `torch.nn.Module` loading, or call "
178
- "`keras.config.enable_unsafe_deserialization()`."
175
+ "default. If you trust the source of the artifact, you can "
176
+ "override this error by passing `safe_mode=False` to the "
177
+ "loading function, or calling "
178
+ "`keras.config.enable_unsafe_deserialization()."
179
179
  )
180
180
 
181
181
  # Decode the base64 string back to bytes
keras/src/version.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from keras.src.api_export import keras_export
2
2
 
3
3
  # Unique source of truth for the version number.
4
- __version__ = "3.12.0.dev2025082003"
4
+ __version__ = "3.12.0.dev2025082103"
5
5
 
6
6
 
7
7
  @keras_export("keras.version")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: keras-nightly
3
- Version: 3.12.0.dev2025082003
3
+ Version: 3.12.0.dev2025082103
4
4
  Summary: Multi-backend Keras
5
5
  Author-email: Keras team <keras-users@googlegroups.com>
6
6
  License: Apache License 2.0
@@ -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=njY7f4Il2CTFP8VpP-i-fu_W9TrUOijOX1eeYI-KMMA,204
129
+ keras/src/version.py,sha256=3WxaFuZhA9X3LMhCWXM1PlE7M9PhUGBXga0hrf2P5Qk,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
@@ -212,7 +212,7 @@ keras/src/backend/tensorflow/nn.py,sha256=oS7sngoA2C2SFfKQdYWvSZe7HCFfG29t4glbE6
212
212
  keras/src/backend/tensorflow/numpy.py,sha256=BWBku9PEiyx3NAcWyccHS_hqu4EzVmNTjrBtMPfSb5U,94514
213
213
  keras/src/backend/tensorflow/optimizer.py,sha256=kFlyEOnGjEYdLpd8mpwhUeku78__xBfZbbrDWpJrq60,9307
214
214
  keras/src/backend/tensorflow/random.py,sha256=iO8V_soaDXZm9ewyAVbjudhsMj08C348c9Bz64nxXC4,6475
215
- keras/src/backend/tensorflow/rnn.py,sha256=SwKOW9j4CYcSYmrlm1vYK34xU0TcVgBcz52fRUT50aM,34600
215
+ keras/src/backend/tensorflow/rnn.py,sha256=99EJqbPdWddmG14zyjjhUZfU5zo9ObmslF_Mak7EmAs,34602
216
216
  keras/src/backend/tensorflow/sparse.py,sha256=a_FZcJY-wPl1x4vY0T7j-GORa4SAuMjNEToJLmK0daQ,32247
217
217
  keras/src/backend/tensorflow/tensorboard.py,sha256=e7pXicuMfQjuCmq1wOmixWhWt2EbjLMBo_JPAqCbZRk,504
218
218
  keras/src/backend/tensorflow/trackable.py,sha256=QZn0JvpBJ7Kx4e6zM2IVIWz9ADcWDB-dHN6vjoQBa9Q,1993
@@ -298,7 +298,7 @@ keras/src/layers/activations/relu.py,sha256=LYtWg_ZpdOEp3YxylsCVdLz00hTgqd0OyFrP
298
298
  keras/src/layers/activations/softmax.py,sha256=HR2FtPzw-vnZAFh4uiF_gksewComHd7z31rwJtCdTCU,2611
299
299
  keras/src/layers/attention/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
300
300
  keras/src/layers/attention/additive_attention.py,sha256=J8joGgCdS4k0tuu8GeDIdabTyJXQk_-JnHgoYABsiGc,4309
301
- keras/src/layers/attention/attention.py,sha256=8kuzrc5yt_YFC7s0oQQBcdoozBzr8bZLWEDdOIYVZPg,13468
301
+ keras/src/layers/attention/attention.py,sha256=1wNlC3fma0ZPb2bS50d6bQ_HB_EuL1UYecAy4wh5sKM,13583
302
302
  keras/src/layers/attention/grouped_query_attention.py,sha256=gJSirCzubfSiNHUeFBvuXVIHDg21fLQSv7u-FPAIoxo,21018
303
303
  keras/src/layers/attention/multi_head_attention.py,sha256=rZmUOvjzwxdF1oopAvlNjkWmUSQ5pLu4zob4xGWeRIM,31934
304
304
  keras/src/layers/convolutional/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -322,7 +322,7 @@ keras/src/layers/core/einsum_dense.py,sha256=yK0ng8wPl17UJP_8LMOPM_R08CFSDrNhWo5
322
322
  keras/src/layers/core/embedding.py,sha256=5y5tvjtOOoxucTRevQGxVkJE3Fn4g03aBNodB3wF7Zg,17144
323
323
  keras/src/layers/core/identity.py,sha256=o0gLHlXL7eNJEbXIgIsgBsZX97K6jN9n3qPXprkXQ9Y,848
324
324
  keras/src/layers/core/input_layer.py,sha256=_CLTG6fxGf4FQ6rx0taxHUG5g0okzErWDF1JAgg5ctw,8129
325
- keras/src/layers/core/lambda_layer.py,sha256=kTtaYYA7cI9obKpDdJ-o9Oi1gEaEfbaMjcYHU9egx1I,9195
325
+ keras/src/layers/core/lambda_layer.py,sha256=Wplek4hOwh_rwXz4_bpz0pXzKe26ywz52glh5uD0l4w,9272
326
326
  keras/src/layers/core/masking.py,sha256=g-RrZ_P50Surh_KGlZQwy2kPNLsop0F8voU4SG2MQkw,2856
327
327
  keras/src/layers/core/wrapper.py,sha256=KIdDBuk24V9rAn97-HUUKQ0JMx9Eyd0q9W4qQFaYNt8,1509
328
328
  keras/src/layers/merging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -455,10 +455,10 @@ keras/src/legacy/preprocessing/sequence.py,sha256=jyot2KR3652vRxuzmLkWjRd5MivMys
455
455
  keras/src/legacy/preprocessing/text.py,sha256=1NCgRIVZhZoWPSv0GKPGZ2r0D6SvcnHQsLpvFSnVals,11103
456
456
  keras/src/legacy/saving/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
457
457
  keras/src/legacy/saving/json_utils.py,sha256=JIGZu1OJylkP71N6h3IBLoG_e9qnCQAC9H4GdDdUIOc,7296
458
- keras/src/legacy/saving/legacy_h5_format.py,sha256=1STGZkmKwVFjo7VEf5lzPo9despXD7270xi2Ouf6ArA,22901
458
+ keras/src/legacy/saving/legacy_h5_format.py,sha256=7Jyrrzlsn8UPe58DVwYbMJEBCMr6uKNcOKB5WobWyuk,23092
459
459
  keras/src/legacy/saving/saving_options.py,sha256=ZUyOHYsTf0rBLBAOlSaeqVNv9tGjWA9LsNyPk5WTXRI,485
460
- keras/src/legacy/saving/saving_utils.py,sha256=qpqnUJrJ_kkiuhLAAqXKuFuWTU5SBGzCCy_5x56LqaI,9407
461
- keras/src/legacy/saving/serialization.py,sha256=s4qrdywzIRnMccfXRmxbSqqfquQyohIIf7TdjRQCsBc,21808
460
+ keras/src/legacy/saving/saving_utils.py,sha256=8Sa2rmBGnTv86Tix20OgwF5vTLTpUYbfGdgHNSnrB30,9029
461
+ keras/src/legacy/saving/serialization.py,sha256=hiwqO3Il861pkfm0Egaeph2XbhOlQQobmZjbZZgK32c,21368
462
462
  keras/src/losses/__init__.py,sha256=rt63Ye0f7YdAR0eV0EOj2J61DI6xNdp2ojonx6rB3wE,6595
463
463
  keras/src/losses/loss.py,sha256=BjtYoghA3jfpJ4_bG7c3NRK3rk7omzMSCuK9ZNlaYGs,8787
464
464
  keras/src/losses/losses.py,sha256=lVAuX3K4IzeRVvjvnejlieiuxtPRMvXtvmCrLZGsT9s,99534
@@ -523,9 +523,9 @@ keras/src/saving/__init__.py,sha256=vnrtfvnzW7Gwtxe5COhaMoEnVYB5iDe2YlqJ-DvqFIk,
523
523
  keras/src/saving/file_editor.py,sha256=SVrhhqQTF_ANd_hSRIgfM2vCqKBtvSyUaUuI8uuhGms,28976
524
524
  keras/src/saving/keras_saveable.py,sha256=aGIt1ajtsaamfUq18LM6ql8JEoQzi3HwzJEuwQ9bmKE,1285
525
525
  keras/src/saving/object_registration.py,sha256=aZmmFrJP5GjjNpLNmq4k6D-PqdAH8PMBGk7BXI7eogE,7358
526
- keras/src/saving/saving_api.py,sha256=KlTXFSZzGUnG0vvEZdEOsuRH5SvoV15K3_lryYfif7s,11597
526
+ keras/src/saving/saving_api.py,sha256=hYMr0g_4zboDHUA4Dop7PVSPsGB0FBN7d29W4RhNPNI,11655
527
527
  keras/src/saving/saving_lib.py,sha256=-4Gsv9fd2ZK_arAiaDOTmO-yROsfk8ZpyTZGnk2hcxc,58711
528
- keras/src/saving/serialization_lib.py,sha256=qtonRiLraW742tlzulMebA0ptpbFvqvxkd94Ru6TO-w,30391
528
+ keras/src/saving/serialization_lib.py,sha256=NRavrwwrUU5NG0dI8G-x8tHrH55liNJvecg2_y1CAuM,30379
529
529
  keras/src/testing/__init__.py,sha256=xOZf-VBOf3wrXu47PgII2TNfXgxUse60HCinBryHiK8,266
530
530
  keras/src/testing/test_case.py,sha256=YFQYAG-EH-FP70bWLzYP3IG3kDjLc2lvoWJ67mHLohQ,30844
531
531
  keras/src/testing/test_utils.py,sha256=6Vb8tJIyjU1ay63w3jvXNNhh7sSNrosQll4ii1NXELQ,6197
@@ -574,7 +574,7 @@ keras/src/utils/summary_utils.py,sha256=jjbTB6NTqMniSWXPKeNY6dvpn-U37WJdwqdfl8uX
574
574
  keras/src/utils/text_dataset_utils.py,sha256=6ACAHwEhjjd5rjfzwLl7Es2qkvmSBUWs5IYQLGrHFrQ,14543
575
575
  keras/src/utils/tf_utils.py,sha256=FTunWC5kdyjsK0TyxQxiHGaYNaAyUxhMX52Zee_Rz9c,4930
576
576
  keras/src/utils/timeseries_dataset_utils.py,sha256=rVxSuqlYLpzw_dVo8Ym5HSE2jFmndS8MAv4Uewycojo,9842
577
- keras/src/utils/torch_utils.py,sha256=y8vRSx_R9MtC1IpRqyK6LBRETxwrlUFnsu45R4_-7Hs,6638
577
+ keras/src/utils/torch_utils.py,sha256=n0CAb7NFnK3CcfxY9VgA2kcZp_8SU05Ddg-KY0-qnoc,6619
578
578
  keras/src/utils/traceback_utils.py,sha256=VI8VJ8QjTDc3-cx3xfR9H7g68D2KVH7VknHi_JrVMuU,8997
579
579
  keras/src/utils/tracking.py,sha256=mVig-TS5LZbModoyAOnN3msazudKggW62hxUq4XzT2I,8844
580
580
  keras/src/visualization/__init__.py,sha256=bDdV3eLKeLKoUwUDBFuZxMO560OyFZND0zBn8vaG6rg,111
@@ -593,7 +593,7 @@ keras/utils/bounding_boxes/__init__.py,sha256=jtvQll4u8ZY0Z96HwNhP1nxWEG9FM3gI-6
593
593
  keras/utils/legacy/__init__.py,sha256=oSYZz6uS8UxSElRaaJYWJEoweJ4GAasZjnn7fNaOlog,342
594
594
  keras/visualization/__init__.py,sha256=UKWmiy6sps4SWlmQi9WX8_Z53cPpLlphz2zIeHdwJpQ,722
595
595
  keras/wrappers/__init__.py,sha256=QkS-O5K8qGS7C3sytF8MpmO6PasATpNVGF8qtb7Ojsw,407
596
- keras_nightly-3.12.0.dev2025082003.dist-info/METADATA,sha256=LZyWd4xCofCT4FX7BEdbxKxsT4K1qqybGB16Rj2U_II,5970
597
- keras_nightly-3.12.0.dev2025082003.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
598
- keras_nightly-3.12.0.dev2025082003.dist-info/top_level.txt,sha256=ptcw_-QuGZ4ZDjMdwi_Z0clZm8QAqFdvzzFnDEOTs9o,6
599
- keras_nightly-3.12.0.dev2025082003.dist-info/RECORD,,
596
+ keras_nightly-3.12.0.dev2025082103.dist-info/METADATA,sha256=5k0b73CF7vZyxjf3tDo_vwQc2tqEFc9nNqyeY9C-ROM,5970
597
+ keras_nightly-3.12.0.dev2025082103.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
598
+ keras_nightly-3.12.0.dev2025082103.dist-info/top_level.txt,sha256=ptcw_-QuGZ4ZDjMdwi_Z0clZm8QAqFdvzzFnDEOTs9o,6
599
+ keras_nightly-3.12.0.dev2025082103.dist-info/RECORD,,