[Bug]使用Transformers 微调 Whisper出现版本不兼容的bug

错误的现象

ImportError Traceback (most recent call last)

<ipython-input-20-6958d7eed552> in ()

from transformers import Seq2SegTrainingArguments

training_args = Seq2SeqTrainingArguments(

output_dir="./whisper-small-hi", # change to a repo name of your choice

per_device_train_batch_size=16,

/usr/local/lib/python3.1o/dist-packages/transformers/training_args-py in_setup_devices(self)

if not is_sagemaker_mp_enabled():

if notis_accelerate_available():

raise ImportError(

f"Using the`Trainer`with^PyTorch`requires `accelerate>={ACCELERATE_MIN_VERSION}`:"

"please run `pip install transformers[torch]` or `pip install accelerate -U`

ImportError: Using the^Trainer` with `PyTorch` requires `accelerate>=0.21.0`: Please run `pip install transformers[torch]` or `pip install accelerate -U`

原因分析

看上去accelerate包的依赖没有导入,或者是版本不太匹配。

我先按照他的建议执行了

pip install transformers[torch]

pip install accelerate -U

这两个命令,但是都不管用。

分析一下提到的每个包的作用

transformers

accelerate

PyTorch

依赖分析结果是

accelerate 来管理 transformers 模型的分布式训练和混合精度训练,他们都依赖PyTorch 来执行底层操作。

OK,一步步尝试吧

尝试解决

我做了多次尝试如下,

复制代码
import transformers
import accelerate
import torch

accelerate.__version__,transformers.__version__,torch.__version__
复制代码
('0.30.1', '4.42.0.dev0', '2.3.0+cu121')
复制代码
('0.30.1', '4.41.2', '2.3.0+cu121')
复制代码
('0.21.0', '4.41.2', '2.3.0+cu121')

经过多次尝试,最后一次的版本好能走通。

新问题

下一步的时候又有新错误:

复制代码
from transformers import Seq2SeqTrainer
 
trainer = Seq2SeqTrainer(
    args=training_args,
    model=model,
    train_dataset=common_voice["train"],
    eval_dataset=common_voice["test"],
    data_collator=data_collator,
    compute_metrics=compute_metrics,
    tokenizer=processor.feature_extractor,
)
复制代码
TypeError                                 Traceback (most recent call last)
<ipython-input-26-ec450b16962e> in <cell line: 3>()
      1 from transformers import Seq2SeqTrainer
      2 
----> 3 trainer = Seq2SeqTrainer(
      4     args=training_args,
      5     model=model,
/usr/local/lib/python3.10/dist-packages/transformers/trainer.py in create_accelerator_and_postprocess(self)
   4533 
   4534         # create accelerator object
-> 4535         self.accelerator = Accelerator(**args)
   4536         # some Trainer classes need to use `gather` instead of `gather_for_metrics`, thus we store a flag
   4537         self.gather_function = self.accelerator.gather_for_metrics

TypeError: Accelerator.__init__() got an unexpected keyword argument 'use_seedable_sampler'

最终可用版本

重新尝试了下面新的依赖:

!pip install torch==2.2.0

!pip install accelerate==0.27.2

复制代码
('0.27.2', '4.41.2', '2.3.0+cu121')

终于成功了!

注意,每次尝试新的版本,都要重启启动整个计算资源,这样新的版本才会生效,建议最上面导入资源的时候指定版本

哎,这玩意真难啊,本来版本不会是太大的问题,奈何菜鸟碰到的问题多啊!

相关推荐
吃货界的硬件攻城狮16 小时前
【BUG】记STM32F030多通道ADC DMA读取乱序问题
stm32·嵌入式硬件·bug
星释16 小时前
Yii2项目自动向GitLab上报Bug
前端·gitlab·bug·yii
upp2 天前
【bug】Error: /undefinedfilename in (/tmp/ocrmypdf.io.9xfn1e3b/origin.pdf)
ubuntu·pdf·bug·ghostscript
杨过姑父2 天前
部署开源版禅道,修改apache端口无效解决
bug·apache·软件工程·issue
chao_7893 天前
针对“仅某个地区出现Bug”的原因分析与解决方案
测试用例·bug
帅帅哥的兜兜3 天前
Bug问题
bug
养意3 天前
git提交代码和解决冲突修复bug
git·bug
东方不败之鸭梨的测试笔记4 天前
20250605车充安服务器受木马攻击导致服务不可用
bug
Htht1114 天前
【Qt】之【Get√】【Bug】通过值捕获(或 const 引用捕获)传进 lambda,会默认复制成 const
数据库·bug
前端发现4 天前
如何用 pnpm patch 给 element-plus 打补丁修复线上 bug(以 2.4.4 修复 PR#15197 为例)
bug