AttributeError:无法在 <module 'diffusers.models.attention'

问题描述 投票:0回答:1

两个月前我在 Kaggle 上训练了一个扩散模型。我将 Unet2D 模型存储为检查点处的 pickle 文件,以便稍后加载它以进行推理或在该检查点恢复训练。

def save_model(model):
  with open(f'{config.output_dir}/model.pkl','wb') as f:
    pickle.dump(model,f)

def load_model(path):
  with open(path,'rb') as f:
    return pickle.load(f)

这段代码 2 个月前在 Kaggle 和 Google Colab 上运行良好,但是当我今天尝试加载 model.pkl 文件时,出现以下错误:

AttributeError: Can't get attribute 'AttentionBlock' on <module 'diffusers.models.attention' from '/opt/conda/lib/python3.7/site-packages/diffusers/models/attention.py'>

谢谢,

我尝试将扩散器库更改为我2个月前使用的版本,但没有任何变化。

python pytorch google-colaboratory huggingface-transformers kaggle
1个回答
0
投票

我不确定为什么你不能使用以前工作过的相同版本的扩散器,但是,从this看来,AttentionBlock已被Attention取代。从 here 看来您可以使用

_convert_deprecated_attention_blocks
来更新您的模型。

© www.soinside.com 2019 - 2024. All rights reserved.