wenet-e2e / wenet

Production First and Production Ready End-to-End Speech Recognition Toolkit
https://wenet-e2e.github.io/wenet/
Apache License 2.0
3.89k stars 1.04k forks source link

[feats/llm]语音大模型背景下的llm集成 #2142

Open Mddct opened 7 months ago

Mddct commented 7 months ago

现状

语音大模型是一方面https://github.com/wenet-e2e/wenet/issues/2097, 另外一个路子是和llm的结合, 后者目前paper 日益增多, 缺少合语音、llm的一体的简单易于diy/研究的repo

在此有个想法,wenet集成llm 比如llama

宗旨

  1. 数据、模型、代码全部都会开源开放,欢迎大家贡献,有数据的出数据,有意见的出意见,有机器的出机器,大家共创。
  2. 且做且分析

目标

  1. base 当前/未来语音大模型https://github.com/wenet-e2e/wenet/issues/2097/ + xxx llm, 构造Audio+LLM的语音语言打模型,unify all speech task + speech multi-round chat ability
  2. 积累语音所有任务的数据以及构造audio instruct/prompt数据

Action

数据

训练

部署

目前可行方案,

robin1001 commented 7 months ago

可以的,我们之前的思路是:

  1. 模型放大,简单粗暴,大就是强。
  2. LLM based,站在巨人的肩膀。
  3. 在语音任务中直接引入 LLM 的方法,让语音模型直接有理解能力。

目前在做的是1,在做 1 的生态和基础设施。2 确实现在出现了很多的 paper,是新的研究热点。以前的思路是资源有限,先做 1,1 和 2 本质上是不冲突的,社区有资源的话,可以都搞起来。

xingchensong commented 7 months ago

周哥可以针对这条路线,起草个计划,我们给你打工

Mddct commented 7 months ago

周哥可以针对这条路线,起草个计划,我们给你打工

大佬谦虚了 , 我给你打工

我先整理下这方面的最新成果, 看能不能抽出共性东西, 再写个TODO (现在功力不够)

xingchensong commented 7 months ago

提一个,tokenizer可能需要重构一下,现在有两种模式,一种是纯词表模式,一种是bpe模式,未来肯定还会有适配LLM的模式,这样就是三种模式了,需要重新构建下代码

Mddct commented 7 months ago

step1: support wenet llama2, Adhering to the principle of maximizing reuse of wenet code

Features

xingchensong commented 7 months ago

我在想,直接import transformers行不行,和自己重新实现一遍,各有什么pros & cons

Mddct commented 7 months ago

我在想,直接import transformers行不行,和自己重新实现一遍,各有什么pros & cons

第一步先单纯imoort transformers 后边再看会有什么问题,上边那个列表先列那里了。

缺点是: 不好魔改,比如阿里的通义audio 会有个model parallel ,hugface封装过厚 fintune audio llm 如果需要对llm做些改动 需要去hug里去改。而且输入输出需要符合hg的接口

robin1001 commented 7 months ago

+1,我觉得对于文本大模型的支持,直接 import transformer,不需要重复造轮子了。

xingchensong commented 7 months ago

https://github.com/espnet/espnet/pull/4099 this might be a reference for integrating hugginface

Mddct commented 7 months ago

hg的llm模型 几乎是下边伪代码pattern


from transformers import CasulLM...

tokenizer = from_pretrain

tokenizer.add_special_tokens

# 这里dataset 包含mask的计算
dataset = ...

model = from_pretain 

# 这里可以构造和语音id或emb的input+ text 给model, 包含att mask
output = model(....)

calac loss

model.generate for base

model.chat for chat
xingchensong commented 7 months ago

提一个,tokenizer可能需要重构一下,现在有两种模式,一种是纯词表模式,一种是bpe模式,未来肯定还会有适配LLM的模式,这样就是三种模式了,需要重新构建下代码

This might be a reference for refactoring tokenizer https://github.com/espnet/espnet/tree/master/espnet2/text

Mddct commented 7 months ago

hg的llm模型 几乎是下边伪代码pattern

from transformers import CasulLM...

tokenizer = from_pretrain

tokenizer.add_special_tokens

# 这里dataset 包含mask的计算
dataset = ...

model = from_pretain 

# 这里可以构造和语音id或emb的input+ text 给model, 包含att mask
output = model(....)

calac loss

model.generate for base

model.chat for chat

cv有篇工作,https://arxiv.org/pdf/2311.03079.pdf

Screenshot 2023-11-23 at 14 53 15

该做法整体看,和通义audio相似,区别在于他给llm 加了个cross attention, 这里涉及到了对llm的修改

xingchensong commented 7 months ago

涉及到修改的可不可以通过下面的方式:

from transformers import XXXModelForCasulLM
from wenet.transformer.asr_model import AsrModel

class NewModel(nn.Module, AsrModel, XXXModelForCasulLM):
    def __init__(self, ...):
        # init father
        super().__init__()
        # add new member if needed, i.e.,
        self.new_member = nn.Identity()

    def forward(self, ...):
        # overwrite father
        pass

    # overwrite other functions if needed, i.e., function from XXXModelForCasulLM
    def from_pretrained(self, ...):
        pass

    # overwrite other functions if needed, i.e., function from AsrModel
    def _cal_att_loss(self, ...):
        pass
Mddct commented 7 months ago

涉及到修改的可不可以通过下面的方式:

from transformers import XXXModelForCasulLM
from wenet.transformer.asr_model import AsrModel

class NewModel(nn.Module, AsrModel, XXXModelForCasulLM):
    def __init__(self, ...):
        # init father
        super().__init__()
        # add new member if needed, i.e.,
        self.new_member = nn.Identity()

    def forward(self, ...):
        # overwrite father
        pass

    # overwrite other functions if needed, i.e., function from XXXModelForCasulLM
    def from_pretrained(self, ...):
        pass

    # overwrite other functions if needed, i.e., function from AsrModel
    def _cal_att_loss(self, ...):
        pass

+1 也倾向于这种

Mddct commented 7 months ago

gemini 是最近谷歌发布的多模态模型,支持语音输入

文中提到了语音输入还是经过”USM“化, 输入LLM 从头pretrain

image

(NOTE: 区别图片patch, 无预训练比如vit, 直接patch 输入)

该形式和通义之类的实现是类似的(区别解释通义的mutli task),个人觉得咱们可以搞搞这类实现的代码框架

@robin1001 @xingchensong

TODO:

如果上述实现,即使不训练,也可以load 通义audio的开源模型

Mddct commented 5 months ago

https://arxiv.org/abs/2402.01831