Chapter 09
多模态:NeVA / SpeechLLM / 视觉与语音
NeMo 是当前主流训练框架里多模态覆盖最全的——除了 LLM,还包括 ASR、TTS、视觉、语音 LLM。本章蜻蜓点水带一下这一面。
9.1NeMo 多模态全家谱
| 模态 | 子模块 | 典型任务 |
|---|---|---|
| 文本 LLM | collections.llm | GPT / Llama 训练 |
| 视觉 LLM | collections.vlm | NeVA / LLaVA-style |
| 语音 LLM | collections.speechlm | SALM / BESTOW |
| ASR | collections.asr | Conformer / Parakeet / Canary |
| TTS | collections.tts | FastPitch / Mixer-TTS / VITS |
| 多模态扩散 | collections.multimodal | Stable Diffusion / DiT / Sora-style |
9.2NeVA:NVIDIA 自家的视觉 LLM
NeVA = NeMo Vision-and-language Assistant,是 LLaVA 架构的 NVIDIA 实现,特点是用 Megatron-Core 训练,扩展性比 LLaVA 原版好。
架构
┌──────────────┐ ┌──────────────┐
│ Vision │ │ LLM │
│ Encoder │ ───▶ │ (e.g. Llama) │
│ (CLIP/SigLIP)│ MLP │ │
└──────────────┘ proj └──────────────┘
│ │
└──── image tokens + text tokens ────▶ output
训两阶段
- Pre-training:冻结 LLM 和 vision encoder,只训 MLP projector;
- Instruction tuning:解冻 LLM,全模型训。
python examples/multimodal/multimodal_llm/neva/neva_pretrain.py \
--config-path conf --config-name llava_v1_5_7b
python examples/multimodal/multimodal_llm/neva/neva_finetune.py \
--config-path conf --config-name llava_v1_5_7b_finetune
9.3SpeechLLM:语音版 LLM
把 ASR encoder 的输出当 token 喂给 LLM,让 LLM 直接听语音回答。NeMo 提供两个变体:
- SALM(Speech-Augmented Language Model):ASR encoder + LLM;
- BESTOW:cross-attention 风格融合,效果更好。
python examples/multimodal/speech_llm/modular_audio_gpt_train.py \
--config-name modular_audio_gpt_config \
model.pretrained_audio_model=stt_en_fastconformer_transducer_large \
model.pretrained_llm_model=./llama3_8b.nemo
9.4ASR:Conformer 和后续
NeMo ASR 是这个领域的事实标准之一,2020 后多次 SOTA。模型谱系:
- Conformer-CTC / Transducer:标准 ASR 模型;
- Parakeet:2024 NVIDIA 自家 ASR,效果接近 Whisper;
- Canary:多语言 ASR + 翻译,1B 参数;
- FastConformer:训练快 3-4×。
9.5TTS
主要模型:
- FastPitch:非自回归 TTS,快;
- VITS:高质量自回归 TTS;
- Mixer-TTS:轻量级;
- RAD-TTS:研究用,神经声学模型。
9.6本书后续章节不深入多模态
多模态每个分支都能单独写一本书,本章只做总览。重点章节安排:
- 视觉 LLM 想深入 → 看 NeMo docs/multimodal/;
- ASR/TTS 想深入 → 看 NeMo docs/asr/ 和 docs/tts/;
- 本书后续 ch10-ch13 继续聚焦 LLM 训练栈。
9.7SALM:当前 NeMo 仓库里真实的多模态 LLM
本书第 1 章提到 NeMo 2.x 仓库现在专注语音 + 语音 LLM。真正能跑、有完整代码的多模态模型是 SALM(Speech-Audio-Language Model)。源码位置:
| 文件 | 用途 |
|---|---|
nemo/collections/speechlm2/models/salm.py | SALM 主类(Lightning + HFHubMixin) |
nemo/collections/speechlm2/models/salm_automodel.py:45 | SALMAutomodel:FSDP2/DTensor 版本 |
nemo/collections/speechlm2/models/salm_asr_decoder.py | 专门给 ASR 任务用的 decoder |
nemo/collections/speechlm2/data/salm_dataset.py | 音频-文本配对数据集 |
nemo/collections/speechlm2/parts/automodel_lora.py:27 | make_peft_config():装 LoRA |
nemo/collections/speechlm2/parts/optim_setup.py | configure_optimizers 实现 |
examples/speechlm2/salm_train.py:28 | 训练入口(@hydra_runner) |
9.8SALM 架构:encoder + adapter + LLM
看 salm.py 的 configure_model(),组装方式:
- Speech encoder:默认 NVIDIA Canary / Parakeet(
parts/pretrained.py:setup_speech_encoder()); - Adapter:把 encoder 的 hidden 投到 LLM hidden 维(小 MLP / Q-Former / 简单 Linear 都可配);
- LLM 主体:可加载任意 HF causal LM(Llama / Nemotron / Qwen),
load_pretrained_hf(); - 训练目标:standard CE(next-token),可选 auxiliary loss;
- 推理:
generate()调 HF 的generate_ids。
9.9FSDP2 + DTensor(不用 Megatron 的多卡训练)
NeMo 2.x 在语音模型这条线不依赖 Megatron-Core,纯 PyTorch FSDP2 + DTensor。看 parts/parallel.py:参数分片到所有 rank,forward all-gather,backward reduce-scatter,显存接近 ZeRO-3。_embed_tokens()(salm_automodel.py:91)等基础算子用 DTensor 自动处理切片 + 集合通信。启动:torchrun --nproc_per_node=8 examples/speechlm2/salm_train.py。SLURM / K8s 用 nemo-run 包装 sbatch。
9.10语音子模块速览
| collection | 代表模型 / 模块 |
|---|---|
nemo/collections/asr/ | Canary / Parakeet / Citrinet / Conformer-CTC |
nemo/collections/tts/ | FastPitch / HiFi-GAN / VITS |
nemo/collections/audio/ | audio-to-audio(去噪 / 增强 / 分离) |
nemo/collections/speechlm2/ | ★ SALM 多模态 LLM + Duplex(S2S 双向) |
nemo/agents/voice_agent/ | 2026 新 Voice Agent(streaming STT+LLM+TTS) |
9.11这章你需要带走的
- NeMo 多模态覆盖:VLM + SpeechLLM + ASR + TTS + 多模态扩散;
- NeVA = LLaVA 的 NeMo 实现,两阶段训练(projector → 全模型);
- SpeechLLM 把 ASR encoder 输出当 token 给 LLM;
- ASR / TTS 是 NeMo 老牌强项,Parakeet / Canary 是 2024 sota。