File tree Expand file tree Collapse file tree 2 files changed +0
-27
lines changed Expand file tree Collapse file tree 2 files changed +0
-27
lines changed Original file line number Diff line number Diff line change 1
- import os
2
-
3
1
import numpy as np
4
2
import pytest
5
3
9
7
from keras .src import metrics
10
8
from keras .src import optimizers
11
9
from keras .src import testing
12
- from keras .src .backend .common .variables import initialize_all_variables
13
10
14
11
15
12
class MyModel (keras .Model ):
@@ -55,25 +52,3 @@ def test_basic_fit_no_training(self):
55
52
x = np .random .random ((128 , 4 ))
56
53
model .predict (x )
57
54
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
- )
Original file line number Diff line number Diff line change @@ -214,8 +214,6 @@ def _deferred_initialize(self):
214
214
# If NNX is enabled, it's possible the variable was already
215
215
# initialized by a concrete call. In this case,
216
216
# _deferred_initialize becomes a no-op for this variable.
217
- if config .is_nnx_enabled ():
218
- return
219
217
raise ValueError (f"Variable { self .path } is already initialized." )
220
218
221
219
if in_stateless_scope ():
You can’t perform that action at this time.
0 commit comments