当前位置:   article > 正文

错误: NotImplementedError: Cannot copy out of meta tensor; no data!(多机多卡)_cannot copy out of meta tensor; no data!

cannot copy out of meta tensor; no data!

模型参数初始化有问题
在模型文件中,有个modeling_chatglm.py文件,大概750多行左右,将默认的empty_init=True,改为empty_init=False,即可

class ChatGLMModel(ChatGLMPreTrainedModel):
		# 修改这里的默认值
    def __init__(self, config: ChatGLMConfig, device=None, empty_init=True): 
        super().__init__(config)
        if empty_init:
            init_method = skip_init
        else:
            init_method = default_init
        init_kwargs = {}
       
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

解释:

按照原博的解释,这个错误通常是由于 Deepspeed 在使用自定义权重初始化时出现问题,而这些初始化可能需要从先前的训练中加载权重。如果在使用 Deepspeed 进行分布式训练时出现此错误,则需要在初始化模型时指定empty_init=False,以便在加载权重之前,权重矩阵不会被初始化为空。

AutoModel.from_pretrained 是 Hugging Face Transformers 库中的一个方法,用于从预训练模型中加载权重。在 Deepspeed 分布式训练中,模型的初始化和权重加载可能需要特殊处理,因此需要使用 empty_init=False 参数来指定在加载权重之前不要将权重矩阵初始化为空。

这位作者提供了多种方法

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/article/detail/57721
推荐阅读
相关标签
  

闽ICP备14008679号