Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多机多卡分布式训练如何实现? #62

Open
447428054 opened this issue Nov 7, 2022 · 4 comments
Open

多机多卡分布式训练如何实现? #62

447428054 opened this issue Nov 7, 2022 · 4 comments
Labels
todo list New feature or request

Comments

@447428054
Copy link

@Tongjilibo 您好,我看model里面有BaseModelDDP,想知道是如何使用来进行分布式训练呢,里面只有一个master_rank参数,多机多卡的进程数、地址那些在哪设置呢

@Tongjilibo
Copy link
Owner

Tongjilibo commented Nov 7, 2022

您好,我之前写过一个单机多卡的DDP的示例,多机多卡我这边还没测试过,欢迎指教和补充~

@Tongjilibo Tongjilibo added the todo list New feature or request label May 12, 2023
@zhouyiyuan-mt
Copy link

zhouyiyuan-mt commented Aug 30, 2023

您好,我之前写过一个单机多卡的DDP的示例,多机多卡我这边还没测试过,欢迎指教和补充~

在训练时,每个epoch需要设置sampler的随机种子,model.fit()里好像并没有考虑到。官方的torch.utils.data.DistributedSampler使用代码如下:

sampler = DistributedSampler(dataset) if is_distributed else None
loader = DataLoader(dataset, shuffle=(sampler is None), sampler=sampler)
for epoch in range(start_epoch, n_epochs):
....if is_distributed:
........sampler.set_epoch(epoch)
....train(loader)

@Tongjilibo
Copy link
Owner

好的,谢谢指导~,目前要实现的话,方式的确有点别扭,是需要在一个callbackon_epoch_begin中手动实现,我看看怎么自动实现比较好

@Tongjilibo
Copy link
Owner

Tongjilibo commented Aug 30, 2023

@zhouyiyuan-mt 我在torch4keras中这里,也是就dataloader消耗完的时候重新设置(即steps_per_epoch=None时,一个epoch结束时候即为dataloader消耗完)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
todo list New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants