本文共 1664 字,大约阅读时间需要 5 分钟。
forvalidation_batch_sizeandtest_batch_size, you should pick the largest batch size that your hardware can handle without running out of memory and crashing.
Finding this is usually a simple trial and error process.
The larger your batch size at inference time, the faster it will be, since more inputs can be processed in parallel.
centernet的resdcn18,batchsize64左右时,num woker调到20,每个epoch比设为0快10分钟(原来是17min)
摘抄:
num_worker大,下一轮迭代的batch可能在上一轮/上上一轮...迭代时已经加载好了。坏处是内存(显卡内存?)开销大(开了pin memory?) ,也加重了CPU负担。显存=显卡内存(内存单词是memory),作用是用来存储显卡芯片处理过或者即将提取的渲染数据。
如同计算机的内存一样,显存是用来存储要处理的图形信息的部件。(显存和GPU的关系有点类似于内存和CPU的关系)
CPU不能直接调用存储在硬盘上的系统、程序和数据,必须首先将硬盘的有关内容存储在内存中,这样才能被CPU读取运行。因而,内存(即物理 内存,是相对于硬盘这个“外存”而言)作为硬盘和CPU的“中转站”,对电脑运行速度有较大影响。
https://zhuanlan.zhihu.com/p/31558973
pin memory: 开了就在GPU上面预留一片固定的内存区域,以加速传输。
如果开了pin memory: 增大num_workers的数量,内存占用也会增加。因为每个worker都需要缓存一个batch的数据。此时,batch size和num_workers的增大不可兼得,否则cuda out of memory。
开pin memory不觉得能快多少,反倒是牺牲了batch size。
观点1:
如果性能瓶颈是在io上,那么num_workers超过(cpu核数*2)是有加速作用的。CPU的物理个数:grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l
结果为2,说明CPU有两个。
每个CPU的核数:cat /proc/cpuinfo |grep "cores"|uniq
10,说明每个10核。
cpu核数 = 2x10
但如果性能瓶颈在cpu计算上,继续增大num_workers反而会降低性能。
观点2:
Actually for a batch_size=32, num_workers=16 seem to be quite big. Have you tried any lower number of workers? say num_workers=4 or 8.
The extra time T (T is about 15s or more when batch_size=32 andnum_workers=16) it costs for every Nth iteration is directly proportional to the thread number N.
扩展阅读:物理cpu数:主板上实际插入的cpu数量,可以数不重复的 physical id 有几个(physical id)
cpu核数:单块CPU上面能处理数据的芯片组的数量,如双核、四核等 (cpu cores)
查看系统内存(不是显卡内存/显存):在命令行中输入“cat /proc/meminfo | grep MemTotal”
转载地址:https://blog.csdn.net/weixin_33001305/article/details/112841985 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!