Skip to content

Conversation

@Abhinavexists
Copy link
Contributor

@Abhinavexists Abhinavexists commented Nov 15, 2025

Fix: #21808

using dot_product_attention with a mask inside JAX control flow operations (e.g., while_loop, scan) on TPU, the code raised a ConcretizationTypeError

Added a traced mask detection check before attempting to use TPU flash attention

Add check for traced masks to disable flash attention.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Abhinavexists, 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 resolves a specific ConcretizationTypeError that arose when dynamic attention masks, represented as JAX Tracer objects, were passed to the dot_product_attention function within JAX's control flow on TPU devices. The fix ensures that the system gracefully handles these traced masks by bypassing the incompatible TPU flash attention mechanism, thereby improving the robustness and compatibility of attention operations within JAX's tracing environment.

Highlights

  • Error Resolution: Addresses a ConcretizationTypeError that occurred when dot_product_attention was used with traced masks within JAX control flow operations on TPUs.
  • Flash Attention Logic: Introduces a check within the dot_product_attention function to detect if the provided mask is a JAX Tracer and, if so, disables the use of TPU flash attention to prevent the error.
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.

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2025

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.47%. Comparing base (edbf8f5) to head (862c271).

Files with missing lines Patch % Lines
keras/src/backend/jax/nn.py 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21853   +/-   ##
=======================================
  Coverage   82.47%   82.47%           
=======================================
  Files         577      577           
  Lines       59508    59510    +2     
  Branches     9332     9333    +1     
=======================================
+ Hits        49080    49082    +2     
  Misses       8015     8015           
  Partials     2413     2413           
Flag Coverage Δ
keras 82.30% <0.00%> (+<0.01%) ⬆️
keras-jax 62.89% <0.00%> (-0.01%) ⬇️
keras-numpy 57.55% <0.00%> (-0.01%) ⬇️
keras-openvino 34.34% <0.00%> (-0.01%) ⬇️
keras-tensorflow 64.12% <0.00%> (+<0.01%) ⬆️
keras-torch 63.60% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 fixes a ConcretizationTypeError that occurs when using dot_product_attention with a traced mask on TPUs. The fix involves adding a check to detect if the mask is a JAX tracer and, if so, disabling flash attention. This is a good and direct solution to the problem. I've suggested a small improvement to scope this check specifically to the TPU platform, aligning it more closely with the reported issue and preventing any potential unintended side effects on other platforms like GPU.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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 addresses a ConcretizationTypeError that occurs when using dot_product_attention with a traced mask on TPUs, which typically happens within JAX control flow constructs like scan or while_loop. The fix involves detecting if the attention mask is a JAX Tracer and disabling flash attention in that case to fall back to a compatible implementation. My review focuses on making this fix more precise to avoid potential performance regressions on other hardware platforms. I've suggested restricting the check to only apply on TPUs, aligning it more closely with the described issue.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

Failed to apply Splash kernel for flash attention.

3 participants