pytorch distributed learning分布式训练

本文档介绍了如何在PyTorch中进行分布式训练,强调首先在非分布式环境中调试模型,然后通过命令行以分布式方式运行。关键步骤包括在`__main__`中初始化分布式,配置数据集,以及使用`torch.distributed.launch`工具启动多GPU训练。注意,批量大小应至少等于参与节点的数量。
摘要由CSDN通过智能技术生成

参考https://theaisummer.com/distributed-training-pytorch/

一般来说,最好先用非分布式的模型下debug,然后包装成分布式用命令行运行。

1、在__main__ 中parse args之前init distributed


#============================Example 2=================================
def init_distributed():

    # Initializes the distributed backend which will take care of synchronizing nodes/GPUs
    dist_url = "env://" # default

    # # only works with torch.distributed.launch // torch.run
    rank = int(os.environ["RANK"])
    world_size = int(os.environ['WORLD_SIZE'])
    loca
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值