# Transformers trying to use keras?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftransformers-trying-to-use-keras%2F44245%3E%5C
**Category:** 🤗Transformers\
**Created:** [June 23, 2023, 1:00am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftransformers-trying-to-use-keras%2F44245 "2023-06-23T01:00:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![EEE211](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@EEE211](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FEEE211)%5C
**Post date:** [June 23, 2023, 1:00am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftransformers-trying-to-use-keras%2F44245%2F1 "2023-06-23T01:00:22Z")

</div>

Hello,

I am trying to setup a very simple example:

from transformers import pipeline  
generator = pipeline(‘text-generation’, model=‘gpt2’)

But it seems transformers is automatically trying to use keras instead of pytorch. This seems to be happening with any model I use, not just gpt2. Its also happening only with pipeline, the rest of examples I can run just fine.

Is this the expected behaviour?  
if so, is it possible to switch it to pytorch?

Error I get:

ModuleNotFoundError Traceback (most recent call last)  
File c:\Users\LKP\anaconda3\envs\hugg\lib\site-packages\transformers\utils\import\_utils.py:1082, in \_LazyModule.\_get\_module(self, module\_name)  
1081 try:  
 → 1082 return importlib.import\_module(“.” + module\_name, self. **name** )  
1083 except Exception as e:

File c:\Users\LKP\anaconda3\envs\hugg\lib\importlib\__init_\_.py:127, in import\_module(name, package)  
126 level += 1  
 → 127 return \_bootstrap.\_gcd\_import(name[level:], package, level)

File :1014, in \_gcd\_import(name, package, level)

File :991, in _find\_and\_load(name, import_)

File :975, in _find\_and\_load\_unlocked(name, import_)

File :671, in \_load\_unlocked(spec)

File :843, in exec\_module(self, module)

File :219, in \_call\_with\_frames\_removed(f, \*args, \*\*kwds)

File c:\Users\LKP\anaconda3\envs\hugg\lib\site-packages\transformers\models\gpt2\modeling\_tf\_gpt2.py:26  
24 import tensorflow as tf  
—\> 26 from …activations\_tf import get\_tf\_activation  
27 from …modeling\_tf\_outputs import (  
28 TFBaseModelOutputWithPastAndCrossAttentions,  
29 TFCausalLMOutputWithCrossAttentions,  
30 TFSequenceClassifierOutputWithPast,  
31 )

File c:\Users\LKP\anaconda3\envs\hugg\lib\site-packages\transformers\activations\_tf.py:107  
105 return tf.keras.activations.gelu(x, approximate=True)  
 → 107 gelu = tf.keras.activations.gelu  
108 gelu\_new = approximate\_gelu\_wrap

File ~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\util\lazy\_loader.py:58, in LazyLoader. **getattr** (self, item)  
57 def **getattr** (self, item):  
—\> 58 module = self.\_load()  
59 return getattr(module, item)

File ~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\util\lazy\_loader.py:41, in LazyLoader.\_load(self)  
40 # Import the target module and insert it into the parent’s namespace  
—\> 41 module = importlib.import\_module(self. **name** )  
42 self.\_parent\_module\_globals[self.\_local\_name] = module

File c:\Users\LKP\anaconda3\envs\hugg\lib\importlib\__init_\_.py:127, in import\_module(name, package)  
126 level += 1  
 → 127 return \_bootstrap.\_gcd\_import(name[level:], package, level)

ModuleNotFoundError: No module named ‘keras’

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last)  
Cell In[2], line 8  
5 from transformers import pipeline  
6 #from transformers import pipeline, set\_seed  
----\> 8 generator = pipeline(‘text-generation’, model=‘gpt2’)

File c:\Users\LKP\anaconda3\envs\hugg\lib\site-packages\transformers\pipelines\__init_\_.py:788, in pipeline(task, model, config, tokenizer, feature\_extractor, image\_processor, framework, revision, use\_fast, use\_auth\_token, device, device\_map, torch\_dtype, trust\_remote\_code, model\_kwargs, pipeline\_class, \*\*kwargs)  
786 if isinstance(model, str) or framework is None:  
787 model\_classes = {“tf”: targeted\_task[“tf”], “pt”: targeted\_task[“pt”]}  
 → 788 framework, model = infer\_framework\_load\_model(  
789 model,  
790 model\_classes=model\_classes,  
791 config=config,  
792 framework=framework,  
793 task=task,  
794 \*\*hub\_kwargs,  
795 \*\*model\_kwargs,  
796 )  
798 model\_config = model.config  
799 hub\_kwargs[“\_commit\_hash”] = model.config.\_commit\_hash

File c:\Users\LKP\anaconda3\envs\hugg\lib\site-packages\transformers\pipelines\base.py:245, in infer\_framework\_load\_model(model, config, model\_classes, task, framework, \*\*model\_kwargs)  
243 classes.append(\_class)  
244 if look\_tf:  
 → 245 \_class = getattr(transformers\_module, f"TF{architecture}", None)  
246 if \_class is not None:  
247 classes.append(\_class)

File c:\Users\LKP\anaconda3\envs\hugg\lib\site-packages\transformers\utils\import\_utils.py:1073, in \_LazyModule. **getattr** (self, name)  
1071 elif name in self.\_class\_to\_module.keys():  
1072 module = self.\_get\_module(self.\_class\_to\_module[name])  
 → 1073 value = getattr(module, name)  
1074 else:  
1075 raise AttributeError(f"module {self. **name** } has no attribute {name}")

File c:\Users\LKP\anaconda3\envs\hugg\lib\site-packages\transformers\utils\import\_utils.py:1072, in \_LazyModule. **getattr** (self, name)  
1070 value = self.\_get\_module(name)  
1071 elif name in self.\_class\_to\_module.keys():  
 → 1072 module = self.\_get\_module(self.\_class\_to\_module[name])  
1073 value = getattr(module, name)  
1074 else:

File c:\Users\LKP\anaconda3\envs\hugg\lib\site-packages\transformers\utils\import\_utils.py:1084, in \_LazyModule.\_get\_module(self, module\_name)  
1082 return importlib.import\_module(“.” + module\_name, self. **name** )  
1083 except Exception as e:  
 → 1084 raise RuntimeError(  
1085 f"Failed to import {self. **name** }.{module\_name} because of the following error (look up to see its"  
1086 f" traceback):\n{e}"  
1087 ) from e

RuntimeError: Failed to import transformers.models.gpt2.modeling\_tf\_gpt2 because of the following error (look up to see its traceback):  
No module named ‘keras’
