question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

distributed.joblib do not runs while joblib does or How to execute an arbitrary code on the worker right before sending him a taks for deserialization?

See original GitHub issue

I’ve found that ipyparallel’s

dview.execute('import sys; sys.path.append("/shared/dir/with/source/code")')

and similar hacks using execute are quite helpful to setup environment before sending a task. This way things like deserialization won’t be messed up and will, probably, do the right thing.

Currently I’m dealing with a simple joblib program:

nloops=5
wavelet = makeRicker(nt=1024,dt=0.004,f=30)
pinv = [Perturb(nt=1024,dt=0.004,nOffsets=256,dx=25,motionType=2,srcDepth=10,rvrDepth=10) for m in range(nloops)]
misfit=np.zeros(nm)

with parallel_backend('dask.distributed', scheduler_host='scheduler:8786'):
    pmisfit = Parallel(n_jobs=-1)(map(delayed(superf), range(nloops)))

So when I run it I get this:

/dist/anaconda/lib/python2.7/site-packages/distributed/protocol/pickle.pyc in loads()
     57 def loads(x):
     58     try:
---> 59         return pickle.loads(x)
     60     except Exception:
     61         logger.info("Failed to deserialize %s", x[:10000], exc_info=True)

ImportError: No module named spie1d

Missing module is in that /shared/dir/with/source/code and appears in superf cause it using pinv and wavelet global variables.

The very same example with multiprocessing backend works fine with joblib so I’m a little bit puzzled why distributed.joblib is not working and that’s why I think that having a pre_task_accept closure in the workers class or cluster.execute method would be useful.

Could you please advise what should I do in cases like that?

P.S. the code in that /shared/dir/with/source/code is not pure python - it has precompiled python modules (.so files - interfaces to some Fortran libs).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jcristcommented, May 12, 2017

The distributed joblib backend just runs on a dask-distributed cluster. Any of the normal ways of making python libraries available to the workers should work fine here. A few possibilities:

  • Actually install your python code into the PYTHONPATH of your worker processes (recommended). Is there a reason you can’t do this?
  • Use Client.run and do what you’re doing above:
from dask.distributed import Client
c = Client(...)

def f():
    import sys;
    sys.path.append("/shared/dir/with/source/code")

c.run(f)
0reactions
GenevieveBuckleycommented, Oct 15, 2021

Hi @thoth291, I don’t know if you have had a chance to try John’s suggestion. If you do that and have more questions, I encourage you to open a new issue to discuss 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Embarrassingly parallel for loops - Joblib - Read the Docs
This backend creates an instance of multiprocessing. Pool that forks the Python interpreter in multiple processes to execute each of the items of...
Read more >
joblib Documentation - Read the Docs
Joblib can save their computation to disk and rerun it only if necessary: ... which means that arbitrary Python code can be executed...
Read more >
Easy distributed training with Joblib and dask - Tom Augspurger
This article will talk about some improvements we made to improve training scikit-learn models using a cluster. Scikit-learn uses joblib for ...
Read more >
Use Joblib to run your Python code in parallel - Measure Space
For most problems, parallel computing can really increase the computing speed. As the increase of PC computing power, we can simply increase our...
Read more >
https://huggingface.co/jeniya/BERTOverflow/commit/...
... +we +by +You +when +##ex +##ine +would +##ach +some +##op +there +##out +am ... +Ch +running +well +send +defin +Ex +##lder +fine...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found