Coder Social home page Coder Social logo

yeyupiaoling / whisper-finetune Goto Github PK

View Code? Open in Web Editor NEW
681.0 8.0 107.0 5.68 MB

Fine-tune the Whisper speech recognition model to support training without timestamp data, training with timestamp data, and training without speech data. Accelerate inference and support Web deployment, Windows desktop deployment, and Android deployment

License: Apache License 2.0

Python 6.87% CSS 0.10% JavaScript 0.57% HTML 0.36% Shell 0.41% Kotlin 2.52% Makefile 0.11% C 74.25% C++ 14.80%
asr ctranslate2 huggingface whisper lora speech-recognition transformers chinese pytorch android web

whisper-finetune's Issues

Expected all tensors to be on the same device, but found at least two devices

  warnings.warn("None of the inputs have requires_grad=True. Gradients will be None")
/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/bitsandbytes/autograd/_functions.py:298: UserWarning: MatMul8bitLt: inputs will be cast from torch.float32 to float16 during quantization
  warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
Traceback (most recent call last):
  File "finetune.py", line 124, in <module>
    trainer.train(resume_from_checkpoint=args.resume_from_checkpoint)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/transformers/trainer.py", line 1662, in train
    return inner_training_loop(
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/transformers/trainer.py", line 1929, in _inner_training_loop
    tr_loss_step = self.training_step(model, inputs)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/transformers/trainer.py", line 2699, in training_step
    loss = self.compute_loss(model, inputs)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/transformers/trainer.py", line 2731, in compute_loss
    outputs = model(**inputs)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/peft/peft_model.py", line 281, in forward
    return self.get_base_model()(*args, **kwargs)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/accelerate/hooks.py", line 165, in new_forward
    output = old_forward(*args, **kwargs)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/transformers/models/whisper/modeling_whisper.py", line 1435, in forward
    loss = loss_fct(lm_logits.view(-1, self.config.vocab_size), labels.reshape(-1))
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/torch/nn/modules/loss.py", line 1174, in forward
    return F.cross_entropy(input, target, weight=self.weight,
  File "/home/ybZhang/miniconda3/envs/whister/lib/python3.8/site-packages/torch/nn/functional.py", line 3026, in cross_entropy
    return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:0! (when checking argument for argument target in method wrapper_nll_loss_forward)
  0%|

训练过程占用显存过高的问题

你好,我在使用large模型进行微调,之前使用的huggingface的脚本,在单卡上设置batch_size=16 A100 80G的显存也是够的,但是我使用咱们脚本时只能设置batch_size=4 (63G),这部分怎么改进? 多谢

微调时的奇怪问题,训练集变大之后,准确度反而下降了

我实现现场录音微调whisper,发现一个棘手的问题,我首次采集了30份录音,拿前3个录音作为测试集,后27份作为训练集,训练集大概5小时,训练了一个模型。然后我又增加了30份录音到训练集,测试集没变,结果最终准确率还不如第一个模型。理论上来说训练数据越多,模型准确率是会提升的,不知道哪位高手有遇到过类似问题,请给与指点。另外使用wav格式的数据集跟使用mp3格式的数据集对模型有影响吗?

如何转换V3版本

使用ct2-transformers-converter如何转换V3版本的格式,出现错误提示:
Traceback (most recent call last):
File "/home/anaconda3/envs/Whisper-finetune/bin/ct2-transformers-converter", line 8, in
sys.exit(main())
File "/home/anaconda3/envs/Whisper-finetune/lib/python3.9/site-packages/ctranslate2/converters/transformers.py", line 1771, in main
converter.convert_from_args(args)
File "/home/anaconda3/envs/Whisper-finetune/lib/python3.9/site-packages/ctranslate2/converters/converter.py", line 50, in convert_from_args
return self.convert(
File "/home/anaconda3/envs/Whisper-finetune/lib/python3.9/site-packages/ctranslate2/converters/converter.py", line 89, in convert
model_spec = self._load()
File "/home/anaconda3/envs/Whisper-finetune/lib/python3.9/site-packages/ctranslate2/converters/transformers.py", line 98, in _load
config = transformers.AutoConfig.from_pretrained(
File "/home/anaconda3/envs/Whisper-finetune/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py", line 1034, in from_pretrained
config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/anaconda3/envs/Whisper-finetune/lib/python3.9/site-packages/transformers/configuration_utils.py", line 620, in get_config_dict
config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/anaconda3/envs/Whisper-finetune/lib/python3.9/site-packages/transformers/configuration_utils.py", line 675, in _get_config_dict
resolved_config_file = cached_file(
File "/home/anaconda3/envs/Whisper-finetune/lib/python3.9/site-packages/transformers/utils/hub.py", line 400, in cached_file
raise EnvironmentError(
OSError: whisper-large-v3 does not appear to have a file named config.json. Checkout 'https://huggingface.co//whisper-large-v3/None' for available files.

训练发生异常

使用项目中的代码微调的时候发生如下异常,不知道是什么原因,我使用的是audiofolder数据集:

File "/usr/local/lib/python3.10/dist-packages/peft/peft_model.py", line 442, in forward
    return self.get_base_model()(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/transformers/models/whisper/modeling_whisper.py", line 1486, in forward
    outputs = self.model(
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/transformers/models/whisper/modeling_whisper.py", line 1346, in forward
    encoder_outputs = self.encoder(
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/transformers/models/whisper/modeling_whisper.py", line 896, in forward
    inputs_embeds = nn.functional.gelu(self.conv1(input_features))
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/conv.py", line 313, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/conv.py", line 309, in _conv_forward
    return F.conv1d(input, weight, bias, self.stride,
RuntimeError: Given groups=1, weight of size [1280, 80, 3], expected input[1, 8, 3000] to have 80 channels, but got 8 channels instead

微调在WhisperProcessor.from_pretrained调用时就报错

我使用单卡训练,一启动就报错:
Traceback (most recent call last):
File "/workspace/Whisper-Finetune-master/finetune.py", line 47, in
processor = WhisperProcessor.from_pretrained(args.base_model,
File "/opt/conda/lib/python3.10/site-packages/transformers/processing_utils.py", line 228, in from_pretrained
args = cls._get_arguments_from_pretrained(pretrained_model_name_or_path, **kwargs)
File "/opt/conda/lib/python3.10/site-packages/transformers/processing_utils.py", line 272, in _get_arguments_from_pretrained
args.append(attribute_class.from_pretrained(pretrained_model_name_or_path, **kwargs))
File "/opt/conda/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 2024, in from_pretrained
return cls._from_pretrained(
File "/opt/conda/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 2249, in _from_pretrained
init_kwargs[key] = added_tokens_map.get(init_kwargs[key], init_kwargs[key])
TypeError: unhashable type: 'dict'
这个是怎么回事,是哪里搞错了吗?

123

tensorflow.python.framework.errors_impl.FailedPreconditionError: output/基础模型 is not a directory

关于DataCollatorSpeechSeq2SeqWithPadding的一处问题

我在使用这个库微调的时候发现报错,后来检查发现有一处:
input_features = [{"input_features": feature["input_features"][0]} for feature in features]
正确应该是
input_features = [{"input_features": feature["input_features"]} for feature in features]

如何随机化模型参数,从头开始训练

你好,如果我想从头开始训练,如何对加载的模型参数进行随机化?

获取模型

model = WhisperForConditionalGeneration.from_pretrained(args.base_model,
load_in_8bit=args.use_8bit,
device_map=device_map,
local_files_only=args.local_files_only)

性能和效果?

老哥,描述里的评价指标是微调后的whisper-tiny对于中文的识别吗?
中文识别方面的速度咋样?

识别长音频问题

你好,我按照你的文档教程,使用large-v2模型在aishell数据集上训练得到了一个模型,然后使用infer.py识别一个2min45s的长音频时,只输出了第一句话。使用infer_ct.py时也只输出了第一句话和中间的2句话。请问这是什么问题呢?我用是5月11号的代码,最新代码的 max_audio_len参数能否解决这个问题呢?

accelerate方式训练是否支持deepspeed?

很好的项目,Star了

请教下使用accelerate方式多卡训练时,是否支持deepspeed的ZERO stage优化显存占用?我这边单卡显存太小了,无法开更多的batch size
谢谢

微調後的模型在其他語言的效果降低了??

嗨, 大佬,
先感謝您開源了這麼棒的專案,

我成功的利用中文音頻來fine-tune模型,

但因為在訓練代碼跟預測代碼都需指定language='zh',

造成若中英夾雜或是一串中文中有數字時,

無法像沒有fine-tune前的模組一樣表現得很好,

例如 編號89757, fine-tune後可能就會變成'編號巴舅漆舞漆'
請問有什麼辦法解決嗎? 或是可以在預測時不指定語言?

謝謝您!

使用lora微调时遇到的奇怪问题

我使用A40(40GB)显卡使用20小时的多语言数据集微调large-v2,在使用了LORA之后没有看到显存和速度方面的优化,具体情况如下:

  1. 使用lora,加载模型的时候不使用8位,直接oom
  2. 使用lora,加载模型的时候的使用8位,需要3.5小时
  3. 全参数微调的时候,需要4小时,不过是加了 gradient_checkpointing = True以减少显存消耗,不然也是oom
    实测的情况是LORA并不能起到加速训练和减少显存使用。lora训练的时候参数打印是1.35%,不知道大家有没有遇到过。下面是是用来为微调的笔记本:
    colab
    希望高手指点一下。

关于whisper微调

您好,最近开始关注语音转文字这一块,我使用原始的large-v2模型进行语音转文字,基本不会出现语气词和结巴导致出现的重复词,但是按照您这个微调之后,出现了这类转文字情况,但是我看语料里面也没有教模型去识别语气词,是什么原因呢?

whisper large v3 Fine-Tune 後變得不太能辨識語音

Fine-Tune 前

[0.00s > 18.94s] 大家報告一下上週的進度
[19.20s > 21.50s] 上週主要在PPC
[21.76s > 26.12s] AVAP這邊是用那個AML模型建立生存的
[26.12s > 29.20s] 預測模型來看它的效果
[29.44s > 31.24s] 那一開始就是如上週報告
[31.50s > 34.56s] 有測試的就是不同初始值會對模型的影響
[34.82s > 36.10s] 這邊是使用同一個
[36.36s > 37.90s] 深度的模型來測試
[38.40s > 41.22s] 那測試的結果是明顯的
[41.48s > 45.06s] 初始的權重會對模型的表現性影響很大
[45.58s > 46.86s] 那這邊
[47.12s > 49.68s] 分別就是使用了三種不同的初始權重
[50.18s > 54.54s] 那他們雖然在同一個架構一層的hidden layer下面
[54.80s > 55.30s] 他們的
[55.56s > 56.08s] 表現性
[56.38s > 57.66s] 還是有明顯的不同
[58.94s > 60.48s] 等於說這是什麼專案
[60.72s > 61.76s] 這個是
[62.00s > 64.06s] 這邊是用
[64.56s > 65.84s] PVTC的
[66.10s > 66.62s] 數據
[67.12s > 69.44s] 你現在在研究的這個專案是哪一個
[69.68s > 70.46s] 現在
[70.96s > 72.24s] 這個的專案就是
[72.76s > 77.12s] 因為PVTC跟VAEP都要想要用CVAE的生成方式
[77.62s > 83.26s] 但是因為CVAE那邊生成的數據還是需要一個模型去驗證
[83.52s > 85.04s] 出來它的數據預測準不準
[85.56s > 86.08s] 那目前就是
[86.32s > 87.92s] 生成這邊就先放置然後來
......

Fine-Tune 後

[21.76s > 25.86s] ,
[25.86s > 55.86s] 的預測模型來看它的效果 那測試的結果是 明顯的初始的權重會對模型的表現性影響很大 那這邊分別就是使用的三種不同的初始權重 那他們雖戾一層的械類的下面 他們的表現

Fine-Tune 輸入資料格式

# decode 前
[ 50258, 50260, 50359, 50363, 25583, 5000, 13331, 252, 4511, 5884, 44, 25729, 27735, 50257 ]
# decode 後
'<|startoftranscript|><|zh|><|transcribe|><|notimestamps|>還是他塞到我們MongoDB<|endoftext|>'

相關套件版本

numba
numpy>=1.23.1
soundfile>=0.12.1
librosa>=0.10.0
dataclasses>=0.6
transformers>=4.35.0
bitsandbytes>=0.41.0
datasets>=2.11.0
evaluate>=0.4.0
ctranslate2>=3.21.0
faster-whisper>=0.10.0
jiwer>=2.5.1
peft>=0.6.2
accelerate>=0.21.0
zhconv>=1.4.2
tqdm>=4.62.1
soundcard>=0.4.2
uvicorn>=0.21.1
fastapi>=0.95.1
starlette>=0.26.1
tensorboardX>=2.2
tiktoken==0.3.3
openai-whisper>=20231117
notebook==6.5.4
jupyterlab==4.0.2
pydub>=0.25.1
openpyxl>=3.1.2
setuptools-rust
more-itertools

這個流程在 fine-tune whisper-large-v2 都沒什麼問題,但是換成 large-v3 的時候就會出現上述的問題,請問我到底是哪個環節出了問題?

关于微调模型的问题

你好,有个问题想请教一下:
现在whisper不支持某个领域的专有名词,是否可以通过增加部分专有数据到现有的开源中文数据中,构成新的数据集,然后进行微调,实现对这些专有词汇的支持,如果这个方案可行的话,应该需要多少的数据量能达到较好的效果呢?并且对采集的音频数据有啥要求呢?
期待答复,不胜感激。

LoRA参数

使用finetune.py里的LoRA参数跑出来的收敛曲线跟AdaLoRA差异比较大,这是符合预期的吗?有能跟AdaLoRA收敛差不多的LoRA参数么?
图片

Error: libcudnn_ops_infer.so.8

我在CUDA version:12.0的服务器上,调用 whisper-large-v2-finetune-ct2模型,通过infer_ct2.py进行测试报了如下错误:

"Could not load library libcudnn_ops_infer.so.8. Error: libcudnn_ops_infer.so.8: cannot open shared object file: No such file or directory
Please make sure libcudnn_ops_infer.so.8 is in your library path!
Aborted"

有人遇到过类似问题吗?原因是什么?具体怎么解决的?

Keyword arguments {'sampling_rate': 16000} not recognized.

python finetune.py --base_model=openai/whisper-base --output_dir=output/
執行上述程式遇到的問題
程式不會中斷 但是會一直顯示

請問我是資料的問題嗎
Keyword arguments {'sampling_rate': 16000} not recognized.
我的資料格式如下 :

[
    {
        "audio": {
            "path": "/mnt/datadisk/ovien_lee/Tai_testsets/aishell_test/wav/BAC009S0769/BAC009S0769W0461.wav"
        },
        "sentence": "撿拾一些冰塊回家冰凍保存",
        "language": "Chinese",
        "duration": 4.1803125,
        "sampling_rate": 16000
    },
    {
        "audio": {
            "path": "/mnt/datadisk/ovien_lee/Tai_testsets/aishell_test/wav/BAC009S0769/BAC009S0769W0482.wav"
        },
        "sentence": "但問題至今沒有解決",
        "language": "Chinese",
        "duration": 3.20325,
        "sampling_rate": 16000
    },
    {
        "audio": {
            "path": "/mnt/datadisk/ovien_lee/Tai_testsets/aishell_test/wav/BAC009S0769/BAC009S0769W0312.wav"
        },
        "sentence": "浪潮官方尚未給出回應",
        "language": "Chinese",
        "duration": 3.8673125,
        "sampling_rate": 16000
    },............................

多卡训练爆ram

按照博主的方式去做多卡ddp训练。设备是三张V100, 显存32GB,在openai-medium的基础上做微调爆ram了。
请问应该如何调参才可以避免这个问题,或者说这个配置不适合finetune medium模型呢?

Tue Aug  8 15:44:49 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.125.06   Driver Version: 525.125.06   CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla V100-PCIE...  Off  | 00000000:3B:00.0 Off |                    0 |
| N/A   27C    P0    26W / 250W |      9MiB / 32768MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  Tesla V100-PCIE...  Off  | 00000000:AF:00.0 Off |                    0 |
| N/A   26C    P0    25W / 250W |      9MiB / 32768MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   2  Tesla V100-PCIE...  Off  | 00000000:D8:00.0 Off |                    0 |
| N/A   26C    P0    24W / 250W |      9MiB / 32768MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

训练集 num_rows: 8806
验证集 num_rows: 1105

正常数据和空数据一起训练的格式

你好,如果我使用正常标注(没有时间戳)和空数据一起训练,下面的格式是否正确:
{"audio": {"path": "dataset/0.wav"},"sentence": "近几年,不但我用书给女儿压岁,也劝说亲朋不要给女儿压岁钱,而改送压岁书。","language": "Chinese"} -- 正常标注
{"audio": {"path": "dataset/1.wav"},"sentence": ""} -- 空音频或者背景音

多谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.