gpt4 book ai didi

scikit-learn:关于并行计算的一般问题

转载 作者:行者123 更新时间:2023-12-04 02:07:10 25 4
gpt4 key购买 nike

我想用 sklearn.grid_search.GridSearchCV()在多个处理器上并行。这是我第一次这样做,但我的初步测试表明它似乎有效。

我想了解 this部分文档:

n_jobs : int, default 1

Number of jobs to run in parallel.



pre_dispatch : 整数或字符串,可选

Controls the number of jobs that get dispatched during parallel execution. Reducing this number can be useful to avoid an explosion of memory consumption when more jobs get dispatched than CPUs can process. This parameter can be:

None, in which case all the jobs are immediately created and spawned. Use this for lightweight and fast-running jobs, to avoid delays due to on-demand spawning of the jobs An int, giving the exact number of total jobs that are spawned A string, giving an expression as a function of n_jobs, as in ‘2*n_jobs’




有人可以为我分解一下吗?我无法理解 n_jobs 之间的区别和 pre_dispatch .如果我设置 n_jobs = 5pre-dispatch=2 ,这和仅仅设置 n_jobs=2有什么不同?

最佳答案

假设您正在使用 GridSearchCV对于带有参数网格的 KNN:k=[1,2,3,4,5, ... 1000] .

即使您设置 n_jobs=2 , GridSearchCV将首先创建 1000 个工作岗位,每个工作岗位可以选择您的 k ,还制作 1000 个数据副本(如果数据很大,可能会炸毁您的内存),然后将这 1000 个作业发送到 2 个 CPU(当然,大多数作业将处于待处理状态)。
GridSearchCV不只是为 2 个 CPU 生成 2 个作业,因为按需生成作业的过程很昂贵。它直接产生等量的作业作为您拥有的参数组合(在本例中为 1000)。

从这个意义上说,措辞n_jobs可能会产生误导。现在,使用 pre_dispatch您可以设置要生成的预调度作业数量。

关于scikit-learn:关于并行计算的一般问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32673579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com