Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change multiprocessing methodology from Process to Pool.starmap. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Iain-S
Copy link

@Iain-S Iain-S commented Oct 16, 2020

Hello

The existing code for handling processes in:

  • mantis_ml/modules/supervised_learn/model_selection/benchmark_all_classifiers.py
  • mantis_ml/modules/supervised_learn/feature_selection/run_boruta.py
  • mantis_ml/modules/supervised_learn/model_selection/dnn_grid_search_cv.py
  • mantis_ml/modules/supervised_learn/pu_learn/pu_learning.py

Looks something like:

procs = []
for i in range(len(train_data)):
    p = Process(train_data[i], test_data[i], results_list)
    procs.append(p)

    if len(procs) > max_procs:
        for k in procs:
            k.join()
        procs = []

for k in procs:
    k.join()

This means that any time len(procs) > max_procs, you wait on all currently running processes to finish. This is inefficient because you will always be waiting on the slowest process to finish before starting any others.

Instead, you can use Pool.starmap from multiprocessing.

It works like this:

with Pool(max_procs) as pool:
    pool.starmap(zip(train_data, test_data, repeat(results_list)))

It means that as soon as one process finishes, another will start. In my tests, the time for the first 50 training sets to run went from 60 seconds to 12 seconds.

I have proposed changes to pu_learning.py because that was the only module I knew how to test. The same logic could easily be applied to the other three.

@Iain-S
Copy link
Author

Iain-S commented Jan 17, 2021

Hi @dvitsios

Just wanted to draw your attention to this PR, in case you hadn't seen it or wanted to propose any changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant