Skip to content

Commit b53714b

Browse files
Address Fabien's comments
1 parent 8f2798e commit b53714b

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

keras/src/backend/common/variables.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ def __init__(
212212
def _deferred_initialize(self):
213213
if self._value is not None:
214214
# If NNX is enabled, it's possible the variable was already
215-
# initialized by a concrete call. In this case,
216-
# _deferred_initialize becomes a no-op for this variable.
215+
# initialized by a concrete call.
216+
if config.is_nnx_enabled():
217+
return
217218
raise ValueError(f"Variable {self.path} is already initialized.")
218219

219220
if in_stateless_scope():

keras/src/ops/function.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,9 @@ def _setup_nnx_op_mapping(self):
112112
# Create a mapping from operation id to operation instance
113113
self._nnx_op_mapping = {}
114114

115-
# Store operations as direct attributes for NNX traversal
116-
for i, operation in enumerate(self._operations):
117-
# Store operation as direct attribute with unique name
118-
attr_name = f"_op_{i}_{operation.name}"
119-
setattr(self, attr_name, operation)
115+
# Assign the list of operations to a single attribute for NNX traversal
116+
self.nnx_operations = self._operations[:]
117+
for operation in self._operations:
120118
# Map the operation id to this operation instance
121119
self._nnx_op_mapping[id(operation)] = operation
122120

0 commit comments

Comments
 (0)