-
Notifications
You must be signed in to change notification settings - Fork 17
support all tests in layers to tpu #170
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: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @wenyi-guo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the testing infrastructure for Keras layers by enabling comprehensive support for Tensor Processing Units (TPUs). It centralizes TPU strategy management and execution logic into a new utility module, which is then integrated across various layer test suites. This refactoring not only streamlines the process of writing and maintaining TPU tests but also improves the overall reliability and performance validation of Keras layers on specialized hardware accelerators. Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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 is a significant and valuable refactoring to enable TPU support for a wide range of layer tests. The introduction of the tpu_test_utils.py module to centralize TPU strategy creation and execution is a great design choice that improves code maintainability and consistency. The changes are applied systematically across numerous test files. I've identified a couple of issues, including one critical issue in the new utility function that needs to be addressed to ensure tests run correctly on non-TensorFlow backends.
hertschuh
left a comment
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.
Let's try to really minimize the changes. I think most test files can be left intact.
| run: pytest keras_rs/src/layers/embedding/distributed_embedding_test.py | ||
| - name: Test with pytest (TensorFlow) | ||
| if: ${{ matrix.backend == 'tensorflow' }} | ||
| run: pytest keras_rs/ --ignore=keras_rs/src/layers/embedding/jax |
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.
Instead of the --ignore=keras_rs/src/layers/embedding/jax, can you do this on the JAX tests?
@pytest.mark.skipif(
keras.backend.backend() != "jax",
reason="JAX specific 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.
I think the issue with the Jax test in TF TPU backend is that it has issue with import jax as it's not installed. So the skip won't work here.
keras_rs/src/layers/embedding/jax/distributed_embedding_test.py
Outdated
Show resolved
Hide resolved
keras_rs/src/layers/embedding/tensorflow/config_conversion_test.py
Outdated
Show resolved
Hide resolved
keras_rs/src/layers/feature_interaction/dot_interaction_test.py
Outdated
Show resolved
Hide resolved
| self.on_tpu = "TPU_NAME" in os.environ | ||
| self._strategy = tpu_test_utils.get_tpu_strategy(self) |
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.
Let's not do that in each test class.
For self.on_tpu, you can probably do it once for all in testing.TestCase.setUp.
For self.strategy, let's make a property that is lazily created, in testing.TestCase.setUp.
@property
def strategy(self):
if hasattr(self, "_strategy"):
return self._strategy
...
self._strategy = ...
return self._strategyAlthough, we may have to do that in a piece of code that is shared between all tests, like conftest.py.
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.
Moved to testing.TestCase.setUp. Do we actually want to move the logic to conftest.py instead?
support all tests in layers to tpu