Skip to content
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

Backend not switching dynamically between tensorflow and torch #20918

Open
jobs-git opened this issue Feb 17, 2025 · 2 comments
Open

Backend not switching dynamically between tensorflow and torch #20918

jobs-git opened this issue Feb 17, 2025 · 2 comments
Assignees
Labels

Comments

@jobs-git
Copy link

jobs-git commented Feb 17, 2025

As the title says, using keras 3.8 on python 3.10:

from keras.src.utils import backend_utils
from keras.src import backend
dynamic = backend_utils.DynamicBackend ()
dynamic.set_backend('tensorflow')
print (backend.backend())
dynamic.set_backend('torch')
print (backend.backend())
tensorflow
tensorflow
@sonali-kumari1
Copy link
Contributor

sonali-kumari1 commented Feb 18, 2025

Hi @jobs-git -

Thanks for reporting this issue!
keras.backend.backend() returns global keras backend, which is tensorflow by default. However, DynamicBackend creates a local backend instance, so you can try printing dynamic.name to know the backend you are using locally with DynamicBackend like this:

from keras.src.utils import backend_utils
from keras.src import backend
import tensorflow as tf
dynamic = backend_utils.DynamicBackend()
dynamic.set_backend('tensorflow')
print(dynamic.name)
dynamic.set_backend('torch')
print(dynamic.name)

@jobs-git
Copy link
Author

Right, its working that way. Could we get a documentation to on its usage? (i.e. Sequential among others) The backend_utils_test.py only shows one or few example of calculating with the backend using numpy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants