-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Document that set_backend requires re-importing keras.
#21764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,12 @@ def set_backend(backend): | |
| Example: | ||
|
|
||
| ```python | ||
| import keras | ||
|
|
||
| keras.config.set_backend("jax") | ||
|
|
||
| del keras | ||
| import keras | ||
| ``` | ||
|
|
||
| ⚠️ WARNING ⚠️: Using this function is dangerous and should be done | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
|
|
@@ -138,7 +143,7 @@ def set_backend(backend): | |
|
|
||
| This includes any function or class instance that uses any Keras | ||
| functionality. All such code needs to be re-executed after calling | ||
| `set_backend()`. | ||
| `set_backend()` and re-importing the `keras` module. | ||
| """ | ||
| os.environ["KERAS_BACKEND"] = backend | ||
| # Clear module cache. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
kerasis necessary and what the function accomplishes. This aligns with the style guide's emphasis on showing how to use the API to solve problems.1Style Guide References
Footnotes
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. ↩