Skip to content

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

Draft
wants to merge 99 commits into
base: master
Choose a base branch
from

Conversation

divyashreepathihalli
Copy link
Collaborator

just using this for some tests

@divyashreepathihalli
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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", ""),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The jax version specified here (0.5.1) differs from the one in requirements.txt (0.5.0). This inconsistency can lead to testing discrepancies. Align the versions to ensure a consistent testing environment.

Comment on lines 1 to 147
# 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test file is fully commented out, which removes its test coverage. If these tests are no longer needed, remove the file. If temporarily disabled, add a comment explaining the reason and a tracking issue for re-enabling.

Comment on lines 445 to 448
env_val = os.environ["KERAS_NNX_ENABLED"].lower()
if env_val == "true":
_NNX_ENABLED = True
elif env_val == "false":
_NNX_ENABLED = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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

Comment on lines 1677 to 1679
self._parent_path = current_path()
except Exception:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The try...except Exception: pass block can hide issues when getting current_path(). Consider catching a specific exception or logging the exception for debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants