【问题标题】:AttributeError: module 'torch.distributed' has no attribute 'is_initialized' in pytorch==1.11.XAttributeError:模块'torch.distributed'在pytorch == 1.11.X中没有属性'is_initialized'
【发布时间】:2022-06-16 15:17:42
【问题描述】:

每当我们为 TrainingArguments 创建对象时

from transformers import Trainer, TrainingArguments
batch_size = 64
logging_steps = len(emotions_encoded["train"]) // batch_size
model_name = f"{model_ckpt}-finetuned-emotion"
training_args = TrainingArguments(output_dir=model_name,
                                      num_train_epochs=2,
                                      learning_rate=2e-5,
                                      per_device_train_batch_size=batch_size,
                                      per_device_eval_batch_size=batch_size,
                                      weight_decay=0.01,
                                      evaluation_strategy="epoch",
                                      disable_tqdm=False,
                                      logging_steps=logging_steps,
                                      push_to_hub=True,
                                      log_level="error")

我得到了

AttributeError: 模块 'torch.distributed' 没有属性 'is_initialized'

【问题讨论】:

    标签: python pytorch huggingface-transformers


    【解决方案1】:

    为了解决这个问题

    实际上 Window 和 Mac 不支持分布式训练工具

    所以出现了这个问题

    解决这个问题

    转到安装它的转换器包

    就我而言

    Desktop/rajesh/pytorch_env/env/lib/python3.8/site-packages/transformers/training_args.py
    

    替换第 1024 行
    如果 torch.distributed.is_initialized() 和 self.local_rank == -1: 和 if True and self.local_rank == -1:

    重启你的内核

    【讨论】:

      猜你喜欢
      • 2017-01-17
      • 2018-10-10
      • 2021-08-11
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 2018-04-14
      • 2019-02-18
      相关资源
      最近更新 更多