关于dataloader设置num_works和batchsize最佳方法

我是参照了这两个大佬的
1.dataloader合理设置num_works和batchsize
https://blog.csdn.net/qq_41917697/article/details/114663331
2.Pytorch之DataLoader的num_works参数设置
https://blog.csdn.net/qq_41196472/article/details/106393994?utm_source=app&app_version=4.7.1&code=app_1562916241&uLinkId=usr1mkqgl919blen
我的笔记本是CPU 6核12线程的,num_workers=8,设置这个数字是CPU利用率就达到100%了
GPU是6G显存
我的batch_size=16

这样不会爆内存,用第二个大佬的代码测试到最佳num_workers<12,等于12的时候就直接崩了,我的理解是最好不要直接多少线程填多少,其它数字可以自己边调代码边看利用率。
batch_size=16时我GPU显存也才用4G多点,GPU利用率也在50%左右,没有爆,理论上还可以往上加,但是听说GPU对2的幂次的batch可以发挥更佳的性能,因此设置成16、32、64、128…时往往要比设置为整10、整100的倍数时表现更优。具体是不是,我不知道,这有个文章,可以看看https://blog.csdn.net/wydbyxr/article/details/84855489

  • 6
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I can help you with that! Here's a Python program that implements the commands you've described: ```python class Sequence: def __init__(self): self.sequences = {} def new(self, id): if id >= 200000: print("Error: id should be less than 200000") return self.sequences[id] = [] def add(self, id, num): if id not in self.sequences: self.new(id) self.sequences[id].append(num) def merge(self, id1, id2): if id1 not in self.sequences or id2 not in self.sequences: print("Error: invalid ids") return self.sequences[id1] += self.sequences[id2] self.sequences[id2] = [] def unique(self, id): if id not in self.sequences: print("Error: invalid id") return self.sequences[id] = list(set(self.sequences[id])) def out(self, id): if id not in self.sequences: print("Error: invalid id") return sequence = sorted(self.sequences[id]) print(" ".join(str(num) for num in sequence)) sequence = Sequence() # Example usage: sequence.new(1) sequence.add(1, 5) sequence.add(1, 2) sequence.add(1, 3) sequence.add(1, 5) sequence.unique(1) sequence.out(1) sequence.new(2) sequence.add(2, 6) sequence.add(2, 1) sequence.add(2, 4) sequence.add(2, 3) sequence.merge(1, 2) sequence.out(1) ``` Here's an explanation of how it works: - The `Sequence` class represents a collection of sequences of numbers, identified by an integer ID. - The `new` method creates a new sequence with the specified ID. - The `add` method adds a number to the sequence with the specified ID. - The `merge` method merges two sequences with the specified IDs into one, and empties the second sequence. - The `unique` method removes any duplicate elements from the sequence with the specified ID. - The `out` method outputs the elements of the sequence with the specified ID, sorted in ascending order and separated by spaces. You can test the program by calling the methods on a `Sequence` instance, as shown in the example usage at the end.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值