latent-diffusion icon indicating copy to clipboard operation
latent-diffusion copied to clipboard

packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'

Open shencuifeng opened this issue 3 years ago • 20 comments

I meet this error when start training

Traceback (most recent call last): File "main.py", line 6, in import pytorch_lightning as pl File "/opt/conda/envs/ldm/lib/python3.8/site-packages/pytorch_lightning/init.py", line 20, in from pytorch_lightning import metrics # noqa: E402 File "/opt/conda/envs/ldm/lib/python3.8/site-packages/pytorch_lightning/metrics/init.py", line 15, in from pytorch_lightning.metrics.classification import ( # noqa: F401 File "/opt/conda/envs/ldm/lib/python3.8/site-packages/pytorch_lightning/metrics/classification/init.py", line 14, in from pytorch_lightning.metrics.classification.accuracy import Accuracy # noqa: F401 File "/opt/conda/envs/ldm/lib/python3.8/site-packages/pytorch_lightning/metrics/classification/accuracy.py", line 16, in from torchmetrics import Accuracy as _Accuracy File "/opt/conda/envs/ldm/lib/python3.8/site-packages/torchmetrics/init.py", line 14, in from torchmetrics import functional # noqa: E402 File "/opt/conda/envs/ldm/lib/python3.8/site-packages/torchmetrics/functional/init.py", line 82, in from torchmetrics.functional.text.bleu import bleu_score File "/opt/conda/envs/ldm/lib/python3.8/site-packages/torchmetrics/functional/text/init.py", line 30, in from torchmetrics.functional.text.bert import bert_score # noqa: F401 File "/opt/conda/envs/ldm/lib/python3.8/site-packages/torchmetrics/functional/text/bert.py", line 24, in from torchmetrics.functional.text.helper_embedding_metric import ( File "/opt/conda/envs/ldm/lib/python3.8/site-packages/torchmetrics/functional/text/helper_embedding_metric.py", line 26, in from transformers import AutoModelForMaskedLM, AutoTokenizer, PreTrainedModel, PreTrainedTokenizerBase File "/opt/conda/envs/ldm/lib/python3.8/site-packages/transformers/init.py", line 43, in from . import dependency_versions_check File "/opt/conda/envs/ldm/lib/python3.8/site-packages/transformers/dependency_versions_check.py", line 41, in require_version_core(deps[pkg]) File "/opt/conda/envs/ldm/lib/python3.8/site-packages/transformers/utils/versions.py", line 94, in require_version_core return require_version(requirement, hint) File "/opt/conda/envs/ldm/lib/python3.8/site-packages/transformers/utils/versions.py", line 85, in require_version if want_ver is not None and not ops[op](version.parse(got_ver), version.parse(want_ver)): File "/opt/conda/envs/ldm/lib/python3.8/site-packages/packaging/version.py", line 52, in parse return Version(version) File "/opt/conda/envs/ldm/lib/python3.8/site-packages/packaging/version.py", line 197, in init raise InvalidVersion(f"Invalid version: '{version}'") packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'

shencuifeng avatar Dec 22 '22 08:12 shencuifeng

I have the same problem.

tianye2856 avatar Dec 22 '22 11:12 tianye2856

having the same problem. It has something to do with transformers package and pl version

GiannisPikoulis avatar Dec 22 '22 22:12 GiannisPikoulis

I get the same issue. I updated pytorch-lightning to a more recent version like 1.5.0, which fixed this error: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' but then it created a different issue in pytorch-lightning where it couldn't create a trainer from arguments. NameError: name 'trainer' is not defined

scottp100 avatar Dec 22 '22 23:12 scottp100

if you remove the transformers package, then it runs correctly. Also kornia (0.5.0) needs to be installed and torchmetrics 0.10 or 0.11

GiannisPikoulis avatar Dec 22 '22 23:12 GiannisPikoulis

I get the same issue. I updated pytorch-lightning to a more recent version like 1.5.0, which fixed this error: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' but then it created a different issue in pytorch-lightning where it couldn't create a trainer from arguments. NameError: name 'trainer' is not defined

did you fix the '0.10.1<0.11' error?

GiannisPikoulis avatar Dec 22 '22 23:12 GiannisPikoulis

I have the same problem

Downgrade torchmetrics to 0.5

GiannisPikoulis avatar Dec 23 '22 00:12 GiannisPikoulis

using pytorch-lightning=1.8 works fine for me.

lx709 avatar Dec 30 '22 11:12 lx709

  • packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'
    • Upgrading transfomers to 4.6 or higher works for me
    • Related issue: https://github.com/huggingface/transformers/issues/20799#issuecomment-1375328420
  • ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data'
    • Downgrading torchmetrics to 0.6 works for me

zaburo-ch avatar Jan 09 '23 09:01 zaburo-ch

use pip list | grep packaging to check if the version of your packaging is upper than 21.3

try to reinstall your packaging , like this pip install packaging==21.3

this issue has something to do with the format requirements in new packaging version checking

Candysad avatar Jan 10 '23 14:01 Candysad

TLDR:

conda env create -f environment.yaml
conda activate ldm
pip install packaging==21.3
pip install 'torchmetrics<0.8'

  • Perform pip install packaging==21.3 as mentioned by @Candysad to fix packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'.
  • Then comes to the second error ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data'. This is because torchmetrics removed get_num_classes from torchmetrics.utilities.data at version v0.8.0, so a quick fix can be pip install 'torchmetrics<0.8' to downgrade your torchmetrics version to 0.7.3

HuengchI avatar Jan 11 '23 13:01 HuengchI

I get the same issue. I updated pytorch-lightning to a more recent version like 1.5.0, which fixed this error: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' but then it created a different issue in pytorch-lightning where it couldn't create a trainer from arguments. NameError: name 'trainer' is not defined

hey, did you solve the problem with the 'trainer' not defined?

thesisfinitobitte avatar Mar 08 '23 16:03 thesisfinitobitte

I'm interested in how did you solve the NameError: name 'trainer' is not defined as well

isbkch avatar Mar 18 '23 00:03 isbkch

Hello, I would like to ask the difference between unconditional LDM and conditional LDM. After the model is trained, is unconditional sampling generate image randomly, but not based on a given image? So, if I want to generate a normal image from a flawed image (without any annotations in the inference phase), should I use conditional LDM? @HuengchI @zaburo-ch @tianye2856 @scottp100

ustczhouyu avatar Mar 27 '23 03:03 ustczhouyu

me too, good job

But a final step “pip install einops==0.6.0” was before successful running at my side.

picard314 avatar Apr 07 '23 10:04 picard314

conda env create -f environment.yaml conda activate ldm pip install packaging==21.3 pip install 'torchmetrics<0.8'

Works good for me However, I also encounter the error from torch._six import string_classes ModuleNotFoundError: No module named 'torch._six' Doing the following step is helpful for me: (reference https://github.com/pytorch/pytorch/pull/94709) from torch._six import string_classes -> delete this import and replace string_classes with str

ChiehYunChen avatar Apr 10 '23 16:04 ChiehYunChen

TLDR:

conda env create -f environment.yaml
conda activate ldm
pip install packaging==21.3
pip install 'torchmetrics<0.8'

Tried this but now I'm getting this error. This error occurs during Sampling Batches (unconditional): (DDIM Sampler & Plotting: Restored training weights runs successfully).

File "scripts/sample_diffusion.py", line 309, in run(model, imglogdir, eta=opt.eta, File "scripts/sample_diffusion.py", line 123, in run logs = make_convolutional_sample(model, batch_size=batch_size, File "/home/usama/.local/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "scripts/sample_diffusion.py", line 100, in make_convolutional_sample x_sample = model.decode_first_stage(sample) File "/home/usama/.local/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "/home/usama/usama/others/latent-diffusion/ldm/models/diffusion/ddpm.py", line 761, in decode_first_stage return self.first_stage_model.decode(z, force_not_quantize=predict_cids or force_not_quantize) File "/home/usama/usama/others/latent-diffusion/ldm/models/autoencoder.py", line 277, in decode quant, emb_loss, info = self.quantize(h) File "/home/usama/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/home/usama/usama/others/latent-diffusion/src/taming-transformers/taming/modules/vqvae/quantize.py", line 276, in forward z = rearrange(z, 'b c h w -> b h w c').contiguous() File "/home/usama/anaconda3/envs/latent-diff/lib/python3.8/site-packages/einops/einops.py", line 424, in rearrange return reduce(tensor, pattern, reduction='rearrange', **axes_lengths) File "/home/usama/anaconda3/envs/latent-diff/lib/python3.8/site-packages/einops/einops.py", line 368, in reduce return recipe.apply(tensor) File "/home/usama/anaconda3/envs/latent-diff/lib/python3.8/site-packages/einops/einops.py", line 203, in apply backend = get_backend(tensor) File "/home/usama/anaconda3/envs/latent-diff/lib/python3.8/site-packages/einops/_backends.py", line 49, in get_backend if backend.is_appropriate_type(tensor): File "/home/usama/anaconda3/envs/latent-diff/lib/python3.8/site-packages/einops/_backends.py", line 513, in is_appropriate_type return self.K.is_tensor(tensor) and self.K.is_keras_tensor(tensor) AttributeError: module 'keras.backend' has no attribute 'is_tensor'

usama-axcelerate avatar May 31 '23 16:05 usama-axcelerate

How do I just add this thread to my favourites? :D This is so unbelievable.

newbie-lad avatar Jun 28 '23 16:06 newbie-lad

TLDR:

conda env create -f environment.yaml
conda activate ldm
pip install packaging==21.3
pip install 'torchmetrics<0.8'
  • Perform pip install packaging==21.3 as mentioned by @Candysad to fix packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'.
  • Then comes to the second error ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data'. This is because torchmetrics removed get_num_classes from torchmetrics.utilities.data at version v0.8.0, so a quick fix can be pip install 'torchmetrics<0.8' to downgrade your torchmetrics version to 0.7.3

I followed exactly these steps, and got the following error:

ValueError: transformers.__spec__ is None

Has anyone also encountered this issue?

MikaYeghi avatar Feb 15 '24 19:02 MikaYeghi

TLDR:

conda env create -f environment.yaml
conda activate ldm
pip install packaging==21.3
pip install 'torchmetrics<0.8'
  • Perform pip install packaging==21.3 as mentioned by @Candysad to fix packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'.
  • Then comes to the second error ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data'. This is because torchmetrics removed get_num_classes from torchmetrics.utilities.data at version v0.8.0, so a quick fix can be pip install 'torchmetrics<0.8' to downgrade your torchmetrics version to 0.7.3

I followed exactly these steps, and got the following error:

ValueError: transformers.__spec__ is None

Has anyone also encountered this issue?

Updating transformers to 4.10.2 solved the issue for me.

mgheisar avatar Apr 05 '24 14:04 mgheisar

New TLDR: conda env create -f environment.yaml conda activate ldm pip install packaging==21.3 pip install 'torchmetrics<0.8' pip install transformers==4.10.2

Luh1124 avatar May 11 '24 04:05 Luh1124