GPT2-Chinese icon indicating copy to clipboard operation
GPT2-Chinese copied to clipboard

使用多gpu训练的时候,会有RuntimeError: Gather got an input of invalid size:问题

Open 256785 opened this issue 5 years ago • 8 comments

我查了一下是因为,多gpu计算的时候分配数据造成的,项目里是不是也要加一些类似的处理

256785 avatar Dec 23 '19 07:12 256785

你好,这个问题会影响训练吗?直接使用DataParallel确实会影响多卡训练的效率,这个有空的话大家可以自己改一下或者提交PR

Morizeyao avatar Dec 23 '19 09:12 Morizeyao

确实影响了训练,比如batch_size使用三个卡训练,数据被分成了3,3,2就影响了。使用两个卡,也遇到过类似的报错。

256785 avatar Dec 23 '19 09:12 256785

嗯嗯,可以设置batch size为卡数的整数倍吗?

Morizeyao avatar Dec 23 '19 10:12 Morizeyao

嗯嗯 设置过 但是也有问题。试过batchsize是64 卡数是2------------------ 原始邮件 ------------------ 发件人: "Zeyao Du"[email protected] 发送时间: 2019年12月23日(星期一) 晚上6:33 收件人: "Morizeyao/GPT2-Chinese"[email protected]; 抄送: "256785"[email protected];"Author"[email protected]; 主题: Re: [Morizeyao/GPT2-Chinese] 使用多gpu训练的时候,会有RuntimeError: Gather got an input of invalid size:问题 (#118)

嗯嗯,可以设置batch size为卡数的整数倍吗?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

256785 avatar Dec 23 '19 10:12 256785

试过 batch_size=64 2个卡 也还是有这个问题

256785 avatar Dec 23 '19 11:12 256785

试试这个? https://github.com/Link-Li/Balanced-DataParallel

Morizeyao avatar Dec 23 '19 11:12 Morizeyao

我 设置batchsize为卡个数的倍数 就解决了

ares89 avatar Jan 17 '20 03:01 ares89

我又重新做了下 确实是卡的倍数就可以了,不知道第一次是因为什么没训练出来。非常感谢大家帮忙呀~

256785 avatar Jan 17 '20 03:01 256785