CUDA error (3): initialization error while using img.cuda()

Getting this error in Flask + nginx + uwsgi , but works fine in gunicorn before.

Error msg:

Traceback (most recent call last):
  File "/home/AiServer/env/lib/python3.5/site-packages/flask/", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/AiServer/env/lib/python3.5/site-packages/flask/", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/AiServer/env/lib/python3.5/site-packages/flask/", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/AiServer/env/lib/python3.5/site-packages/flask/", line 35, in reraise
    raise value
  File "/home/AiServer/env/lib/python3.5/site-packages/flask/", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/AiServer/env/lib/python3.5/site-packages/flask/", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "./", line 717, in cate_reco
    img_tensor = image_loader(img_pil)
  File "./", line 322, in image_loader
    if cuda: return image.cuda()  # assumes that you're using GPU
RuntimeError: cuda runtime error (3) : initialization error at /pytorch/aten/src/THC/THCCachingAllocator.cpp:507

Is it the uwsgi configuration issue? I wonder if you could help me with this.thx

Got it , it is the uwsgi configuration issue , when i remove master = true , the error is gone

# master = true

Can you please share your configuration file @Rokuki since I am also facing the same issue .
Tried commenting master = true and no of workers and threads set to default and OMP_NUM_THREADS=2 and 1.