-
-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Open
Description
Describe the bug
The time needed tocross_validate can have a big (x100) slow down when using parallel jobs (n_jobs > 1).
Note that the effect is difficult to reproduce as it happens only on the first few calls to cross_validate, perhaps some weird caching mechanism is at play ?
Steps/Code to Reproduce
from sklearn.datasets import make_regression
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_validate
import time
est = Ridge()
X, y = make_regression(100, 5, random_state=22)
for idx in range(5):
start_time = time.time()
scores = cross_validate(est, X, y, n_jobs=2)
elapsed_time = time.time() - start_time
print(f"{idx=} {elapsed_time=:.2f}")Expected Results
About the same time for each call.
Actual Results
idx=0 elapsed_time=1.15 # about 100x slower
idx=1 elapsed_time=0.01
idx=2 elapsed_time=0.01
idx=3 elapsed_time=0.01
idx=4 elapsed_time=0.01
Versions
System:
python: 3.13.5 | packaged by conda-forge | (main, Jun 16 2025, 08:24:05) [Clang 18.1.8 ]
executable: /Users/abaker/miniforge3/envs/sklearn-dev/bin/python
machine: macOS-14.5-arm64-arm-64bit-Mach-O
Python dependencies:
sklearn: 1.9.dev0
pip: 25.2
setuptools: 80.9.0
numpy: 2.3.2
scipy: 1.16.1
Cython: 3.1.3
pandas: 2.3.2
matplotlib: 3.10.5
joblib: 1.5.1
threadpoolctl: 3.6.0
Built with OpenMP: True
threadpoolctl info:
user_api: blas
internal_api: openblas
num_threads: 8
prefix: libopenblas
filepath: /Users/abaker/miniforge3/envs/sklearn-dev/lib/libopenblas.0.dylib
version: 0.3.30
threading_layer: openmp
architecture: VORTEX
user_api: openmp
internal_api: openmp
num_threads: 8
prefix: libomp
filepath: /Users/abaker/miniforge3/envs/sklearn-dev/lib/libomp.dylib
version: None