2

I've been tackling python and torch specifically lately as a hobby, and, while some API works, I keep getting invalid stoi argument exception with other very basic API torch provides.

Reproduced with the code below:

import torch
torch.cuda.is_available()
torch.cuda.current_device()

First call (is_available()) works as expected and returns True, but the second throws an exception:

Exception has occurred: RuntimeError
invalid stoi argument
  File "C:\DEV\pthon_test\torch_test.py", line 5, in <module>
    torch.cuda.current_device()

Needless to say, more complicated things (for example, running stable_diffusion_webui) fail if used with GPU (said webui works with CPU), and trying to dig deeper into the code brings me to the same exception.

OS is Windows 11, python Python 3.10.8, torch version checked with torch.__version__ returns 1.12.1+cu113. And, well, GPU is present

List of packages installed:

❯ pip list
Package                 Version
----------------------- ---------------
absl-py                 1.3.0
addict                  2.4.0
antlr4-python3-runtime  4.9.3
basicsr                 1.4.2
beautifulsoup4          4.11.1
cachetools              5.2.0
certifi                 2022.9.24
charset-normalizer      2.1.1
clip                    1.0
colorama                0.4.6
contourpy               1.0.6
cycler                  0.11.0
einops                  0.4.1
facexlib                0.2.5
ffmpy                   0.3.0
filelock                3.8.0
filterpy                1.4.5
font-roboto             0.0.1
fonts                   0.0.3
fonttools               4.38.0
ftfy                    6.1.1
future                  0.18.2
gdown                   4.5.3
gfpgan                  1.3.5
google-auth             2.14.0
google-auth-oauthlib    0.4.6
grpcio                  1.50.0
idna                    3.4
imageio                 2.22.3
kiwisolver              1.4.4
lark                    1.1.2
llvmlite                0.39.1
lmdb                    1.3.0
lpips                   0.1.4
Markdown                3.4.1
MarkupSafe              2.1.1
matplotlib              3.6.2
networkx                2.8.8
numba                   0.56.3
numpy                   1.23.3
oauthlib                3.2.2
omegaconf               2.2.3
opencv-python           4.6.0.66
orjson                  3.8.1
packaging               21.3
piexif                  1.1.3
Pillow                  9.2.0
pip                     22.2.2
protobuf                3.19.6
pyasn1                  0.4.8
pyasn1-modules          0.2.8
pycparser               2.21
pycryptodome            3.15.0
pydantic                1.10.2
pyDeprecate             0.3.2
pydub                   0.25.1
pyparsing               3.0.9
pyrsistent              0.19.2
PySocks                 1.7.1
python-dateutil         2.8.2
python-multipart        0.0.4
pytz                    2022.6
PyWavelets              1.4.1
PyYAML                  6.0
regex                   2022.10.31
requests                2.28.1
requests-oauthlib       1.3.1
resize-right            0.0.2
rfc3986                 1.5.0
rsa                     4.9
scikit-image            0.19.3
scipy                   1.9.3
setuptools              63.2.0
six                     1.16.0
sniffio                 1.3.0
soupsieve               2.3.2.post1
tb-nightly              2.11.0a20221103
tensorboard-data-server 0.6.1
tensorboard-plugin-wit  1.8.1
tifffile                2022.10.10
tokenizers              0.12.1
torch                   1.12.1+cu113
torchvision             0.13.1+cu113
tqdm                    4.64.1
typing_extensions       4.4.0
uc-micro-py             1.0.1
urllib3                 1.26.12
wcwidth                 0.2.5
websockets              10.4
Werkzeug                2.2.2
wheel                   0.37.1
yapf                    0.32.0
zipp                    3.10.0

This brings me to two questions:

  1. What's causing the issue? I do have a rough understanding of the c++ meaning of the error, but not sure why I'm getting this on python
  2. Is there anything I can do to fix the problem?

Thanks

Dmitrii Chichuk
  • 674
  • 7
  • 15
  • Do you have any other packages installed that require cuda? The only thing I could find in the direction of `stoi` was [this](https://torchmetrics.readthedocs.io/en/stable/audio/short_time_objective_intelligibility.html). Furthermore, note that the official [PyTorch documentation](https://pytorch.org/get-started/locally/) only supports PyTorch on Windows for Python versions 3.7-3.9. – BlackCat Nov 13 '22 at 11:53
  • Added a list of installed packages. As for version - webui repo states that it has to be 3.10, but I'll check if 3.9 gives a different result, and update the question & comment. Thanks for the input though o7 Article is a good read, gave me a bit more insight – Dmitrii Chichuk Nov 13 '22 at 18:58
  • Tried version 3.9 of python - same result. I was wondering if it's because how cuda installed? Maybe some extra steps are required? (I just installed the installer I got from nvidia site), although I can't see anything I could've possibly do wrong – Dmitrii Chichuk Nov 14 '22 at 04:39
  • What you could do is try Python 3.9 with only `torch` as a dependency, at least then you can specifically say it is `torch` that raises the error. What I also found is [this](https://stackoverflow.com/questions/19478687/no-member-named-stoi-in-namespace-std), so make sure that your C++ compiler supports C++ 11 otherwise this could result in the error. – BlackCat Nov 14 '22 at 07:53
  • As for c++ stoi (string-to-integer), that probably goes for self-compiled python enterpreter (or engine, w\e it's called), which I'm not really trying to do (just using the installer shipped on python website). As for torch stoi - still not sure how to deal with it, and it seems it doesn't really have anything to do with C++( As for "only torch as a dependency", well, I did that - problem is still there, so im still stuck, unfortunately – Dmitrii Chichuk Nov 14 '22 at 16:54

1 Answers1

0

As there is no other answers, and initial problem seem to have been solved, I thought I'd share some information.

I've noticed the problem was fixed when... I updated my Nvidia driver. No idea what was the problem, and if there's anything else I unknowingly did, but updating to 526.98 did the trick for me.

If there's anyone else to share more details on the original issue, or possible solutions - feel free to edit or give a better answer, I'd mark that as the best option instead.

Have a nice day o/

Dmitrii Chichuk
  • 674
  • 7
  • 15