super-gradients icon indicating copy to clipboard operation
super-gradients copied to clipboard

collection.Iterable is deprecated in Python 3.9+

Open thangngoc89 opened this issue 1 year ago • 12 comments

🐛 Describe the bug

Any code path that touch this particular line of code (for example trainer.qat)

https://github.com/Deci-AI/super-gradients/blob/7907c486d1a0bb479c68590ffd5bc8478f9f18b8/src/super_gradients/training/utils/utils.py#L595

On Python 3.9+, this will have this error

AttributeError: module 'collections' has no attribute 'Iterable'

See this SO answer: https://stackoverflow.com/a/72032097

Versions

Collecting environment information... PyTorch version: 1.11.0+cu102 Is debug build: False CUDA used to build PyTorch: 10.2 ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64) GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 Clang version: Could not collect CMake version: Could not collect Libc version: glibc-2.27

Python version: 3.10.11 (main, Apr 20 2023, 19:02:41) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-4.4.0-143-generic-x86_64-with-glibc2.27 Is CUDA available: True CUDA runtime version: 11.8.89 CUDA_MODULE_LOADING set to: GPU models and configuration: GPU 0: Tesla T4 Nvidia driver version: 525.105.17 cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5 HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 16 On-line CPU(s) list: 0-15 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 16 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 79 Model name: Intel(R) Xeon(R) Platinum 8260M CPU @ 2.40GHz Stepping: 0 CPU MHz: 2400.000 BogoMIPS: 4800.00 L1d cache: 32K L1i cache: 32K L2 cache: 1024K L3 cache: 36608K NUMA node0 CPU(s): 0-15 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch invpcid_single kaiser fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt arat

Versions of relevant libraries: [pip3] numpy==1.23.0 [pip3] pytorch-quantization==2.1.2 [pip3] torch==1.11.0 [pip3] torchmetrics==0.8.0 [pip3] torchvision==0.12.0 [conda] numpy 1.23.0 pypi_0 pypi [conda] pytorch-quantization 2.1.2 pypi_0 pypi [conda] torch 1.11.0 pypi_0 pypi [conda] torchmetrics 0.8.0 pypi_0 pypi [conda] torchvision 0.12.0 pypi_0 pypi

thangngoc89 avatar Jun 02 '23 11:06 thangngoc89

This indeed a bug. On 3.9 it raises a warning, on 3.10 it fails with an ImportError. However the solution is quite simple: collections.Iterable -> typing.Iterable should do the work. Are you interested in making a PR with a fix? Should be a straightforward fix if you master the signed commits.

BloodAxe avatar Jun 02 '23 12:06 BloodAxe

@BloodAxe sure. Thank you for confirming this quickly. I will send a PR tonight

thangngoc89 avatar Jun 02 '23 13:06 thangngoc89

this PR has been merged?

skyprince999 avatar Jun 11 '23 16:06 skyprince999

@skyprince999 sorry. I have loss interests in using yolonas because of the hops I have jumped through to getting started. I tried yolov8 and it’s good enough for my use case

thangngoc89 avatar Jun 11 '23 17:06 thangngoc89

This indeed a bug. On 3.9 it raises a warning, on 3.10 it fails with an ImportError. However the solution is quite simple: collections.Iterable -> typing.Iterable should do the work. Are you interested in making a PR with a fix? Should be a straightforward fix if you master the signed commits.

@BloodAxe Hi, I tried collections.Iterable -> typing.Iterable but it not work I tried collections.Iterable -> collections.abc.Iterable then it work if isinstance(inputs, collections.abc.Iterable) and not isinstance(inputs, str)

DoManhQuang avatar Jun 15 '23 08:06 DoManhQuang

This indeed a bug. On 3.9 it raises a warning, on 3.10 it fails with an ImportError. However the solution is quite simple: collections.Iterable -> typing.Iterable should do the work. Are you interested in making a PR with a fix? Should be a straightforward fix if you master the signed commits.

@BloodAxe Hi, I tried collections.Iterable -> typing.Iterable but it not work I tried collections.Iterable -> collections.abc.Iterable then it work if isinstance(inputs, collections.abc.Iterable) and not isinstance(inputs, str)

typing is imported at the start of the file, from typing import XXXX,XXXx, Iterable

so you need to change it to Iterable

skyprince999 avatar Jun 15 '23 09:06 skyprince999

@DoManhQuang Can you please elaborate what error do you get for typing.Iterable and what python version did you test on?

BloodAxe avatar Jun 15 '23 09:06 BloodAxe

Yes, I imported typing and change collections.Iterable -> typing.Iterable and it not work. Now, try again then typing.Iterable is working. I can't reproduce the issue :( Env: Colab, python 3.10.12

DoManhQuang avatar Jun 15 '23 09:06 DoManhQuang

How to solve this problem on Kaggle, where we do not have access to the library to edit it?

ferdzo avatar Jun 15 '23 22:06 ferdzo

@ferdzo Hi, you can try my way: 1/ git clone https://github.com/Deci-AI/super-gradients.git

2/ change collections.Iterable =>typing.Iterable or collections.abc.Iterable from https://github.com/Deci-AI/super-gradients/blob/7907c486d1a0bb479c68590ffd5bc8478f9f18b8/src/super_gradients/training/utils/utils.py#L595

3/ pip install -r ./super-gradients/requirements.dev.txt

4/ pip install ./super-gradients

DoManhQuang avatar Jun 16 '23 04:06 DoManhQuang

It is fixed in master already: https://github.com/Deci-AI/super-gradients/pull/1178 You can expect the next version to be available soon. Meanwhile you can install SG from master: pip install git+https://github.com/Deci-AI/super-gradients.git

BloodAxe avatar Jun 16 '23 07:06 BloodAxe

@ferdzo Hi, you can try my way: 1/ git clone Deci-AI/super-gradients.git

2/ change collections.Iterable =>typing.Iterable or collections.abc.Iterable from

https://github.com/Deci-AI/super-gradients/blob/7907c486d1a0bb479c68590ffd5bc8478f9f18b8/src/super_gradients/training/utils/utils.py#L595

3/ pip install -r ./super-gradients/requirements.dev.txt

4/ pip install ./super-gradients

Well, I've fixed it on my computer and on Colab, because I can access the library and edit it, too much gymnastics to fix it on Kaggle, thanks anyway!

ferdzo avatar Jun 16 '23 09:06 ferdzo

Fixed in 3.1.2

BloodAxe avatar Aug 10 '23 13:08 BloodAxe