我无法在PyTorch中初始化BERT模型的组进程,我曾尝试使用以下代码初始化:
import torch
import datetime
torch.distributed.init_process_group(
backend='nccl',
init_method='env://',
timeout=datetime.timedelta(0, 1800),
world_size=0,
rank=0,
store=None,
group_name=''
)
并尝试访问get_world_size()
函数:
num_train_optimization_steps = num_train_optimization_steps // torch.distributed.get_world_size()
完整代码:
train_examples = None
num_train_optimization_steps = None
if do_train:
train_examples = processor.get_train_examples(data_dir)
num_train_optimization_steps = int(
len(train_examples) / train_batch_size / gradient_accumulation_steps) * num_train_epochs
if local_rank != -1:
import datetime
torch.distributed.init_process_group(backend='nccl',init_method='env://', timeout=datetime.timedelta(0, 1800), world_size=0, rank=0, store=None, group_name='')
num_train_optimization_steps = num_train_optimization_steps // torch.distributed.get_world_size()
print(num_train_optimization_steps)
3条答案
按热度按时间j1dl9f461#
我通过引用https://github.com/NVIDIA/apex/issues/99来解决这个问题。具体运行
ruarlubt2#
只是更新,而不是运行:
现在你只需要运行:
如here所示。
kmbjn2e33#
如果你想在原生python中运行脚本,你也可以将这些行添加到你的脚本中(有助于调试)