Deci-AI / super-gradients

Easily train or fine-tune SOTA computer vision models with one open source training library. The home of Yolo-NAS.
https://www.supergradients.com
Apache License 2.0
4.53k stars 490 forks source link

Failed to import pytorch_quantization #996

Closed mriamnobody closed 1 year ago

mriamnobody commented 1 year ago

I have used to following code for testing (available in documentation):

import super_gradients

yolo_nas = super_gradients.training.models.get("yolo_nas_l", pretrained_weights="coco").cuda()
yolo_nas.predict("https://deci-pretrained-models.s3.amazonaws.com/sample_images/beatles-abbeyroad.jpg").show()

but I received the following error:

The console stream is logged into /home/ethan/sg_logs/console.log
[2023-05-14 13:39:15] INFO - crash_tips_setup.py - Crash tips is enabled. You can set your environment variable to CRASH_HANDLER=FALSE to disable it
[2023-05-14 13:39:32] WARNING - __init__.py - Failed to import pytorch_quantization
[2023-05-14 13:39:32] WARNING - calibrator.py - Failed to import pytorch_quantization
[2023-05-14 13:39:32] WARNING - export.py - Failed to import pytorch_quantization
[2023-05-14 13:39:32] WARNING - selective_quantization_utils.py - Failed to import pytorch_quantization
[2023-05-14 13:39:33] INFO - checkpoint_utils.py - License Notification: YOLO-NAS pre-trained weights are subjected to the specific license terms and conditions detailed in
https://github.com/Deci-AI/super-gradients/blob/master/LICENSE.YOLONAS.md
By downloading the pre-trained weight files you agree to comply with these terms.
Could not load library libcudnn_cnn_infer.so.8. Error: libcuda.so: cannot open shared object file: No such file or directory
Aborted

Environment:

dagshub[bot] commented 1 year ago

Join the discussion on DagsHub!

Louis-Dupont commented 1 year ago

Hi @mriamnobody It seems to be related to cudnn and not SuperGradients. You can check out the following resources, it might help you;

mriamnobody commented 1 year ago

Thank you @Louis-Dupont for providing the links/source to resolve an issue which is not related to super-gradients. I tried to perform the steps mentioned in the StackOverflow link and it got rid of the error Could not load library libcudnn_cnn_infer.so.8. Error: libcuda.so: cannot open shared object file: No such file or directory Aborted the following errors were still present:

[2023-05-15 06:43:25] WARNING - __init__.py - Failed to import pytorch_quantization
[2023-05-15 06:43:25] WARNING - calibrator.py - Failed to import pytorch_quantization
[2023-05-15 06:43:25] WARNING - export.py - Failed to import pytorch_quantization
[2023-05-15 06:43:25] WARNING - selective_quantization_utils.py - Failed to import pytorch_quantization

So did some searching on internet and found that two more modules need to be installed: nvidia-pyindex and pytorch-quantization. For anyone in future gets this issue, you first need to install the nvidia-pyindex and then pytorch-quantization else if you try to install pytorch-quantization first and then nvidia-pyindex you will the following error:

Collecting pytorch-quantization
  Downloading pytorch-quantization-0.0.1.dev5.tar.gz (7.9 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [17 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-t9i6zekc/pytorch-quantization_9cb4035ffda345a7959b12c1917f5e0c/setup.py", line 150, in <module>
          raise RuntimeError(open("ERROR.txt", "r").read())
      RuntimeError:
      ###########################################################################################
      The package you are trying to install is only a placeholder project on PyPI.org repository.
      This package is hosted on NVIDIA Python Package Index.

      This package can be installed as:
  $ pip install nvidia-pyindex
  $ pip install pytorch-quantization
  ```
  ###########################################################################################

  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed

× Encountered error while generating package metadata. ╰─> See above for output.

note: This is an issue with the package mentioned above, not pip. hint: See above for details.

mriamnobody commented 1 year ago

@Louis-Dupont I have still one query related to this problem after performing the steps unnecessary to resolve the issue I'm facing what shall be the output of this code:

import super_gradients

yolo_nas = super_gradients.training.models.get("yolo_nas_l", pretrained_weights="coco").cuda()
yolo_nas.predict("https://deci-pretrained-models.s3.amazonaws.com/sample_images/beatles-abbeyroad.jpg").show()

When the above code is run I only get the following on terminal:

The console stream is logged into /home/ethan/sg_logs/console.log
[2023-05-15 06:49:10] INFO - crash_tips_setup.py - Crash tips is enabled. You can set your environment variable to CRASH_HANDLER=FALSE to disable it

and it takes close to 25 seconds for the script to complete. Also, the load on GPU fluctuates from 10% to 100% while the script is running. Am I missing something?

Louis-Dupont commented 1 year ago

Is this all the logs you had in the terminal? Because if its the first time you run, it makes sense it would take more time because it downloads the model, but you should have logs like:

image

Try rerunning it again after the model is downloaded it should be way faster.

mriamnobody commented 1 year ago

Thanks for your reply @Louis-Dupont. Nothing is being displayed on my terminal except the text which I shared in my last comment. No model download progress bar nothing. I have attached a screenshot for your reference.

mriamnobody commented 1 year ago
Screenshot (2331)

@Louis-Dupont

Louis-Dupont commented 1 year ago

Let's see what takes time.

import time
import torch

start_predict = time.perf_counter()

from super_gradients.common.object_names import Models
from super_gradients.training import models

post_import_time = time.perf_counter()
print("Loading SG: ", post_import_time - start_predict)

# Note that currently only YoloX, PPYoloE and YOLO-NAS are supported.
model = models.get(Models.YOLO_NAS_L, pretrained_weights="coco")

# We want to use cuda if available to speed up inference.
model = model.to("cuda" if torch.cuda.is_available() else "cpu")

post_model_time = time.perf_counter()
print("Loading Model: ", post_model_time - post_import_time)

images_predictions = model.predict(
    "../../../../documentation/source/images/examples/pose_elephant_flip.gif",
)

post_predict_time = time.perf_counter()
print("Predict: ", post_predict_time - post_model_time)
mriamnobody commented 1 year ago

@Louis-Dupont, Below are the results of three consecutive runs. The script took close to 45 seconds to complete its execution. I have attached the console image for your reference.

Screenshot (2333)