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

replace multi processing with joblib #477

Merged
merged 11 commits into from
Sep 13, 2021

Conversation

you-n-g
Copy link
Collaborator

@you-n-g you-n-g commented Jun 24, 2021

Description

Multiprocessing has following weakness

  • It can not be used in a nested way multiple times
  • It can not be disabled automatically even when the number of workers is 1.

Joblib has no above problems.
So we try to replace multi processing with joblib

How Has This Been Tested?

  • Pass the test by running: pytest qlib/tests/test_all_pipeline.py under upper directory of qlib.
  • If you are adding a new feature, test on your own test scripts.

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

@you-n-g you-n-g force-pushed the nested_decision_exe branch from 5100a5a to ef7fe8a Compare July 3, 2021 09:22
@you-n-g you-n-g force-pushed the nested_decision_exe branch 2 times, most recently from 1b7080f to 4a62e02 Compare July 18, 2021 07:12
@wangwenxi-handsome wangwenxi-handsome deleted the branch microsoft:nested_decision_exe August 31, 2021 12:02
@you-n-g you-n-g reopened this Sep 1, 2021
require=None,
maxtasksperchild=None,
**kwargs)
self._backend_args["maxtasksperchild"] = ["maxtasksperchild"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._backend_args["maxtasksperchild"] = maxtasksperchild

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isinstance(self._backend, MultiprocessingBackend):
    self._backend_args["maxtasksperchild"] = maxtasksperchild

from joblib import Parallel


class UpdateParallel(Parallel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateParallel moves to qlib/utils/__init__.py
UpdateParllel renamed to ParallelExt

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/microsoft/qlib/blob/main/qlib/utils/paral.py will be a better place

maxtasksperchild=None,
**kwargs
):
super(UpdateParallel, self).__init__(n_jobs=n_jobs,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super(UpdateParallel, self).__init__(
    n_jobs=n_jobs,
    backend=backend,
    verbose=verbose,
    timeout=timeout,
    pre_dispatch=pre_dispatch,
    batch_size=batch_size,
    temp_folder=temp_folder,
    max_nbytes=max_nbytes,
    mmap_mode=mmap_mode,
    prefer=prefer,
    require=require,
)

backend=None,
verbose=0,
timeout=None,
pre_dispatch="2 * n_jobs",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using *args, **kwargs instead of explicitly list all the arguments?

from joblib import Parallel


class UpdateParallel(Parallel):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/microsoft/qlib/blob/main/qlib/utils/paral.py will be a better place

qlib/config.py Outdated
@@ -92,6 +92,7 @@ def set_conf_from_C(self, config_c):
"kernels": NUM_USABLE_CPU,
# How many tasks belong to one process. Recommend 1 for high-frequency data and None for daily data.
"maxtasksperchild": None,
"joblib_backend" : None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the default backend to multiprocessing if loky is very likely to OOM?

@@ -0,0 +1,41 @@
from joblib import Parallel
Copy link
Collaborator Author

@you-n-g you-n-g Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""
For testing if it will raise error
"""
qlib.init(provider_uri=TestAutoData.provider_uri, expression_cache=None, dataset_cache=None)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to use loky to pass the test

@you-n-g you-n-g marked this pull request as ready for review September 13, 2021 17:15
@you-n-g you-n-g merged commit 163e3c6 into microsoft:nested_decision_exe Sep 13, 2021
@you-n-g you-n-g deleted the fix_multi_proc branch September 13, 2021 17:16
qianyun210603 pushed a commit to qianyun210603/qlib that referenced this pull request Mar 23, 2023
* replace multi processing with joblib

* update class Parallel and data.py

* update class Parallel and data.py

* update class Parallel and data.py

* update class Parallel and data.py

* update class Parallel and data.py

* update class Parallel and data.py

* update class Parallel and data.py

* update class Parallel and data.py

* Fix Parallel support for maxtasksperchild

Co-authored-by: wangw <1666490690@qq.com>
Co-authored-by: zhupr <zhu.pengrong@foxmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants