Skip to content

Conversation

@hertschuh
Copy link
Collaborator

Addressing comments from #21764

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hertschuh, 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 improves the user experience and safety when using the set_backend utility in Keras. It introduces a prominent warning to alert users to the potential pitfalls of switching backends dynamically, such as issues with existing Keras objects. Additionally, it provides a more comprehensive and illustrative example, along with a docstring clarification, to guide users through the correct procedure for changing backends and ensuring all related modules are properly reloaded.

Highlights

  • Warning Added to set_backend: A UserWarning has been integrated into the keras.config.set_backend function to explicitly caution users about the implications of dynamically changing the Keras backend, particularly regarding already-instantiated objects and the necessity of re-importing modules.
  • Enhanced Example for set_backend: The example for keras.config.set_backend has been significantly expanded to provide a more detailed and practical demonstration of switching backends, including setting environment variables, verifying tensor types, and the critical step of re-importing Keras modules after a backend change.
  • Docstring Clarification: The docstring for set_backend has been updated to clarify that all imported Keras modules need to be re-imported, not just the keras module itself, to ensure the backend change is fully applied.
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.

@hertschuh
Copy link
Collaborator Author

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 improves the set_backend function by adding a runtime warning and a more detailed usage example in the docstring. These changes significantly enhance the user experience by making the function's behavior and potential risks much clearer. The new example is particularly helpful. I've identified a minor grammatical error in the updated docstring and have provided a suggestion for a fix.

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Oct 27, 2025
@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.63%. Comparing base (eecd34f) to head (b155895).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/utils/backend_utils.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21787      +/-   ##
==========================================
- Coverage   82.63%   82.63%   -0.01%     
==========================================
  Files         577      577              
  Lines       59316    59318       +2     
  Branches     9300     9300              
==========================================
+ Hits        49018    49019       +1     
- Misses       7910     7911       +1     
  Partials     2388     2388              
Flag Coverage Δ
keras 82.46% <50.00%> (-0.01%) ⬇️
keras-jax 63.32% <50.00%> (-0.01%) ⬇️
keras-numpy 57.55% <50.00%> (-0.01%) ⬇️
keras-openvino 34.29% <50.00%> (+<0.01%) ⬆️
keras-tensorflow 64.11% <50.00%> (-0.01%) ⬇️
keras-torch 63.62% <50.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.
@hertschuh hertschuh merged commit adbfd13 into keras-team:master Oct 27, 2025
11 checks passed
@google-ml-butler google-ml-butler bot removed awaiting review ready to pull Ready to be merged into the codebase labels Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 participants