MCPcopy Index your code
hub / github.com/scikit-learn/scikit-learn / Parallel

Class Parallel

sklearn/utils/parallel.py:41–91  ·  view source on GitHub ↗

Tweak of :class:`joblib.Parallel` that propagates the scikit-learn configuration. This subclass of :class:`joblib.Parallel` ensures that the active configuration (thread-local) of scikit-learn is propagated to the parallel workers for the duration of the execution of the parallel tasks.

Source from the content-addressed store, hash-verified

39
40
41class Parallel(joblib.Parallel):
42 """Tweak of :class:`joblib.Parallel` that propagates the scikit-learn configuration.
43
44 This subclass of :class:`joblib.Parallel` ensures that the active configuration
45 (thread-local) of scikit-learn is propagated to the parallel workers for the
46 duration of the execution of the parallel tasks.
47
48 The API does not change and you can refer to :class:`joblib.Parallel`
49 documentation for more details.
50
51 .. versionadded:: 1.3
52 """
53
54 def __call__(self, iterable):
55 """Dispatch the tasks and return the results.
56
57 Parameters
58 ----------
59 iterable : iterable
60 Iterable containing tuples of (delayed_function, args, kwargs) that should
61 be consumed.
62
63 Returns
64 -------
65 results : list
66 List of results of the tasks.
67 """
68 # Capture the thread-local scikit-learn configuration at the time
69 # Parallel.__call__ is issued since the tasks can be dispatched
70 # in a different thread depending on the backend and on the value of
71 # pre_dispatch and n_jobs.
72 config = get_config()
73 # In free-threading Python >= 3.14, warnings filters are managed through a
74 # ContextVar and warnings.filters is not modified inside a
75 # warnings.catch_warnings context. You need to use warnings._get_filters().
76 # For more details, see
77 # https://docs.python.org/3.14/whatsnew/3.14.html#concurrent-safe-warnings-control
78 filters_func = getattr(warnings, "_get_filters", None)
79 warning_filters = (
80 filters_func() if filters_func is not None else warnings.filters
81 )
82
83 iterable_with_config_and_warning_filters = (
84 (
85 _with_config_and_warning_filters(delayed_func, config, warning_filters),
86 args,
87 kwargs,
88 )
89 for delayed_func, args, kwargs in iterable
90 )
91 return super().__call__(iterable_with_config_and_warning_filters)
92
93
94# remove when https://github.com/joblib/joblib/issues/1071 is fixed

Callers 15

fitMethod · 0.90
fitMethod · 0.90
partial_fitMethod · 0.90
fitMethod · 0.90
partial_fitMethod · 0.90
fitMethod · 0.90
_parallel_funcMethod · 0.90
transformMethod · 0.90
partial_fitMethod · 0.90
fitMethod · 0.90
predictMethod · 0.90
cross_validateFunction · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…