Torch.get_num_threads() gives half the number of threads

Hi All,

I’ve been trying to use PyTorch’s cpu threading capabilities and I’ve noticed that PyTorch’s command torch.get_num_threads only returns half the number of threads. I’m currently working on a computer with 12 threads but torch.get_num_threads returns 6. Is there any reason for this?

If I run lscpu I get the following information

CPU(s):              12
On-line CPU(s) list: 0-11
Thread(s) per core:  2
Core(s) per socket:  6
Socket(s):           1

Is it perhaps returning the number of cores instead? (for some reason)? I’m using PyTorch 1.6.

Thanks in advance! :slight_smile:


It returns the number of thread that can be used to perform multithreading (note that you can change that value if you want).
We don’t put it too high by default to avoid over-subscription that is very detrimental in terms of runtime. But this value will need to be tuned if you want to get the best performances out of your system for sure.



Thanks for the explanation! :smiley: