I have recently configured a new Windows 11 (Pro) PC, that is quite powerful. For sure, it is more powerful than the old machine I had where I did not encounter the problem I am about to describe.
I installed miniconda, then created an environment shared several machine I have access to via a yaml file.
When I load torch within this environment for the first time, the loading takes approximately 1 minute to complete. Thinking it was due to this ai
env, I created another environment named torch
where I installed torch using the command on the homepage:
conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia
The following commands were executed within the same “Anaconda prompt” shell running within Windows Terminal.
(base) C:\Users\user>conda activate ai
(ai) C:\Users\user>python
Python 3.9.15 (main, Nov 24 2022, 14:39:17) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> timeit.timeit("import torch", number=1)
53.3811931
>>> timeit.timeit("import torch", number=1)
3.1999999947629476e-06
>>> exit()
(ai) C:\Users\user>python
Python 3.9.15 (main, Nov 24 2022, 14:39:17) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> timeit.timeit("import torch", number=1)
0.9886645000000005
(ai) C:\Users\user>conda deactivate
(base) C:\Users\user>conda activate torch
(torch) C:\Users\user>python
Python 3.9.15 (main, Nov 24 2022, 14:39:17) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> timeit.timeit("import torch", number=1)
21.7602496
>>> timeit.timeit("import torch", number=1)
2.8999999983625457e-06
>>>
As you can see, the first time I run import torch
it takes almost a minute, then, if I stay in the same environment, the loading is fast. If I change environment, the first loading is still slow.
If I open a new Anacoda prompt within the same Windows Terminal, the loading is fast (as here after the first load). If I close and re-open Windows Terminal, the loading is fast.
When I reboot the machine, I am back at the very slow loading.
I have found other questions here similar to mine, some answers suggested it could be related to the JIT compiler. None had a solution.
This Windows 11 Pro installation is fresh: there are only two environment ai
and the test one torch
. I have been using conda and pytorch for years and I have never had this problem.
Any suggestions on what to look at?