CAIC-AD/YOLOPv2

Cannot run `demo.py` because of invalid torch&torchvision specification

Closed this issue · 2 comments

issue

I have tried to setup the environment via docker as follows;

FROM pytorch/pytorch:1.7.0-cuda11.0-cudnn8-runtime

COPY requirements.txt ./
RUN pip install -r requirements.txt
# install opencv dependencies, which must be done in a container because its installation requires interactive installation settings 
apt update && apt install -y libopencv-dev

and then I tried to run demo.py and got the following error;

python demo.py --source data/example.jpg

/opt/conda/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: /opt/conda/lib/python3.8/site-packages/torchvision/image.so: undefined symbol: _ZN3c104cuda20getCurrentCUDAStreamEa
  warn(f"Failed to load image Python extension: {e}")
Traceback (most recent call last):
  File "demo.py", line 8, in <module>
    from utils.utils import \
  File "/root/workspace/utils/utils.py", line 14, in <module>
    import torchvision
  File "/opt/conda/lib/python3.8/site-packages/torchvision/__init__.py", line 7, in <module>
    from torchvision import models
  File "/opt/conda/lib/python3.8/site-packages/torchvision/models/__init__.py", line 2, in <module>
    from .convnext import *
  File "/opt/conda/lib/python3.8/site-packages/torchvision/models/convnext.py", line 8, in <module>
    from ..ops.misc import Conv2dNormActivation, Permute
  File "/opt/conda/lib/python3.8/site-packages/torchvision/ops/__init__.py", line 18, in <module>
    from .drop_block import drop_block2d, DropBlock2d, drop_block3d, DropBlock3d
  File "/opt/conda/lib/python3.8/site-packages/torchvision/ops/drop_block.py", line 2, in <module>
    import torch.fx
ModuleNotFoundError: No module named 'torch.fx'

I think this error is raised because of invalid version of torchvision. In requirements.txt, torchvision>=0.8.1,!=0.13.0 is specified. This setting will install the latest torchvision, torchvision==0.13.1, and it raises the error. In actual, the installed version of torchvision is 0.13.1;

pip list | grep torchvision

torchvision             0.13.1

How to solve this issue

Modifying the version specification of torch & torchvision will solve the error;

torch==1.7.1
torchvision==0.8.2
I found an error with `torch==1.7.0` and `torchvision==0.8.1`. And I also found `torch==1.7.1` & `torchvision==0.8.2` solved the error. This is the error log I met.
root@0b96290448a1:~/workspace# python demo.py --source data/example.jpg
Namespace(agnostic_nms=False, classes=None, conf_thres=0.3, device='0', exist_ok=False, img_size=640, iou_thres=0.45, name='exp', nosave=False, project='runs/detect', save_conf=False, save_txt=False, source='data/20220801150356A_0g00.mp4', weights='data/weights/yolopv2.pt')
video 1/1 (1/1680) /root/workspace/data/20220801150356A_0g00.mp4: Traceback (most recent call last):
  File "demo.py", line 161, in <module>
    detect()
  File "demo.py", line 77, in detect
    [pred,anchor_grid],seg,ll= model(img)
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
RuntimeError: nvrtc: error: invalid value for --gpu-architecture (-arch)

nvrtc compilation failed:

#define NAN __int_as_float(0x7fffffff)
#define POS_INFINITY __int_as_float(0x7f800000)
#define NEG_INFINITY __int_as_float(0xff800000)


template<typename T>
__device__ T maximum(T a, T b) {
  return isnan(a) ? a : (a > b ? a : b);
}

template<typename T>
__device__ T minimum(T a, T b) {
  return isnan(a) ? a : (a < b ? a : b);
}


#define __HALF_TO_US(var) *(reinterpret_cast<unsigned short *>(&(var)))
#define __HALF_TO_CUS(var) *(reinterpret_cast<const unsigned short *>(&(var)))
#if defined(__cplusplus)
  struct __align__(2) __half {
    __host__ __device__ __half() { }

  protected:
    unsigned short __x;
  };

  /* All intrinsic functions are only available to nvcc compilers */
  #if defined(__CUDACC__)
    /* Definitions of intrinsics */
    __device__ __half __float2half(const float f) {
      __half val;
      asm("{  cvt.rn.f16.f32 %0, %1;}\n" : "=h"(__HALF_TO_US(val)) : "f"(f));
      return val;
    }

    __device__ float __half2float(const __half h) {
      float val;
      asm("{  cvt.f32.f16 %0, %1;}\n" : "=f"(val) : "h"(__HALF_TO_CUS(h)));
      return val;
    }

  #endif /* defined(__CUDACC__) */
#endif /* defined(__cplusplus) */
#undef __HALF_TO_US
#undef __HALF_TO_CUS

typedef __half half;

extern "C" __global__
void func_1(half* t0, half* t1, half* t2, half* t3, half* t4, half* t5, half* t6, half* t7, half* aten_cat_flat, half* aten_cat_flat_1) {
{
  aten_cat_flat[512 * blockIdx.x + threadIdx.x] = __float2half((((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048<1536 ? 1 : 0) ? (((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048<1024 ? 1 : 0) ? (((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048<768 ? 1 : 0) ? (((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048<512 ? 1 : 0) ? (((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048<256 ? 1 : 0) ? __half2float(t0[(20 * (((512 * blockIdx.x + threadIdx.x) / 20) % 20) + (512 * blockIdx.x + threadIdx.x) % 20) + 400 * ((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048)]) : __half2float(t1[((20 * (((512 * blockIdx.x + threadIdx.x) / 20) % 20) + (512 * blockIdx.x + threadIdx.x) % 20) + 400 * ((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048)) - 102400])) : __half2float(t2[((20 * (((512 * blockIdx.x + threadIdx.x) / 20) % 20) + (512 * blockIdx.x + threadIdx.x) % 20) + 400 * ((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048)) - 204800])) : __half2float(t3[((20 * (((512 * blockIdx.x + threadIdx.x) / 20) % 20) + (512 * blockIdx.x + threadIdx.x) % 20) + 400 * ((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048)) - 307200])) : __half2float(t4[((20 * (((512 * blockIdx.x + threadIdx.x) / 20) % 20) + (512 * blockIdx.x + threadIdx.x) % 20) + 400 * ((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048)) - 409600])) : __half2float(t5[((20 * (((512 * blockIdx.x + threadIdx.x) / 20) % 20) + (512 * blockIdx.x + threadIdx.x) % 20) + 400 * ((((512 * blockIdx.x + threadIdx.x) / 20) / 20) % 2048)) - 614400])));
  aten_cat_flat_1[512 * blockIdx.x + threadIdx.x] = __float2half((((((512 * blockIdx.x + threadIdx.x) / 80) / 80) % 128<64 ? 1 : 0) ? __half2float(t6[((512 * blockIdx.x + threadIdx.x) % 80 + 6400 * ((((512 * blockIdx.x + threadIdx.x) / 80) / 80) % 128)) + 80 * (((512 * blockIdx.x + threadIdx.x) / 80) % 80)]) : __half2float(t7[(((512 * blockIdx.x + threadIdx.x) % 80 + 6400 * ((((512 * blockIdx.x + threadIdx.x) / 80) / 80) % 128)) + 80 * (((512 * blockIdx.x + threadIdx.x) / 80) % 80)) - 409600])));
}
}
sgzqc commented

hi , thanks for your reply. For torch==1.7.0 , the corresponding torchvision is torchvision==0.8.0 ; and for torch==1.7.1 , the corresponding torchvision is torchvision==0.8.2 ; And we have changed the requirement.txt . Thanks again !

Thank you for updating requirements.txt!