Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridSearchCV and Google colab: n_jobs=-1 does not work

The problem is the following: when running these lines of code

grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)
grid_result = grid.fit(X, y)

on Google Colab, it returns the error

PicklingError: Could not pickle the task to send it to the workers.

However, if I set n_jobs = 1, it perfectly works.

How can I use multiple processors on Google Colab?

like image 279
Alessandro Avatar asked Nov 14 '25 18:11

Alessandro


1 Answers

There are some possible problems for your issue:

  • One problem may be your param_grid=param_grid, sometimes a change of grid search parameters solve the issue.

  • Another potential issue may be with your model and the parameters that are used there. See this issue as an example.

  • You can try any other numbers for example n_jobs=4 instead of n_jobs=-1. Also, you can use:

n_cpus = multiprocessing.cpu_count()

to get the number of CPUs and then

n_jobs=n_cpus 

or

n_jobs=n_cpus - 1 
like image 186
Raha Moosavi Avatar answered Nov 17 '25 07:11

Raha Moosavi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!