Pytorch >= 2.1 is no more able to use my GPU :(

username: Dom83
cooked: <p>With all versions of PyTorch &gt;= 2.1 I have this error:<br>
<code>RuntimeError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check</code><br>
If I disable the check, it uses the CPU.</p>
<p>Older PyTorch 2.0.1 works perfectly on my system though, I still use it for the old version of ForgeUI. New versions of ForgeUI however need at least version 2.1 of PyTorch, else it says: <code>AttributeError: module 'torch' has no attribute 'float8_e4m3fn'</code>.</p>
<p>Can someone help, please?</p>
<p>Windows 7, Cuda11.4, RTX3060, Python 3.10.14</p>

username: ptrblck
cooked: <p>What does  <code>torch.__version__</code> and <code>torch.version.cuda</code> return?</p>

username: Dom83
cooked: <p>I can’t execute <code>torch.__version__</code> because <code>import torch</code> gives me an error about missing dependencies for c10_cuda.dll. <img src="https://discuss.pytorch.org/images/emoji/apple/frowning.png?v=12" title=":frowning:" class="emoji" alt=":frowning:" loading="lazy" width="20" height="20"></p>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<p>import torch<br>
Traceback (most recent call last):<br>
File “”, line 1, in <br>
File “D:\apps\stable-diffusion\Forge_20240811_121_21\system\python\lib\site-pa<br>
ckages\torch_<em>init</em>_.py”, line 139, in <br>
raise err<br>
OSError: [WinError 126] Le module spécifié est introuvable. Error loading “D:\ap<br>
ps\stable-diffusion\Forge_20240811_121_21\system\python\lib\site-packages\torch<br>
lib\c10_cuda.dll” or one of its dependencies.</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>

username: ptrblck
cooked: <p>In this case you might need to fix this error first, which seems to break your <code>import</code>.<br>
Based on your initial post I assume you are using some kind of wrapper and e.g. <a href="https://www.reddit.com/r/StableDiffusion/comments/1bpcthg/comfyui_error_loading_c10_cudadll_or_one_of_its/">this error</a> describes the same one caused by a specific workflow in <code>ComfyUI</code>.</p>

username: Dom83
cooked: <p>I don’t know how to fix this error though. <img src="https://discuss.pytorch.org/images/emoji/apple/frowning.png?v=12" title=":frowning:" class="emoji" alt=":frowning:" loading="lazy" width="20" height="20"><br>
According to Dependency Walker the missing dependencies of c10_cuda.dll are two dlls that don’t seem to exist for Windows 7 and functions missing in Windows dll like kernel32.dll and ieframe.dll.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/4/04a2ba1551179a486e3be8d329badf224dfa77ff.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/04a2ba1551179a486e3be8d329badf224dfa77ff" title="Dependency Walker c10_cuda.dll 20240827"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/4/04a2ba1551179a486e3be8d329badf224dfa77ff_2_690x133.jpeg" alt="Dependency Walker c10_cuda.dll 20240827" data-base62-sha1="F0y8CLz2p7bkluugXvF9nJSqrd" width="690" height="133" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/4/04a2ba1551179a486e3be8d329badf224dfa77ff_2_690x133.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/0/4/04a2ba1551179a486e3be8d329badf224dfa77ff.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/4/04a2ba1551179a486e3be8d329badf224dfa77ff.jpeg 2x" data-dominant-color="E8E3E3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Dependency Walker c10_cuda.dll 20240827</span><span class="informations">1020×198 127 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I do not use any function wrapper. I don’t know if Forge does.</p>
<p>I am the person in the link actually. I tried using the virtual environment from the older version of Forge or Automatic1111 but they give me this error: <code>AttributeError: module 'torch' has no attribute 'float8_e4m3fn'</code> which seemingly means that I need to update PyTorch to at least version 2.1, but when I do I always end up with the <code>Torch is not able to use GPU</code> error and missing dependencies for c10_cuda.dll.</p>

username: Dom83
cooked: <p>So, is pytorch just not compatible with Windows 7 anymore?</p>
<p><a href="https://pytorch.org/get-started/locally/#windows-prerequisites" rel="noopener nofollow ugc">The website</a> says <code>Windows 7 and greater</code> though.</p>

username: malfet
cooked: <p>According to <a href="https://learn.microsoft.com/en-us/troubleshoot/windows-client/windows-7-eos-faq/windows-7-end-support-faq-general" rel="noopener nofollow ugc">Microsoft web-site</a> Windows 7 have reached end of life in 2020 should have been updated. That said, I don’t think there is anything that blocks it from working on Windows 7, perhaps all you need to do is to update Visual Studio runtime (if I’m not mistaken, in 2.1 we’ve switch from VS2017 to VS2019 builds)</p>

username: Dom83
cooked: <p>Yeah we all sometimes have to keep running a somewhat obsolete software or hardware for compatibility reason and to avoid e-wasting a still perfectly running machine. However of course I understand that you may not want to spend time testing if your code is still compatible with an oldish OS that a small percentage of your users still use.</p>
<p>I did install/repair all Visual Studio redistribuables, including 2019. I made all OS updates available and I checked the integrity of my system files.</p>
<p>I don’t know if I can trust Dependency Walker (some people say it sometimes reports false positives) but it reports that c10_cuda.dll now needs the ResolveDelayLoadedAPI function which is missing from kernel32.dll. From what I read this function may be only available on Windows 8+. <img src="https://discuss.pytorch.org/images/emoji/apple/frowning.png?v=12" title=":frowning:" class="emoji" alt=":frowning:" loading="lazy" width="20" height="20"> This problem only happens with version 2.1 and above.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/1/c1e247cb5cd78b8ff8e0f6ba7069f2ab1bedd40d.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/c1e247cb5cd78b8ff8e0f6ba7069f2ab1bedd40d" title="Dependency Walker c10_cuda.dll kernel32"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/1/c1e247cb5cd78b8ff8e0f6ba7069f2ab1bedd40d_2_690x449.jpeg" alt="Dependency Walker c10_cuda.dll kernel32" data-base62-sha1="rFaXeCSDrDwLXLDl6KazT70ckYR" width="690" height="449" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/1/c1e247cb5cd78b8ff8e0f6ba7069f2ab1bedd40d_2_690x449.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/c/1/c1e247cb5cd78b8ff8e0f6ba7069f2ab1bedd40d_2_1035x673.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/c/1/c1e247cb5cd78b8ff8e0f6ba7069f2ab1bedd40d.jpeg 2x" data-dominant-color="E4E4E5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Dependency Walker c10_cuda.dll kernel32</span><span class="informations">1250×814 197 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>It also reports these two modules missing from c10.dll:</p>
<pre><code class="lang-auto">??0Warning@c10@@QEAA@V?$variant@VUserWarning@Warning@c10@@VDeprecationWarning@23@@1@AEBUSourceLocation@1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z

??0Warning@c10@@QEAA@V?$variant@VUserWarning@Warning@c10@@VDeprecationWarning@23@@1@USourceLocation@1@PEBD_N@Z
</code></pre>

username: Dom83
cooked: <aside class="quote no-group" data-username="malfet" data-post="7" data-topic="208672">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/malfet/48/27485_2.png" class="avatar"> malfet:</div>
<blockquote>
<p>if I’m not mistaken, in 2.1 we’ve switch from VS2017 to VS2019 builds</p>
</blockquote>
</aside>
<p>I did install VS runtime 2019 but it did not solve the problem. <img src="https://discuss.pytorch.org/images/emoji/apple/frowning.png?v=12" title=":frowning:" class="emoji" alt=":frowning:" loading="lazy" width="20" height="20"><br>
Is there a version of pytorch 2.1 build with VS2017 instead that I could try, to tell if this is what caused the problem?</p>

username: Dom83
cooked: <p>It was indeed an incompatibility with Windows 7.<br>
If someone ever has the same problem, here is how I fixed it:</p>
<p>Don’t replace the embed python with pythonwin7, it’s not necessary. Don’t replace any dll either.<br>
If you copied “api-ms-win-security-systemfunctions-l1-1-0.dll” to “system32”, remove it.</p>
<p>Install VxKex (the original repo is dead, I don’t know which new source is safe to download it from: <a href="https://github.com/i486/VxKex" rel="noopener nofollow ugc">i486/VxKex</a> / <a href="https://github.com/Blaukovitch/VxKex" rel="noopener nofollow ugc">Blaukovitch/VxKex</a>)<br>
In VxKex settings, add Forge’s “system/python/python.exe”</p>
<p>Uninstall pytorch and reinstall a compatible version, without torchaudio.</p>
<pre><code class="lang-auto">python -m pip uninstall Torch Torchvision Torchaudio
python -m pip install torch==2.4.0 torchvision==0.19.0 --index-url https://download.pytorch.org/whl/cu118
</code></pre>
<p>“LIBOMP140.X86_64.DLL” will be missing, it’s a known bug for pytorch 2.4.0. Download it, unzip and copy the dll in system32.<br>
<a href="https://www.dllme.com/dll/files/libomp140_x86_64/00637fe34a6043031c9ae4c6cf0a891d" rel="noopener nofollow ugc">https://www.dllme.com/dll/files/libomp140_x86_64/00637fe34a6043031c9ae4c6cf0a891d</a></p>
<p>Voila.</p>