运行Spacetimeformer仓库训练时遇tqdm.auto属性错误求助
问题:运行Spacetimeformer训练代码时出现AttributeError错误
运行Spacetimeformer仓库的训练代码时,触发以下错误:
lib\site-packages\torchmetrics\functional\text\bert.py", line 247, in <module> AttributeError: module 'tqdm' has no attribute 'auto'
涉及的代码片段:
def _get_progress_bar(dataloader: DataLoader, verbose: bool = False) -> Union[DataLoader, tqdm.auto.tqdm]: """Helper function returning either the dataloader itself when `verbose = False`, or it wraps the dataloader with `tqdm.auto.tqdm`, when `verbose = True` to display a progress bar during the embbeddings calculation.""" return tqdm.auto.tqdm(dataloader) if verbose else dataloader
解决方法
1. 升级tqdm到兼容版本
tqdm.auto 是tqdm较新版本才引入的模块,旧版本没有该属性。执行以下命令升级:
pip install --upgrade tqdm
建议升级到4.42.0及以上版本(该版本开始支持tqdm.auto)。
2. 替换代码中的tqdm.auto.tqdm
如果升级tqdm后存在依赖冲突问题,可以直接修改报错的代码:
将代码里的 tqdm.auto.tqdm 替换为 tqdm.tqdm,修改后的函数如下:
def _get_progress_bar(dataloader: DataLoader, verbose: bool = False) -> Union[DataLoader, tqdm.tqdm]: """Helper function returning either the dataloader itself when `verbose = False`, or it wraps the dataloader with `tqdm.tqdm`, when `verbose = True` to display a progress bar during the embbeddings calculation.""" return tqdm.tqdm(dataloader) if verbose else dataloader
tqdm.tqdm 是基础进度条实现,和tqdm.auto.tqdm功能一致,后者仅自动适配显示环境(如Jupyter/终端),终端运行训练时替换后无影响。
3. 检查虚拟环境依赖
确保在项目对应的虚拟环境中运行代码,避免全局环境的低版本tqdm干扰。先查看当前环境的tqdm版本:
pip show tqdm
若版本低于4.42.0,执行升级命令即可。
内容的提问来源于stack exchange,提问作者fragger
相关产品推荐
相关产品推荐

