[English] | 中文版
ZipRWKV-Speech is a Speech-LLM based Automatic Speech Recognition (ASR) system. Its core architecture utilizes Zipformer as the speech encoder, integrated with RWKV7 as the language model backbone.
[!IMPORTANT]
Research Phase Disclaimer: This project is currently in the experimental/development stage and serves primarily as a personal implementation record. The codebase draws from several open-source projects (such as NeMo, K2, and RWKV), extracting and simplifying key components to create a lightweight yet high-performance SpeechLLM framework. Each module contains its own README to explain the implementation logic.
-
Speech Encoder: Zipformer (from K2/Icefall), providing efficient downsampling and feature extraction.
-
LLM Backbone: RWKV7, combining the inference efficiency of RNNs with the training performance of Transformers.
-
Data Pipeline: A dynamic bucketing system based on Lhotse.
Current progress on code organization and implementation:
- Data Pipeline (Lhotse-based)
- Support for NeMo-style Manifest loading.
- Implementation of
DynamicBucketingSamplerfor dynamic Batch Size adjustment. - Integration of
Cutset.muxfor weighted multi-source data mixing. - On-the-fly data augmentation (Speed, Volume, Noise, SpecAugment).
- test dataset code and
conf.yaml. - noise manifest prepare script.
- Model Architecture
- Zipformer Encoder integration and test code.
- RWKV7 and PEFT (Parameter-Efficient Fine-Tuning) integration.
- projector (MLP and rwkv)
- Training Implementation
- PyTorch Lightning Training Module.
- Checkpoints & Evaluation
- Release of pre-trained model weights.
- Python 3.10
- CUDA 12.8
- PyTorch 2.8
Download the K2 wheel file that matches your environment configuration:
wget https://k2-fsa.github.io/k2/cuda.html
wget k2-1.24.4.dev20250807+cuda12.8.torch2.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whlSometimes the + character in the filename may be converted to %2B after download. You need to rename it back to +:
# If the filename contains %2B, change it to +
# Original filename: k2-1.24.4.dev20250807%2Bcuda12.8.torch2.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
# New filename: k2-1.24.4.dev20250807+cuda12.8.torch2.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whlInstall the wheel package using uv pip:
uv pip install "k2-1.24.4.dev20250807+cuda12.8.torch2.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl"This project uses AudenAI/auden-encoder-tta-m10 as the encoder for Zipformer.
Encoder Output to Tokens
After audio encoding (Fbank → Encoder), the encoder output features are processed through a projector that performs downsampling:
- Encoder output shape:
(B, T, encoder_out_dim)where T = audio_seconds × 25 - After projector downsampling:
(B, T//2, lim_dim) - Resulting temporal resolution: ~12.5 Hz
- Each token represents 80ms of audio
- Typical Chinese character duration: 0.2~0.3 seconds
- Tokens per character: 2~4 tokens
Model-Specific Prompt Formats
Different pre-trained LLM models require different prompt structures, which are already defined during their training:
- RWKV7: Simple format like
User:andAssistant: - Qwen: Special tokens such as
<|im_start|>and<|im_end|> - ASR-specific prompts: Common Chinese prompts include "請轉錄這段{lang}語音" (Please transcribe this {lang} audio)
Additional information: Some papers have also proposed a prompt projector module to address the impact of prompts. Reducing Prompt Sensitivity in LLM-based Speech Recognition Through Learnable Projection
Prompt Projector Alternative
Recent papers have proposed using a simpler approaches work well in practice:
- A straightforward special token like
<|en|>(or<|zh|>for Chinese) is often sufficient - This lightweight approach reduces computational overhead while maintaining effectiveness
- Language specification helps the model adapt its decoding strategy appropriately
Embedding Concatenation Strategy
The key to the entire system is simple concatenation:
- Downsampled audio features: Shape
(B, T//2, lim_dim) - Text embeddings: Various prompt tokens and assistant markers
- Concatenation: Place audio features immediately after the
User:embedding - Combined input:
[User_emb] + [Audio_tokens] + [Assistant_emb] + [Label_emb]with total shape(B, seq_len, lim_dim)
Training vs. Inference Difference
-
Training:
- Concatenate orange portion + green portion
- Feed the entire sequence to the LLM for forward pass
- Compute loss on the green portion to train the model
-
Inference:
- Only the orange portion is needed
- The green portion is generated by the LLM's autoregressive decoding
- No need to provide target text at inference time
The elegance of this approach lies in its simplicity:
- Downsampling creates naturally-aligned tokens (~80ms each) that correspond well with phonetic units
- Prompt design is straightforward and model-dependent; language indicators are sufficient
- Fusion is simply concatenation of embeddings in a specific order
- Training/Inference asymmetry leverages the LLM's inherent ability to generate text autoregressively
By combining downsampled audio features with carefully formatted text prompts, the system enables LLMs to perform effective end-to-end ASR without complex architectural modifications.
In LLM-based ASR systems, the projector serves as a critical bridge between the audio encoder and the LLM. Its role is to downsampe and transform audio features into the embedding space of the LLM. This guide introduces common projector architectures and practical implementation insights.
When designing projectors for LLM-based ASR, three main architectures are commonly used, typically combined with downsampling mechanisms:
- Simple fully-connected layers
- Lightweight and computationally efficient
- Direct mapping from encoder output to LLM embedding space
- Example: Fun-ASR implementation
- Adds sequential modeling capacity
- Can capture temporal dependencies in audio features
- Slightly higher computational cost than MLP
- Cross-attention mechanism for feature alignment
- Advanced feature interaction between audio and LLM embedding space
- More complex but potentially better feature alignment
Based on the RWKV-ASR implementation:
- Projector: 2-layer RWKV (simplified from original implementation)
- Using 2-layer RWKV proved sufficient for effective feature projection
- Maintains consistency with the base LLM architecture
Stage 1: Frozen Encoder & LLM
- Freeze the audio encoder completely
- Freeze the LLM parameters completely
- Train only the projector
- Allows efficient feature space alignment without catastrophic forgetting
Attention Mask Handling
A key correction to the original RWKV-ASR implementation is the addition of attention_mask during forward pass:
# Original issue: Missing attention_mask
# Impact: Causes hallucinations from padding tokens
# Fix: Include attention_mask parameter
output = projector(features, attention_mask=mask)Hallucination Reduction Results:
- Before fix: ~20% hallucination rate
- After fix: 1-2% hallucination rate (on clean test set)
- Note: Hallucination increases on extremely noisy audio
The attention mask prevents the model from attending to padding positions, which was a major source of spurious token generation.
Recent papers have introduced Mixture of Experts (MoE) mechanisms into projectors:
- Language-Specific Alignment: Different languages have different acoustic-to-semantic alignment patterns
- Specialized Experts: Assign different MLP experts for different languages
- Routing Mechanism: Dynamically select appropriate expert based on language identifier
- Better handling of language-specific phonetic-phonemic mappings
- Improved cross-lingual ASR performance
- Flexible scaling for new languages without retraining the entire projector
- Requires explicit language labels during training or let the router choose and adjust via balance loss.
- Add language-specific routing tokens (e.g.,
<|en|>,<|zh|>) - Can be combined with standard downsampling strategies
The projector in LLM-based ASR is a crucial yet often overlooked component:
- Architecture Choice: MLP, Transformer Encoder, or Q-Former, each with trade-offs in complexity and performance
- Training Efficiency: Freezing encoder and LLM allows rapid iteration on projector design
- Implementation Details Matter: Proper attention mask handling can dramatically reduce hallucinations
- Language Diversity: MoE-based projectors offer a promising direction for multilingual ASR
By carefully designing the projector and addressing implementation details, systems can achieve robust audio-to-LLM embedding alignment while maintaining computational efficiency.
We borrowed a lot of code from the following excellent projects:
