keras
keras copied to clipboard
Keras Import Error with torch backend in Keras 3.0
Hi,
I was using previously keras_core. After it got merged with keras 3.0, I am getting an import error while importing keras with torch as keras backend. The torch version I am using is 1.13.0
Error: `
import os os.environ["KERAS_BACKEND"] = "torch" import keras Traceback (most recent call last): File "
", line 1, in File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/init.py", line 8, in from keras import _tf_keras File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/_tf_keras/init.py", line 1, in from keras._tf_keras import keras File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/_tf_keras/keras/init.py", line 8, in from keras import activations File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/activations/init.py", line 8, in from keras.src.activations import deserialize File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/src/init.py", line 1, in from keras.src import activations File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/src/activations/init.py", line 3, in from keras.src.activations.activations import elu File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/src/activations/activations.py", line 1, in from keras.src import backend File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/src/backend/init.py", line 37, in from keras.src.backend.torch import * # noqa: F403 File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/src/backend/torch/init.py", line 22, in from keras.src.backend.torch import random File "anaconda3/envs/e2enc/lib/python3.9/site-packages/keras/src/backend/torch/random.py", line 2, in import torch._dynamo as dynamo ModuleNotFoundError: No module named 'torch._dynamo'`
ModuleNotFoundError: No module named 'torch._dynamo'`
This module is only present in the latest PyTorch version, I believe.
@kiukchung @haifeng-jin could we make sure to avoid importing _dynamo if the module doesn't exist, as many people are still on PyTorch 1.13.0?
@surajpandey353 how hard would it be to upgrade to torch-2.x?
@fchollet we could add a is_dynamo_available() function and use it to guard imports and functionalities that would trigger dynamo (e.g. setting jit_compile=True with the pytorch backend). We'd still want to decide up to which torch version we want to support since it'll be good to run keras unittests with the major versions of pytorch we "officially" support.
I don't think this is the only issue for torch 1.x.
Anything related to torch.compile in the codebase is only in torch 2.x.
Do we want to fully support PyTorch 1?
We'd still want to decide up to which torch version we want to support since it'll be good to run keras unittests with the major versions of pytorch we "officially" support.
So is it not worth supporting 1.13? That is fine as well.
@surajpandey353 how hard would it be to upgrade to
torch-2.x?
Switching to Pytorch-2x solves this issue. But, just to be clear there is not support for Pytorch 1x versions as of now.
@surajpandey353 , Here is the compatibility matrix for pyTorch and Keras 3
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.
This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.