Skip to content

Add "pre_dispatch" parameter to HalvingGridSearchCV #23108

Closed

Description

@nilslacroix

Describe the workflow you want to enable

In base GridSearchCV it is possible to set a pre_dispatch parameter, so that RAM usage by new jobs is limited.
I would like to do the same thing for the newer and arguably better versions of gridsearch.

Describe your proposed solution

Add the pre_dispatch parameter that already exists in scikit to the new grid searches.

Describe alternatives you've considered, if relevant

If you one that would be great because currently I am running into heavy issues with catboost which only accepts n_jobs=1 when running on gpu :)

Additional context

No response

Activity

  1. thomasjpfan commented on Apr 14, 2022

    @thomasjpfan
    Member

    We have resisted adding kwargs from joblib.Parallel into estimators and removed it recently: #18030 (comment)

    One option is to add a parallel_kwargs parameter that would pass the kwars down to joblib.Parallel.

    Another options is to make the parallel_backend context manager work:

    from joblib import Parallel, delayed, parallel_backend
    from math import sqrt
    
    # This does not work
    with parallel_backend("loky", pre_dispatch="2*n_jobs"):
        parallel = Parallel()
        out = parallel(delayed(sqrt)(i ** 2) for i in range(10))
    print(out)

    @lesteve @ogrisel What do you think?

  2. added and removed
    Needs Triage
    on Apr 14, 2022
  3. ogrisel commented on Jun 30, 2022

    @ogrisel
    Member

    I don't understand why pre_dispatch would fundamentally change memory usage anyway: the memory mapping of the training data should prevent large data copies.

  4. ogrisel commented on Jun 30, 2022

    @ogrisel
    Member

    @nilslacroix have you tried to hard-code a different value of pre_dispatch in your local copy of scikit-learn in the source code of HalvingGridSearchCV to see if it actually fix your problem?

    If so, which values help, and which value make the execution crash and what it the error message you get?

  5. ogrisel commented on Jun 30, 2022

    @ogrisel
    Member

    We could implement @thomasjpfan's suggestion but that will make joblib even more complex so I would like to make sure that it is actually useful before considering a pull request.

  6. thomasjpfan commented on Aug 26, 2022

    @thomasjpfan
    Member

    I am closing this issue because there was no response to #23108 (comment).

  7. smith558 commented on Apr 2, 2023

    @smith558
    Contributor

    I am also running into issues with this. HalvingGridSearchCV causes a memory explosion when working with large datasets on HPC clusters with many cores available and therefore using high n_jobs. Having the pre_dispatch parameter available here would help.

  8. smith558 commented on Apr 2, 2023

    @smith558
    Contributor

    I don't understand why pre_dispatch would fundamentally change memory usage anyway: the memory mapping of the training data should prevent large data copies.

    This discussion seems to suggest otherwise and seems to suggest that data replication occurs when using n_jobs.
    https://datascience.stackexchange.com/questions/34416/scikit-learn-n-jobs-parameter-on-cpu-usage-memory

  9. smith558 commented on Apr 2, 2023

    @smith558
    Contributor

    Additionally, this makes the API inconsistent as the GridSearchCV makes this parameter available whilst the HalvingGridSearchCV doesn't.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions