Skip to content

Conversation

@hertschuh
Copy link
Collaborator

Both in the example and the documentation.

Both in the example and the documentation.
@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 enhances the clarity of the keras.config.set_backend function's usage by updating both its example code and docstring. This ensures that users are explicitly aware that a re-import of the keras module is necessary after changing the backend, preventing potential confusion and unexpected behavior.

Highlights

  • Example Update: The example code for keras.config.set_backend has been updated to explicitly demonstrate the necessity of re-importing the keras module after changing the backend.
  • Documentation Clarification: The docstring for set_backend now clearly states that re-importing the keras module is required after calling the function for changes to take effect.
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.

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Oct 22, 2025
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 documentation for keras.config.set_backend by clarifying that the keras module must be re-imported after changing the backend. The changes in both the code example and the warning text are clear and helpful for users. I've suggested a small improvement to the code example to make it even more illustrative of the function's effect.

Comment on lines +128 to +133
import keras
keras.config.set_backend("jax")
del keras
import keras
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The example is good, but it could be more illustrative by showing the effect of changing the backend. A slightly more verbose example that prints the backend name before and after the change would make it clearer to users why re-importing keras is necessary and what the function accomplishes. This aligns with the style guide's emphasis on showing how to use the API to solve problems.1

Suggested change
import keras
keras.config.set_backend("jax")
del keras
import keras
import keras
print(f"Backend before: {keras.backend.backend()}")
keras.config.set_backend("jax")
del keras
import keras
print(f"Backend after: {keras.backend.backend()}")

Style Guide References

Footnotes

  1. The style guide recommends that documentation should show code examples for end-to-end workflows to demonstrate how to use the API, rather than just talking about how it works. A more illustrative example better serves this purpose.

@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.69%. Comparing base (47fcb39) to head (b6615dd).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21764   +/-   ##
=======================================
  Coverage   82.69%   82.69%           
=======================================
  Files         573      573           
  Lines       58888    58888           
  Branches     9218     9218           
=======================================
  Hits        48696    48696           
  Misses       7845     7845           
  Partials     2347     2347           
Flag Coverage Δ
keras 82.49% <ø> (ø)
keras-jax 63.24% <ø> (ø)
keras-numpy 57.72% <ø> (ø)
keras-openvino 34.40% <ø> (ø)
keras-tensorflow 64.01% <ø> (ø)
keras-torch 63.56% <ø> (ø)

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.

import keras
```
⚠️ WARNING ⚠️: Using this function is dangerous and should be done
Copy link

Choose a reason for hiding this comment

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

Perhaps it would good to print/display some of this warning text when set_backend() is run, otherwise it looks like a silent failure (when a set_backend() is called but the backend doesn't actually change).

If concerned about spamming text, perhaps there can be a flag to suppress the warning (but default to printing something, since this is such a "dangerous" function)

Copy link
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

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

In fact, it requires reimporting every single thing imported from Keras! And redefining any function that was using them I believe?

@fchollet fchollet merged commit 53987a7 into keras-team:master Oct 24, 2025
12 checks passed
@google-ml-butler google-ml-butler bot removed awaiting review ready to pull Ready to be merged into the codebase labels Oct 24, 2025
@hertschuh hertschuh deleted the set_backend_import branch October 27, 2025 17:36
hertschuh added a commit to hertschuh/keras that referenced this pull request Oct 27, 2025
hertschuh added a commit to hertschuh/keras that referenced this pull request Oct 27, 2025
hertschuh added a commit to hertschuh/keras that referenced this pull request Oct 27, 2025
hertschuh added a commit that referenced this pull request Oct 27, 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.

7 participants