minimaxir / aitextgen

A robust Python tool for text-based AI training and generation using GPT-2.
https://docs.aitextgen.io
MIT License
1.84k stars 218 forks source link

ImportError: cannot import name '_TPU_AVAILABLE' from 'pytorch_lightning.utilities' #200

Closed ProfessorQu closed 1 year ago

ProfessorQu commented 1 year ago

Tested in a colab notebook, with !pip install aitextgen -q. Then ran

from aitextgen import aitextgen

ai = aitextgen()

in the next cell, an got this error:

---------------------------------------------------------------------------

ImportError                               Traceback (most recent call last)

[<ipython-input-5-5376f3cb6e07>](https://localhost:8080/#) in <module>
----> 1 from aitextgen import aitextgen
      2 
      3 ai = aitextgen()

2 frames

[/usr/local/lib/python3.7/dist-packages/aitextgen/train.py](https://localhost:8080/#) in <module>
     12 import pytorch_lightning as pl
     13 from pytorch_lightning.callbacks.progress import ProgressBarBase
---> 14 from pytorch_lightning.utilities import _TPU_AVAILABLE
     15 
     16 

ImportError: cannot import name '_TPU_AVAILABLE' from 'pytorch_lightning.utilities' (/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/__init__.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
ephraimduncan commented 1 year ago

I had the same issue on an M1.

You can fix it by downgrading aitextgen

pip3 install -q aitextgen==0.5.2
katemonster33 commented 1 year ago

@dephraiim Downgrading did not work for me - same error.

ioistired commented 1 year ago

Can confirm this issue on both 0.5.2 and 0.6.0.

katemonster33 commented 1 year ago

Was able to get past this error by downgrading pytorch_lightning to 1.7.7, still having errors in torch though.

bdunnette commented 1 year ago

Uninstalling torch and then reinstalling with version 1.9.0 seems to do the trick:

!pip uninstall -qqy torch torchvision torchtext torchaudio fastai
!pip install -qq torch==1.9.0 pytorch-lightning==1.7.7 aitextgen==0.6.0 
mirrorsonthewall commented 1 year ago

Tried bdunnette's code but it gave an error, something like that pytorch wasn't available among options of pytorch-lighting 1.11.0 through 1.13.0, so I chose 1.11.0 and it seemed to work instead (after running first uninstall line):

pip install -qq torch==1.9.0 pytorch-lightning==1.11.0 aitextgen==0.6.0

rmc135 commented 1 year ago

FYI, I had the same error. A downgrade to 0.5.2 did not change behaviour, but a further step back to 0.5.1 worked.

This is under pyenv/venv 3.9.15

ThatCoffeeGuy commented 1 year ago

Same issue here. Interestingly I installed the packages with the same command on 2 different machines(Same ubuntu server OS) and only one of them is having this issue.

This solved it:

pip uninstall -qqy torch torchvision torchtext torchaudio fastai
pip install -qq torch==1.11.0 pytorch-lightning==1.7.7 aitextgen==0.6.0
thani-ath-nain commented 1 year ago

None of the above worked for me. Please someone suggest something different

carmocca commented 1 year ago

For any lurkers, @llimllib was kind enough to propose a fix in #202. You can apply the patch locally or pip install git+https://github.com/llimllib/aitextgen@fix_tpu_available until a maintainer merges the PR (at your own discretion).

For the project maintainers, it might be a good idea to pin your dependencies, particularly the PL one, to avoid issues like this: https://github.com/minimaxir/aitextgen/blob/74246011141ce947b4d01044b266df0456e1250c/requirements.txt#L3

jryebread commented 1 year ago

Still getting this issue even after pip installing the separate branch 🤔 None of these options worked for me in the finetuning gpt2 colab

pst2154 commented 1 year ago

All I had to do was restart my jupyter kernal after installing, then import worked

KonradHoeffner commented 1 year ago

The solution of @carmocca worked for me, but only after pip uninstall aitextgen first.