6

I am using VQGAN+CLIP_(Zooming)_(z+quantize_method_with_addons).ipynb Google Repository and when I click the cell "Loading of libraries and definitions"

It sent an error :

ImportError                               Traceback (most recent call last)
<ipython-input-6-fe8fafeed45d> in <module>
     24 from omegaconf import OmegaConf
     25 from PIL import Image
---> 26 from taming.models import cond_transformer, vqgan
     27 import torch
     28 from torch import nn, optim

1 frames
/content/taming-transformers/main.py in <module>
     10 from pytorch_lightning.trainer import Trainer
     11 from pytorch_lightning.callbacks import ModelCheckpoint, Callback, LearningRateMonitor
---> 12 from pytorch_lightning.utilities.distributed import rank_zero_only
     13 
     14 from taming.data.utils import custom_collate

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

I don't know how to solde this problem. I don't know how to manually install Pytorch as it said "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."

Thank you in advance if you have the solution.

Inès

I triad !pip install but I may not really know where to put this cell/line of code

Ines Sieulle
  • 61
  • 1
  • 1
  • 2

5 Answers5

10

pytorch_lightning has recently released a new version which will throw this error (version 1.8.0.post1 released on November 2nd 2022).

https://pypi.org/project/pytorch-lightning/#history

Just install an older version of pytorch_lightning and it will work.

In my system, I ran "pip install pytorch-lightning==1.6.5", higher versions may work as well, you can check them out by clicking on the link provided above and then clicking on release history.

Vishisht Rao
  • 101
  • 4
  • 2
    Thanks, that works! I used pytorch_lightning==1.7.7 which worked out! – Dima Nov 04 '22 at 18:58
  • 1
    Thanks @Gira. `v1.7.7` solved my problem as well. Inès, would you flag the answer as _Accepted_? – Mert Nov 10 '22 at 10:32
7

now rank_zero_only is in /pytorch_lightning/utilities/rank_zero.py

from pytorch_lightning.utilities.rank_zero import rank_zero_only

  • Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Mar 29 '23 at 18:32
1

Finally, after long research, I found the solution for it, try to run it, you will face an issue with CLIP module, once you resolve python issue as well, so for that follow the second code.

conda install pytorch-lightning -c conda-forge

Once you clone it, try to follow below command

Step:1 cd CLIP 
Step2: python setup.py

after that,

type: cd..

Once you do that, you will be redirected to previous directory named "VQGAN-CLIP"

and finally, run the following command:

python generate.py -p "A painting of an apple in a fruit bowl"

Once it is done, then run your generate python file, It will work fine.

Decoder
  • 11
  • 2
0
  1. use @vishisht-rao solution to downgrade the package version of pytorch-lightning to 1.7.7; this step by itself did not solve the problem for me.

    pip install pytorch-lightning==1.6.5
    
  2. run pip list|grep lightning to find the installed version of lightning-utilities. Mine was lightning-utilities==0.4.2

  3. Downgrade the package version of lightning-utilities to 0.4.0

    pip install lightning-utilities==0.4.0
    

Downgrading the package versions of both pytorch-lightning and lightning-utilities solved the problem for me.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
kelper
  • 1
0

rank_zero_only function has been move from distributed.py to rank_zero.py in pl1.6 milestone in PR11747. And you can import this function via distributed during pl version 1.7.x.

Since version 1.8.0, pytorch-lighting has removed pytorch_lightning.utilities.distributed.py but saying nothing about it in the changelog. (You can get the package from here.)

So, there are two solutions here:

  1. pip install --force --reinstall pytorch-lighting<1.8.0
  2. import rank_zero relative functions from from pytorch_lightning.utilities.rank_zero if pytorch-lighting>=1.8.0