我正在使用 Paperspace 进行编程。我想从
trl导入
AutoModelForCausalLMWithValueHead, PPOConfig, PPOTrainer
但我遇到了错误。我安装了所需的库,例如torch==1.9.0 or 2.0.1
,
transformers==4.18.0
和trl
。导入库后如下图:
import pandas as pd
import os
import torch
from transformers import GPT2Tokenizer
from trl import AutoModelForCausalLMWithValueHead, PPOConfig, PPOTrainer
我收到错误:
ImportError: cannot import name 'GenerationConfig' from 'transformers' (/usr/local/lib/python3.9/dist-packages/transformers/__init__.py)
请注意,使用
Google Colab
时代码可以正常运行。然而,当在Paperspace
上运行时,我遇到了错误。看来Paperspace上PyTorch
的版本是1.12.1
,不太适合我的要求。我尝试创建一个虚拟环境来安装不同版本的 PyTorch,但不幸的是,版本仍然是1.12.1
。虽然我设法将 PyTorch 更新到像2.0.1
这样的更高版本,但我遇到了冲突依赖错误:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behavior is the source of the following dependency conflicts.
torchvision 0.13.1+cu116 requires torch==1.12.1, but you have torch 2.0.1 which is incompatible.
torchaudio 0.12.1+cu116 requires torch==1.12.1, but you have torch 2.0.1 which is incompatible.
即使使用最新版本的 PyTorch,错误仍然存在,我仍然无法解决问题。
看起来
torchvision
和 torchaudio
与您当前的 torch
版本不兼容。尝试使用以下命令安装 pytorch 的稳定版本(2.0.1):
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
或从 https://pytorch.org/get-started/locally/生成所需的组合。
另请参阅我对类似问题的其他回答。