-
Notifications
You must be signed in to change notification settings - Fork 19.6k
IGNORE THIS PR #21389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
IGNORE THIS PR #21389
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21389 +/- ##
==========================================
- Coverage 82.75% 82.49% -0.27%
==========================================
Files 565 565
Lines 55346 55571 +225
Branches 8634 8691 +57
==========================================
+ Hits 45804 45842 +38
- Misses 7440 7614 +174
- Partials 2102 2115 +13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
64b99f0
to
f0b10ef
Compare
485f776
to
d8ca752
Compare
f040e7f
to
1bdf4e9
Compare
Fix NNX tracing issue for functional
9d5349c
to
5500382
Compare
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request integrates Flax NNX support into the JAX backend, involving configuration, core components, layers, and models. Key areas for improvement include test dependency alignment, addressing disabled tests, and enhancing error handling in configuration parsing.
"jax": ("jax[cpu]", ""), | ||
# please update the jax version here if jax version is updated in | ||
# requirements file | ||
"jax": ("jax[cpu]==0.5.1 flax>=0.10.1", ""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# keras_module.layers.MaxPooling2D(pool_size=(2, 2)), | ||
# keras_module.layers.Flatten(), | ||
# keras_module.layers.Dense(num_classes, activation="softmax"), | ||
# ] | ||
# ) | ||
# return model | ||
|
||
|
||
# def compile_model(model): | ||
# model.compile( | ||
# loss="categorical_crossentropy", | ||
# optimizer="adam", | ||
# metrics=["mae", "accuracy"], | ||
# jit_compile=False, | ||
# run_eagerly=True, | ||
# ) | ||
|
||
|
||
# def train_model(model, x, y): | ||
# return model.fit( | ||
# x, | ||
# y, | ||
# batch_size=BATCH_SIZE, | ||
# epochs=EPOCHS, | ||
# shuffle=False, | ||
# verbose=0, | ||
# ) | ||
|
||
|
||
# def eval_model(model, x, y): | ||
# score = model.evaluate(x, y, verbose=0, batch_size=BATCH_SIZE) | ||
# print(score) | ||
# return score | ||
|
||
|
||
# def check_history(h1, h2): | ||
# for key in h1.history.keys(): | ||
# print(f"{key}:") | ||
# print(h1.history[key]) | ||
# print(h2.history[key]) | ||
# np.testing.assert_allclose( | ||
# h1.history[key], | ||
# h2.history[key], | ||
# atol=1e-3, | ||
# ) | ||
|
||
|
||
# def predict_model(model, x): | ||
# return model.predict(x, batch_size=BATCH_SIZE, verbose=0) | ||
|
||
|
||
# def numerical_test(): | ||
# x_train, y_train = build_mnist_data(NUM_CLASSES) | ||
# keras_model = build_keras_model(keras, NUM_CLASSES) | ||
# tf_keras_model = build_keras_model(tf_keras, NUM_CLASSES) | ||
|
||
# # Make sure both model have same weights before training | ||
# weights = [weight.numpy() for weight in keras_model.weights] | ||
# tf_keras_model.set_weights(weights) | ||
|
||
# for kw, kcw in zip(keras_model.weights, tf_keras_model.weights): | ||
# np.testing.assert_allclose(kw.numpy(), kcw.numpy()) | ||
|
||
# compile_model(keras_model) | ||
# compile_model(tf_keras_model) | ||
|
||
# print("Checking training histories:") | ||
# keras_history = train_model(keras_model, x_train, y_train) | ||
# tf_keras_history = train_model(tf_keras_model, x_train, y_train) | ||
# check_history(keras_history, tf_keras_history) | ||
# print("Training histories match.") | ||
# print() | ||
|
||
# print("Checking trained weights:") | ||
# for kw, kcw in zip(keras_model.weights, tf_keras_model.weights): | ||
# np.testing.assert_allclose(kw.numpy(), kcw.numpy(), atol=1e-3) | ||
# print("Trained weights match.") | ||
# print() | ||
|
||
# print("Checking predict:") | ||
# outputs1 = predict_model(keras_model, x_train) | ||
# outputs2 = predict_model(tf_keras_model, x_train) | ||
# np.testing.assert_allclose(outputs1, outputs2, atol=1e-3) | ||
# print("Predict results match.") | ||
# print() | ||
|
||
# print("Checking evaluate:") | ||
# score1 = eval_model(keras_model, x_train, y_train) | ||
# score2 = eval_model(tf_keras_model, x_train, y_train) | ||
# np.testing.assert_allclose(score1, score2, atol=1e-3) | ||
# print("Evaluate results match.") | ||
|
||
|
||
# if __name__ == "__main__": | ||
# if keras.backend.backend() == "openvino": | ||
# # this test requires trainable backend | ||
# sys.exit(0) | ||
# keras.utils.set_random_seed(1337) | ||
# tf_keras.utils.set_random_seed(1337) | ||
# numerical_test() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env_val = os.environ["KERAS_NNX_ENABLED"].lower() | ||
if env_val == "true": | ||
_NNX_ENABLED = True | ||
elif env_val == "false": | ||
_NNX_ENABLED = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parsing logic for KERAS_NNX_ENABLED
only handles "true" and "false", ignoring other boolean representations. Enhance it to handle common boolean values like "1" and "0" for better usability.
env_val = os.environ["KERAS_NNX_ENABLED"].lower() | |
if env_val == "true": | |
_NNX_ENABLED = True | |
elif env_val == "false": | |
_NNX_ENABLED = False | |
if "KERAS_NNX_ENABLED" in os.environ: | |
env_val = os.environ["KERAS_NNX_ENABLED"].lower() | |
if env_val in ("true", "1"): | |
_NNX_ENABLED = True | |
elif env_val in ("false", "0"): | |
_NNX_ENABLED = False |
self._parent_path = current_path() | ||
except Exception: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just using this for some tests