Skip to content

Commit 534b975

Browse files
revert variables change
1 parent 7a2ddd8 commit 534b975

File tree

2 files changed

+0
-27
lines changed

2 files changed

+0
-27
lines changed

integration_tests/basic_full_flow.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
import numpy as np
42
import pytest
53

@@ -9,7 +7,6 @@
97
from keras.src import metrics
108
from keras.src import optimizers
119
from keras.src import testing
12-
from keras.src.backend.common.variables import initialize_all_variables
1310

1411

1512
class MyModel(keras.Model):
@@ -55,25 +52,3 @@ def test_basic_fit_no_training(self):
5552
x = np.random.random((128, 4))
5653
model.predict(x)
5754
model(x)
58-
59-
60-
def test_nnx_variable_initializer_bug():
61-
# Enable JAX + NNX backend
62-
os.environ["KERAS_BACKEND"] = "jax"
63-
os.environ["KERAS_NNX_ENABLED"] = "true"
64-
import keras
65-
66-
model = keras.Sequential([keras.layers.Dense(1, input_shape=(2,))])
67-
x = np.ones((1, 2))
68-
# First call: triggers tracing and variable initialization
69-
model(x)
70-
# Save the kernel value after first call
71-
kernel_before = model.layers[0].kernel.value.copy()
72-
# Now forcibly re-initialize all variables
73-
initialize_all_variables()
74-
# Check if the kernel value has changed
75-
kernel_after = model.layers[0].kernel.value
76-
assert np.allclose(kernel_before, kernel_after), (
77-
"Kernel was re-initialized! This is a bug if NNX is enabled and "
78-
"the initializer was not cleared."
79-
)

keras/src/backend/common/variables.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ def _deferred_initialize(self):
214214
# If NNX is enabled, it's possible the variable was already
215215
# initialized by a concrete call. In this case,
216216
# _deferred_initialize becomes a no-op for this variable.
217-
if config.is_nnx_enabled():
218-
return
219217
raise ValueError(f"Variable {self.path} is already initialized.")
220218

221219
if in_stateless_scope():

0 commit comments

Comments
 (0)