Skip to content

Conversation

pctablet505
Copy link
Collaborator

fixes #21420
we need to do cast before we do further processing.

pctablet505 and others added 28 commits May 6, 2025 10:25
Corrected indentation in doc string
Fixed issue with passing a single image without batch dimension.
Test case for unbatched inputs
Testcase for checking both unbatched and batched single image inputs.
There was a bug, and it was causing cycle in graph.
removed the use of tree.map_structure
Enhanced the _can_use_flash_attention function to provide more detailed
error messages when flash attention compatibility checks fail.

Changes:
- Replace generic exception catching with specific error propagation
- When raise_error=True, directly re-raise original exceptions from
  check_layout() and check_is_flash_attention() functions
- Preserve detailed error context from JAX internal validation functions
- Maintain existing behavior when raise_error=False (returns False)

This improves debugging experience by surfacing specific technical details
about tensor layout incompatibilities, cuDNN version requirements, and
other flash attention compatibility issues.

Relates to keras-hub PR keras-team#2257 and addresses flash attention debugging needs.
…sh_attention`

Changes:
- Add missing q_offsets=None and kv_offsets=None parameters to check_layout()
  call to match updated JAX function signature
- Replace bare `except:` with `except Exception as e:` and `raise e` to
  preserve detailed error messages from JAX validation functions
- Maintain existing fallback behavior when raise_error=False

This resolves compatibility issues with newer JAX versions and improves
debugging experience by surfacing specific technical details about
flash attention compatibility failures.
Simplified the check for `flasth_attention` by removing redundant checks that are already done in `_can_use_flash_attention`.
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.

Summary of Changes

Hello @pctablet505, 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 addresses a reported issue related to map coordinates by implementing robust type casting within the image processing backend. The primary goal is to ensure data type consistency throughout tensor operations, specifically within the process_coordinates function, to prevent runtime errors and improve numerical stability. The changes involve strategic placement of tf.cast operations to align tensor dtypes before further computations.

Highlights

  • Data Type Consistency: Introduced explicit type casting for the gathered tensor to weights[0].dtype early in the process_coordinates function (line 710) to prevent potential type mismatches during subsequent operations.
  • Fill Value Handling: Ensured that the fill_value is also explicitly cast to the correct computation dtype (weights[0].dtype) at line 714 before being used in the tf.where conditional assignment, maintaining type consistency.
  • Code Simplification: Streamlined the calculation of the contribution added to outputs (line 717) by directly using the already cast gathered tensor, removing an intermediate contribution variable and a redundant cast.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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

The code change addresses a type mismatch issue in map_coordinates by casting to the computation dtype earlier, improving correctness.

@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.19%. Comparing base (89d953e) to head (d31faa1).

❗ There is a different number of reports uploaded between BASE (89d953e) and HEAD (d31faa1). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (89d953e) HEAD (d31faa1)
keras 5 4
keras-torch 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21473      +/-   ##
==========================================
- Coverage   82.80%   77.19%   -5.62%     
==========================================
  Files         565      565              
  Lines       55505    55508       +3     
  Branches     8662     8662              
==========================================
- Hits        45962    42849    -3113     
- Misses       7429    10599    +3170     
+ Partials     2114     2060      -54     
Flag Coverage Δ
keras 77.10% <100.00%> (-5.51%) ⬇️
keras-jax 63.39% <66.66%> (+<0.01%) ⬆️
keras-numpy 58.60% <66.66%> (+<0.01%) ⬆️
keras-openvino 33.70% <0.00%> (-0.01%) ⬇️
keras-tensorflow 63.85% <100.00%> (+<0.01%) ⬆️
keras-torch ?

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.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Jul 14, 2025
@google-ml-butler google-ml-butler bot removed the ready to pull Ready to be merged into the codebase label Jul 14, 2025
@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Jul 14, 2025
@fchollet fchollet merged commit 2b394c6 into keras-team:master Jul 14, 2025
8 of 10 checks passed
@google-ml-butler google-ml-butler bot removed awaiting review ready to pull Ready to be merged into the codebase kokoro:force-run labels Jul 14, 2025
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.

keras.ops.image.map_coordinates breaks with TF backend
6 participants