Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MAINT Do not propagate n_jobs as n_threads #22593

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,9 @@ functions or non-estimator constructors.
generally be interpreted as ``n_jobs=1``, unless the current
:class:`joblib.Parallel` backend context specifies otherwise.

Note that even if ``n_jobs=1``, low-level parallelism (via Numpy and OpenMP)
might be used in some configuration.

For more details on the use of ``joblib`` and its interactions with
scikit-learn, please refer to our :ref:`parallelism notes
<parallelism>`.
Expand Down
34 changes: 1 addition & 33 deletions sklearn/metrics/_pairwise_distances_reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ cdef class PairwiseDistancesReduction:
scikit-learn configuration for `pairwise_dist_chunk_size`,
and use 256 if it is not set.

n_threads: int, default=None
The number of OpenMP threads to use for the reduction.
Parallelism is done on chunks and the sharding of chunks
depends on the `strategy` set on :method:`~PairwiseDistancesReduction.compute`.

See _openmp_effective_n_threads, for details about
the specification of n_threads.

strategy : str, {'auto', 'parallel_on_X', 'parallel_on_Y'}, default=None
The chunking strategy defining which dataset parallelization are made on.

Expand Down Expand Up @@ -220,7 +212,6 @@ cdef class PairwiseDistancesReduction:
self,
DatasetsPair datasets_pair,
chunk_size=None,
n_threads=None,
strategy=None,
):
cdef:
Expand All @@ -231,7 +222,7 @@ cdef class PairwiseDistancesReduction:

self.chunk_size = check_scalar(chunk_size, "chunk_size", Integral, min_val=20)

self.effective_n_threads = _openmp_effective_n_threads(n_threads)
self.effective_n_threads = _openmp_effective_n_threads()

self.datasets_pair = datasets_pair

Expand Down Expand Up @@ -512,15 +503,6 @@ cdef class PairwiseDistancesArgKmin(PairwiseDistancesReduction):
scikit-learn configuration for `pairwise_dist_chunk_size`,
and use 256 if it is not set.

n_threads: int, default=None
The number of OpenMP threads to use for the reduction.
Parallelism is done on chunks and the sharding of chunks
depends on the `strategy` set on
:meth:`~PairwiseDistancesArgKmin.compute`.

See _openmp_effective_n_threads, for details about
the specification of n_threads.

k: int, default=1
The k for the argkmin reduction.
"""
Expand All @@ -544,7 +526,6 @@ cdef class PairwiseDistancesArgKmin(PairwiseDistancesReduction):
str metric="euclidean",
chunk_size=None,
dict metric_kwargs=None,
n_threads=None,
str strategy=None,
bint return_distance=False,
):
Expand Down Expand Up @@ -574,15 +555,6 @@ cdef class PairwiseDistancesArgKmin(PairwiseDistancesReduction):
metric_kwargs : dict, default=None
Keyword arguments to pass to specified metric function.

n_threads : int, default=None
The number of OpenMP threads to use for the reduction.
Parallelism is done on chunks and the sharding of chunks
depends on the `strategy` set on
:meth:`~PairwiseDistancesArgKmin.compute`.

See _openmp_effective_n_threads, for details about
the specification of n_threads.

strategy : str, {'auto', 'parallel_on_X', 'parallel_on_Y'}, default=None
The chunking strategy defining which dataset parallelization are made on.

Expand Down Expand Up @@ -686,14 +658,12 @@ cdef class PairwiseDistancesArgKmin(PairwiseDistancesReduction):
self,
DatasetsPair datasets_pair,
chunk_size=None,
n_threads=None,
strategy=None,
ITYPE_t k=1,
):
super().__init__(
datasets_pair=datasets_pair,
chunk_size=chunk_size,
n_threads=n_threads,
strategy=strategy,
)
self.k = check_scalar(k, "k", Integral, min_val=1)
Expand Down Expand Up @@ -932,7 +902,6 @@ cdef class FastEuclideanPairwiseDistancesArgKmin(PairwiseDistancesArgKmin):
ITYPE_t k,
bint use_squared_distances=False,
chunk_size=None,
n_threads=None,
strategy=None,
metric_kwargs=None,
):
Expand All @@ -948,7 +917,6 @@ cdef class FastEuclideanPairwiseDistancesArgKmin(PairwiseDistancesArgKmin):
# The datasets pair here is used for exact distances computations
datasets_pair=DatasetsPair.get_for(X, Y, metric="euclidean"),
chunk_size=chunk_size,
n_threads=n_threads,
strategy=strategy,
k=k,
)
Expand Down
8 changes: 5 additions & 3 deletions sklearn/metrics/tests/test_pairwise_distances_reduction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest
import threadpoolctl
from numpy.testing import assert_array_equal, assert_allclose
from scipy.sparse import csr_matrix
from scipy.spatial.distance import cdist
Expand Down Expand Up @@ -229,9 +230,10 @@ def test_n_threads_agnosticism(
return_distance=True,
)

dist, indices = PairwiseDistancesReduction.compute(
X, Y, parameter, n_threads=1, return_distance=True
)
with threadpoolctl.threadpool_limits(limits=1, user_api="openmp"):
dist, indices = PairwiseDistancesReduction.compute(
X, Y, parameter, return_distance=True
)

ASSERT_RESULT[PairwiseDistancesReduction](ref_dist, dist, ref_indices, indices)

Expand Down
1 change: 0 additions & 1 deletion sklearn/neighbors/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,6 @@ class from an array representing our data set and ask who's
k=n_neighbors,
metric=self.effective_metric_,
metric_kwargs=self.effective_metric_params_,
n_threads=self.n_jobs,
strategy="auto",
return_distance=return_distance,
)
Expand Down