简体   繁体   中英

Why is torch.get_num_threads returning 1 despite setting it to NUM_THREADS =12

I am very new to using torch and I am trying to run a python script using torch. The block code is as follows:

torch.backends.cudnn.deterministic = False
torch.backends.cudnn.benchmark = True
# uniform thread number
torch.set_num_threads(NUM_THREADS)
print('THREADS: ',torch.get_num_threads())
assert NUM_THREADS == torch.get_num_threads(), torch.get_num_threads()# Code fails here

Here is my.env file:

CPU_NUM_THREADS=12
OMP_NUM_THREADS=12
OPENMP_NUM_THREADS=12
OPENBLAS_NUM_THREADS=12
MKL_NUM_THREADS=12
VECLIB_MAXIMUM_THREADS=12
NUMEXPR_NUM_THREADS=12

When I tried printing NUM_THREADS, it outputs 12 but when I print torch.get_num_threads, it outputs 1.

My System info:

3.1 GHz 6-Core Intel Core i5 MacOS.

I would like to know why is torch.get_num_threads() outputting 1 instead of 12 and how can I fix it?

Update: I updated my torch version from 1.5.0 to 1.7.1 and that resolved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM