当我保持 n_jobs=8 时,google colab 分配了多少个“CPU”核心,有什么方法可以检查吗?

Atu*_*era 7 google-colaboratory

我正在 Google colab 中使用 GridSearhCV 运行回归任务。在参数中,我保留n_jobs = 8,当我将其保留为-1(以使用所有可能的核心)时,它仅使用2个核心,所以我假设如果n_jobs = -1,服务器端存在限制,所以我会想知道如何检查实际使用了多少个核心。

小智 18

如果您使用下面的代码,您将看到 Google colab 中的多处理器有 2 个核心:

import multiprocessing

cores = multiprocessing.cpu_count() # Count the number of cores in a computer
cores
Run Code Online (Sandbox Code Playgroud)


小智 2

这也是我的疑问。我将 n_job = 100 放入 Colab 中,得到:

[Parallel(n_jobs=100)]:使用具有 100 个并发工作线程的后端 LokyBackend。

这是一个令人惊讶的事情,因为 google colab 只给你 2 个处理器。但是,您始终可以在 Colab 上使用自己的 CPU/GPU。