mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Passing PYTHONPATH to worker nodes in distributed training

Open rahul003 opened this issue 9 years ago • 4 comments

Environment info

Operating System: Ubuntu 16.04 Compiler: gcc5.x Package used: Python MXNet version: master MXNet commit hash (git rev-parse HEAD): 9d24cfd71f14d719a67c903204d866f15e6848fc Python version and distribution: python2.7

Issue:

When launch.py launcher script launches a job, it doesn't respect the PYTHONPATH variable set on the master or on a worker. I was trying to use mxnet python files installed at a custom location. Despite setting PYTHONPATH variables on master and worker, it wasn't used. It still used the default python library location. I verified the version of MXNet used by printing the module.

Steps to reproduce

Let's say we have an Ubuntu cluster. We have our python package of mxnet installed without pip. So it is in a custom location. We then put this on PYTHONPATH. Repeat this for all instances on the cluster. Suppose there's a simple script test.py which includes two lines.

import mxnet
print mxnet

This should give the location of mxnet python packages being imported.

Running this locally works as expected, because PYTHONPATH is set in .bashrc or exported to the bash session. Run this same script with launch.py, on all instances in the cluster. Each of them uses the version of mxnet installed in default site-packages location which pip uses, or fails to import if that location doesn't have mxnet.

What have you tried to solve it?

  1. I tried setting PYTHONPATH manually in both worker and master nodes.
  2. I tried explicitly giving PYTHONPATH while running the launch.py script
  3. I have verified that ssh.py which launches the command on nodes doesn't pass the environment variable PYTHONPATH. It only passes the variables 'OMP_NUM_THREADS', 'KMP_AFFINITY', 'LD_LIBRARY_PATH', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'DMLC_INTERFACE'. See code here
  4. When a command is launched over ssh, it doesn't involve the shell. So it doesn't use the environment variables. I believe we should pass environment variables like PYTHONPATH explicitly as done above. Or if you think there's a better way to do this, let's discuss.

Possible solution

[Described above in more detail, in case you skipped over to this] Add PYTHONPATH to the list of variables in dmlc_tracker/ssh.py. I've verified that this works. Should I send a PR for that?

rahul003 avatar Sep 12 '17 07:09 rahul003

if you run sudo python setup.py install to install MXNet for all machines in the cluster, it will find the default version you install. I do agree that if such env var can be set at runtime, that will be great.

eric-haibin-lin avatar Sep 12 '17 16:09 eric-haibin-lin

Please also check if any other env vars used by MXNet need to be added.

bhavinthaker avatar Sep 12 '17 17:09 bhavinthaker

Created a PR which supports passing any user specified environment variable.

https://github.com/apache/incubator-mxnet/pull/8507

rahul003 avatar Nov 01 '17 18:11 rahul003

@apache/mxnet-committers: This issue has been inactive for the past 90 days. It has no label and needs triage.

For general "how-to" questions, our user forum (and Chinese version) is a good place to get help.

szha avatar Feb 01 '18 00:02 szha