jia-zhuang / pytorch-multi-gpu-training Goto Github PK
View Code? Open in Web Editor NEW整理 pytorch 单机多 GPU 训练方法与原理
整理 pytorch 单机多 GPU 训练方法与原理
你好,我想问一下你这个项目实际的跑起来了吗
并行化模型的时候可以加上一步操作:
# Convert BatchNorm to SyncBatchNorm.
net = nn.SyncBatchNorm.convert_sync_batchnorm(net)
确保batch norm 在所有process上sync了。
When I use torch.nn.DataParallel, the error will appear:
RuntimeError: Caught RuntimeError in replica 0 on device 0.
How can I deal with this situation?
Readme 里面的ddp 代码里有以下行:
# 固定随机种子
seed = 42
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
但是在代码ddp_train.py里没有这些行, 这是故意的吗?
代码如下:
for epoch in range(10):
acc_num=0
for i, (inputs, labels) in enumerate(train_loader):
# forward
inputs = inputs.to(device)
labels = labels.to(device)
outputs = model(inputs)
loss = criterion(outputs[0], labels)
# backward
optimizer.zero_grad()
loss.backward()
optimizer.step()
# log
if args.local_rank == 0 and i % 5 == 0:
tb_writer.add_scalar('loss', loss.item(), i)
acc_num += (outputs[0].argmax(1)==labels).sum()
if args.local_rank == 0:
tb_writer.add_scalar('acc', acc_num/len(train_dataset),epoch)
print(f"acc:{acc_num/len(train_dataset)}")
1个GPU时,acc:89%
3个GPU时,acc:29%
4个GPU时,acc: 17%
运行的时候报错了,缺少了一些环境变量的设置,RANK,WORLD_SIZE,MASTER_ADDR等
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.