unitaryai / detoxify

Trained models & code to predict toxic comments on all 3 Jigsaw Toxic Comment Challenges. Built using ⚡ Pytorch Lightning and 🤗 Transformers. For access to our API, please email us at contact@unitary.ai.
https://www.unitary.ai/
Apache License 2.0
935 stars 114 forks source link

"torch" error by just importing Detoxify #97

Closed IskandarAlex2 closed 2 months ago

IskandarAlex2 commented 11 months ago

Python: 3.10.9 I am getting AttributeError: module 'torch' has no attribute 'no_grad' error when trying to run a simple code, following the short guide inside read me. I am new to Python, I am sorry if my mistake is too obvious.

from detoxify import Detoxify
results = Detoxify('original').predict('example text')

print(results)

Full error:

Traceback (most recent call last):
  File "G:\Deving\Saihex\BOSS-FEEDBACK-BACKEND\index.py", line 1, in <module>     
    from detoxify import Detoxify
  File "C:\Py3.10.9\lib\site-packages\detoxify\__init__.py", line 1, in <module>  
    from .detoxify import (
  File "C:\Py3.10.9\lib\site-packages\detoxify\detoxify.py", line 73, in <module> 
    class Detoxify:
  File "C:\Py3.10.9\lib\site-packages\detoxify\detoxify.py", line 112, in Detoxify
    @torch.no_grad()
AttributeError: module 'torch' has no attribute 'no_grad'
laurahanu commented 8 months ago

You probably have to install/update your torch version! Try pip install --upgrade torch torchvision or follow the instructions on the pytorch website