Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
438 Views

ModuleNotFoundError: No module named 'torch'

please help getting this error while trying to run my python script in a job

Tags (1)
0 Kudos
5 Replies
Highlighted
Moderator
438 Views

Hi,

Thanks for reaching out to us.

Could you please clarify whether you are using custom environment or oneAPI environment?

if you are using oneAPI environment, please make sure that you activated the oneAPI environment using below command

source /opt/intel/inteloneapi/setvars.sh --force

If you are using custom environment, make sure you installed the PyTorch

Please find the below command to install PyTorch:

conda install pytorch torchvision cpuonly -c pytorch

If you are still facing the same issue, please  share more details about the workload and screenshot of the error.

Also share the job file if possible 

0 Kudos
Highlighted
Employee
438 Views

Actually, there's potentially a better way:

 

login-2:~
$ qsub -I
qsub: waiting for job 623886.v-qsvr-1.aidevcloud to start
qsub: job 623886.v-qsvr-1.aidevcloud ready


########################################################################
#      Date:           Fri Jun 12 08:22:30 PDT 2020
#    Job ID:           623886.v-qsvr-1.aidevcloud
#      User:           u25802
# Resources:           neednodes=1:batch:ppn=2,nodes=1:batch:ppn=2,walltime=06:00:00
########################################################################


s001-n009:~
$ conda info --envs
# conda environments:
#
base                  *  /glob/development-tools/versions/oneapi/beta06/inteloneapi/intelpython/latest
2021.1-beta06            /glob/development-tools/versions/oneapi/beta06/inteloneapi/intelpython/latest/envs/2021.1-beta06
pytorch                  /glob/development-tools/versions/oneapi/beta06/inteloneapi/intelpython/latest/envs/pytorch
pytorch-1.4.0            /glob/development-tools/versions/oneapi/beta06/inteloneapi/intelpython/latest/envs/pytorch-1.4.0
tensorflow               /glob/development-tools/versions/oneapi/beta06/inteloneapi/intelpython/latest/envs/tensorflow
tensorflow-2.1.0         /glob/development-tools/versions/oneapi/beta06/inteloneapi/intelpython/latest/envs/tensorflow-2.1.0


s001-n009:~
$ conda activate pytorch

(pytorch)
s001-n009:~

Please try this first. oneAPI AI Toolkit already provides PyTorch and TensorFlow based Conda environments and that might solve your problem.

Please let us know if this helped.

Thank you!

0 Kudos
Highlighted
Employee
438 Views

Some additional info.

There's a get started guide for Intel® AI Analytics Toolkit: https://devcloud.intel.com/oneapi/get-started/analytics-toolkit/

I didn't show you that the torch module is found after starting the existing conda pytorch environment:
 

s001-n009:~
$ conda activate pytorch

(pytorch)
s001-n009:~
$ which python
/glob/development-tools/versions/oneapi/beta06/inteloneapi/intelpython/latest/envs/pytorch/bin/python

(pytorch)
s001-n009:~
$ python
Python 3.7.7 (default, Apr 21 2020, 21:35:54)
[GCC 7.3.0] :: Intel(R) Corporation on linux
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import torch
>>>

I also have another recommendation that might help in the future.
Disable the following line in your ~/.bash_profile:

# Enable Intel tools
export PATH=/glob/intel-python/python3/bin/:/glob/intel-python/python2/bin/:${PATH}

This line is used to enable a previous versions of Intel® Distribution for Python*. Sometimes that leads to conflicts with the Intel® Distribution for Python* included in the Intel® oneAPI Base Toolkit.

0 Kudos
Highlighted
Moderator
438 Views

Hi,

Could you please confirm whether the solution provided was helpful?

 

Thanks

0 Kudos
Highlighted
Moderator
438 Views

Hi,

We are closing the case assuming the solution provided helps. Please feel free to raise a new thread for further issues.

 

Thanks

0 Kudos