Skip to content

Commit

Permalink
Use IndexError instead of ValueError in deserialize_node (#20389)
Browse files Browse the repository at this point in the history
  • Loading branch information
james77777778 authored Oct 22, 2024
1 parent c31fad7 commit 1cc1eb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keras/src/models/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def convert_revived_tensor(x):
inbound_node_index = history[1]
inbound_tensor_index = history[2]
if len(layer._inbound_nodes) <= inbound_node_index:
raise ValueError(
raise IndexError(
"Layer node index out of bounds.\n"
f"inbound_layer = {layer}\n"
f"inbound_layer._inbound_nodes = {layer._inbound_nodes}\n"
Expand Down
12 changes: 12 additions & 0 deletions keras/src/saving/saving_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,18 @@ def test_load_model_concurrently(self):
pool.join()
[r.get() for r in results] # No error occurs here

def test_load_model_containing_reused_layer(self):
# https://github.com/keras-team/keras/issues/20307
inputs = keras.Input((4,))
reused_layer = keras.layers.Dense(4)
x = reused_layer(inputs)
x = keras.layers.Dense(4)(x)
outputs = reused_layer(x)
model = keras.Model(inputs, outputs)

self.assertLen(model.layers, 3) # Input + 2 Dense layers
self._test_inference_after_instantiation(model)


@pytest.mark.requires_trainable_backend
class SavingAPITest(testing.TestCase):
Expand Down

0 comments on commit 1cc1eb5

Please sign in to comment.