Skip to content

New warning message when parallelizing #7552

Closed

Description

@EtienneCmb

Description

I just update to the 0.18 version, and I've now a recurrent parallelizing warning message that was absent previously.

Steps/Code to Reproduce

The code bellow is adapted from an online example, using several features selections. The same didn't produce a warning message with the previous scikit version.

from sklearn.pipeline import Pipeline, FeatureUnion
from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
from sklearn.datasets import load_iris
from sklearn.decomposition import PCA
from sklearn.feature_selection import SelectKBest

if __name__ == '__main__':
    iris = load_iris()

    X, y = iris.data, iris.target

    # This dataset is way too high-dimensional. Better do PCA:
    pca = PCA(n_components=2)

    # Maybe some original features where good, too?
    selection = SelectKBest(k=1)

    # Build estimator from PCA and Univariate selection:

    combined_features = FeatureUnion([("pca", pca), ("univ_select", selection)], n_jobs=1)

    # Use combined features to transform dataset:
    X_features = combined_features.fit(X, y).transform(X)

    svm = SVC(kernel="linear")

    # Do grid search over k, n_components and C:

    pipeline = Pipeline([("features", combined_features), ("svm", svm)])

    param_grid = dict(features__pca__n_components=[1, 2, 3],
                      features__univ_select__k=[1, 2],
                      svm__C=[0.1, 1, 10])

    grid_search = GridSearchCV(pipeline, param_grid=param_grid, verbose=0, n_jobs=-1)
    grid_search.fit(X, y)
    print(grid_search.best_estimator_)

Actual Results

Here is the waning message :

joblib/parallel.py:540: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
  **self._backend_args)

It looks like there is deep process using parallelization.

Versions

Linux-3.19.0-32-generic-x86_64-with-debian-jessie-sid
Python 3.5.1 |Anaconda 2.4.1 (64-bit)| (default, Dec 7 2015, 11:16:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
NumPy 1.11.1
SciPy 0.18.1
Scikit-Learn 0.18
Joblib 0.9.4

Activity

  1. EtienneCmb commented on Oct 2, 2016

    @EtienneCmb
    Author

    An other example producing the same warning message :

    from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
    from sklearn.svm import SVC
    from sklearn.ensemble import VotingClassifier
    from sklearn.model_selection import cross_val_score
    from sklearn.datasets import load_iris
    
    if __name__ == '__main__':
        # Load fisher iris dataset :
        iris = load_iris()
        x, y = iris.data, iris.target
    
        # Create a voting clasifier :
        lda = LinearDiscriminantAnalysis()
        svm = SVC()
        clf = VotingClassifier([('lda', lda), ('svm', svm)])
    
        # Get accuracy :
        da = cross_val_score(clf, x, y, n_jobs=-1)
  2. lesteve commented on Oct 3, 2016

    @lesteve
    Member

    It is very likely related to joblib/joblib#406. We will 1) fix this warning in joblib first, 2) release a new joblib version 3) update the joblib copy bundled with scikit-learn.

    @EtienneCmb just a tip you can have syntax highlighting in your snippet by adding py after the initial three backquotes. Read fenced code blocks for more details.

  3. EtienneCmb commented on Oct 3, 2016

    @EtienneCmb
    Author

    Ok, I didn't saw that it was already solved! For instance I run my script without warning message (python -W ignore myscript.py). Thanks for the syntax highlighting, I just updated my post with your advice.

  4. lesteve commented on Oct 3, 2016

    @lesteve
    Member

    It has already been reported but not already solved.

    Another tip, you can use the PYTHONWARNINGS environment variable to selectively ignore warnings e.g. this seems to do the job:

    export PYTHONWARNINGS='ignore:Multiprocessing-backed parallel loops:UserWarning'
    
  5. reopened this on Oct 3, 2016
  6. added this to the 0.18.1 milestone on Oct 5, 2016
  7. amueller commented on Oct 14, 2016

    @amueller
    Member

    @lesteve you tagged this 0.18.1. When are you planning to release and backport? I would like to do 0.18.1 within the next two weeks.

  8. lesteve commented on Oct 17, 2016

    @lesteve
    Member

    When are you planning to release and backport?

    I was planning to do a joblib bugfix release indeed. I can do it this week and do a PR in scikit-learn.

  9. amueller commented on Oct 17, 2016

    @amueller
    Member

    that would be sweet. Releasing sklearn next week would be ideal but might be somewhat optimistic.

  10. lesteve commented on Oct 18, 2016

    @lesteve
    Member

    @amueller I released a new joblib version and created a PR: #7696.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions