Skip to content

Skip tests not for sparsecore in setUp instead of the decorator.#184

Merged
hertschuh merged 1 commit intokeras-team:mainfrom
hertschuh:jax_tpu_tests
Mar 3, 2026
Merged

Skip tests not for sparsecore in setUp instead of the decorator.#184
hertschuh merged 1 commit intokeras-team:mainfrom
hertschuh:jax_tpu_tests

Conversation

@hertschuh
Copy link
Collaborator

Decorators are evaluated before the unit tests are run and JAX may not be available.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 refactors the test skipping mechanism for JAX-related tests, specifically those dependent on SparseCores. The change addresses an issue where pytest.mark.skipif decorators are evaluated too early, before the JAX backend might be fully initialized. By relocating the SparseCores availability check into the setUp method of the test class, and adjusting the decorator to simply verify the JAX backend, the tests now correctly determine their execution environment, leading to more reliable test runs.

Highlights

  • Test Skipping Logic Refinement: Modified how tests requiring SparseCores are skipped, moving the check from pytest.mark.skipif decorators to the setUp method of the test class. This ensures JAX is available when the check is performed.
  • pytest.mark.skipif Condition Update: Updated the pytest.mark.skipif decorators for several test classes to explicitly check if the Keras backend is set to "jax", ensuring tests are only run in the appropriate environment.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • keras_rs/src/layers/embedding/jax/distributed_embedding_test.py
    • Replaced pytest.mark.skipif condition checking for SparseCores availability with a check for the Keras backend being "jax" for ShardedInitializerTest.
    • Replaced pytest.mark.skipif condition checking for SparseCores availability with a check for the Keras backend being "jax" for StackedTableInitializerTest.
    • Replaced pytest.mark.skipif condition checking for SparseCores availability with a check for the Keras backend being "jax" for DistributedEmbeddingLayerTest.
    • Added a setUp method to DistributedEmbeddingLayerTest to perform the SparseCores availability check and skip the test if not available.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 refactors how tests are skipped when SparseCores are not available by moving the check from a decorator to the setUp method. This is a good change to avoid issues with decorator evaluation time. However, the change is applied inconsistently. StackedTableInitializerTest also requires SparseCores but is missing the setUp method, which will cause test failures on environments without them. I've added a comment with a fix.

reason="Requires SparseCores",
)
@pytest.mark.skipif(keras.backend.backend() != "jax", "JAX backend required.")
class StackedTableInitializerTest(parameterized.TestCase):
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 class requires SparseCores because its tests call jte_utils.num_sparsecores_per_device(), which will raise an error if SparseCores are not available. To align with the goal of this PR, you should add a setUp method to skip these tests, similar to the implementation in DistributedEmbeddingLayerTest.

class StackedTableInitializerTest(parameterized.TestCase):
    def setUp(self):
        super().setUp()
        if not jax_distributed_embedding.DistributedEmbedding.has_sparsecores():
            self.skipTest("Requires SparseCores")

Decorators are evaluated before the unit tests are run and JAX may not be available.
Copy link
Collaborator

@laxmareddyp laxmareddyp left a comment

Choose a reason for hiding this comment

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

LGTM

@hertschuh hertschuh merged commit f101af0 into keras-team:main Mar 3, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants