Skip to content

Try to change backend to ‘torch’, but still 'tensorflow'. #19542

Closed
@ranck626

Description

@ranck626

I only download torchs and i do not have tensorflow.
I had thought it was a matter of not successfully modifying the backend. But I found out through the output that the modification was successful. It seems that some functions inside keras-nlp are written using tensorflow. I'm guessing this is the issue and would appreciate your attention and answers.
torch 2.1.0
torchaudio 2.1.0
torchvision 0.16.0
cuda11.8/toolkit/11.8.0
cudnn8.5-cuda11.8/8.5.0.96

/home/name/.keras/keras.json
I try KERAS-HOME and KERAS-BACKEND
{
"floatx": "float32",
"epsilon": 1e-07,
"backend": "torch",
"image_data_format": "channels_last"
}
from keras import backend as K
print(K.backend()) # torch

maybe the key is keras-nlp

Traceback (most recent call last):
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/src/backend/config.py", line 21, in detect_if_tensorflow_uses_keras_3
from tensorflow import keras
ModuleNotFoundError: No module named 'tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/name/codes/gemma_demo.py", line 11, in
import keras_nlp
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/init.py", line 8, in
from keras_nlp import layers
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/layers/init.py", line 8, in
from keras_nlp.src.layers.modeling.alibi_bias import AlibiBias
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/src/init.py", line 23, in
from keras_nlp.src import layers
File "/home/xuzichao/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/src/layers/init.py", line 15, in
from keras_nlp.src.layers.modeling.cached_multi_head_attention import (
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/src/layers/modeling/cached_multi_head_attention.py", line 15, in
from keras_nlp.src.api_export import keras_nlp_export
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/src/api_export.py", line 17, in
from keras_nlp.src.backend import keras
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/src/backend/init.py", line 29, in
from keras_nlp.src.backend import config
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/src/backend/config.py", line 38, in
_USE_KERAS_3 = detect_if_tensorflow_uses_keras_3()
File "/home/name/miniconda3/envs/huaxin/lib/python3.10/site-packages/keras_nlp/src/backend/config.py", line 27, in detect_if_tensorflow_uses_keras_3
raise ValueError(
ValueError: Unable to import keras with tensorflow. Please check your Keras and Tensorflow version are compatible; Keras 3 requires TensorFlow 2.15 or later. See keras.io/getting_started for more information on installing Keras.

Metadata

Metadata

Labels

GemmaGemma model specific issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions