#工作记录

一、问题描述

在运行CosyVoice_For_Windows项目时,出现以下报错:

 File "D:\ProgramData\anaconda3\envs\CosyVoice\Lib\site-packages\deepspeed\elasticity\elastic_agent.py", line 9, in <module>
    from torch.distributed.elastic.agent.server.api import log, _get_socket_with_port
ImportError: cannot import name 'log' from 'torch.distributed.elastic.agent.server.api' (D:\ProgramData\anaconda3\envs\CosyVoice\Lib\site-packages\torch\distributed\elastic\agent\server\api.py)


二、受影响的文件和行号


文件:

D:\ProgramData\anaconda3\envs\CosyVoice\Lib\site-packages\deepspeed\elasticity\elastic_agent.py

行号:第 9 行

原代码:

from torch.distributed.elastic.agent.server.api import log, _get_socket_with_port

三、修复方法一


1. 将代码中的“log”更改为“logger”

from torch.distributed.elastic.agent.server.api import logger

2. 测试修改后的代码
重新运行 项目 脚本,确认报错是否消失。


 

四、修复方法二

更新 PyTorch 和 DeepSpeed

确保所使用的 PyTorch 和 DeepSpeed 版本是兼容的。有时,更新这些库可以解决该问题。

示例:

#该命令目前还不适用于Windows
pip install --upgrade torch deepspeed

Windows系统请参考以下文章来升级DeepSpeed版本: 

可用于快捷安装DeepSpeed的whl地址_deepspeed windows whl文件-CSDN博客

五、总结

此问题据说会在较新的DeepSpeed版本中被修复

参考资料

异常:无法从 'torch.distributed.elastic.agent.server.api' 导入名称 'log' ·问题 #180 ·huggingface/对齐手册

[BUG] 无法从 Elastic Agent 导入名称“log” ·问题 #5337 ·深度速度ai/深度速度 

错误:snoels 的 SFTConfig 类型错误 ·拉取请求 #179 ·huggingface/对齐手册 


修复到这里其实还不算完,后续程序大概率还会抛出ImportError: cannot import name '_get_socket_with_port' from 'torch.distributed.elastic.agent.server.api错误,因篇幅和测试原因请看下节。

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐