Delete egs/ami/ASR/xlsr_transducer/README.md
Browse files
egs/ami/ASR/xlsr_transducer/README.md
DELETED
|
@@ -1,194 +0,0 @@
|
|
| 1 |
-
# XLSR-Transducer Training for AMI Dataset
|
| 2 |
-
|
| 3 |
-
## Overview
|
| 4 |
-
Comprehensive production-ready training script for fine-tuning XLSR (Cross-lingual Speech Representation) models on the AMI meeting corpus using pruned transducer loss.
|
| 5 |
-
|
| 6 |
-
## Created Files
|
| 7 |
-
- **train.py** (1,280 lines) - Main training script with full icefall integration
|
| 8 |
-
- **TRAINING_GUIDE.md** - Detailed usage and configuration guide
|
| 9 |
-
|
| 10 |
-
## Architecture
|
| 11 |
-
```
|
| 12 |
-
Raw Waveform (16kHz)
|
| 13 |
-
↓
|
| 14 |
-
XLSR Encoder (facebook/wav2vec2-large-xlsr-53)
|
| 15 |
-
↓ (batch, frames, 1024)
|
| 16 |
-
├─→ Decoder (stateless prediction network)
|
| 17 |
-
│ ↓
|
| 18 |
-
└─→ Joiner (joint network)
|
| 19 |
-
↓
|
| 20 |
-
Pruned Transducer Loss
|
| 21 |
-
```
|
| 22 |
-
|
| 23 |
-
## Quick Start
|
| 24 |
-
|
| 25 |
-
### 1. Prepare Data
|
| 26 |
-
Ensure you have:
|
| 27 |
-
- BPE model: `data/lang_bpe_500/bpe.model`
|
| 28 |
-
- Training cuts: `data/manifests/cuts_train_all.jsonl.gz` (or `cuts_train_ihm.jsonl.gz`)
|
| 29 |
-
- Dev cuts: `data/manifests/cuts_dev_ihm.jsonl.gz`
|
| 30 |
-
|
| 31 |
-
### 2. Train
|
| 32 |
-
```bash
|
| 33 |
-
export CUDA_VISIBLE_DEVICES="0,1,2,3"
|
| 34 |
-
|
| 35 |
-
./xlsr_transducer/train.py \
|
| 36 |
-
--world-size 4 \
|
| 37 |
-
--num-epochs 15 \
|
| 38 |
-
--use-fp16 1 \
|
| 39 |
-
--exp-dir xlsr_transducer/exp \
|
| 40 |
-
--max-duration 150
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
### 3. Monitor
|
| 44 |
-
```bash
|
| 45 |
-
tensorboard --logdir xlsr_transducer/exp/tensorboard
|
| 46 |
-
```
|
| 47 |
-
|
| 48 |
-
## Key Features Implemented
|
| 49 |
-
|
| 50 |
-
### Required (from specification)
|
| 51 |
-
- [x] Import XLSR encoder from xlsr_encoder.py
|
| 52 |
-
- [x] Import AsrModel from model.py
|
| 53 |
-
- [x] Import decoder and joiner from respective files
|
| 54 |
-
- [x] Import AmiAsrDataModule from asr_datamodule.py
|
| 55 |
-
- [x] Load AMI cuts from data/manifests/
|
| 56 |
-
- [x] Use BPE model from data/lang_bpe_500/bpe.model
|
| 57 |
-
- [x] Support --encoder-name argument (default: facebook/wav2vec2-large-xlsr-53)
|
| 58 |
-
- [x] Support --freeze-encoder argument for frozen finetuning
|
| 59 |
-
- [x] Use pruned transducer loss (similar to finetune.py)
|
| 60 |
-
- [x] Include proper argument parsing for AMI-specific options
|
| 61 |
-
- [x] Include training loop with validation
|
| 62 |
-
- [x] Include checkpointing and model averaging
|
| 63 |
-
- [x] Handle raw waveforms from datamodule correctly
|
| 64 |
-
|
| 65 |
-
### Additional Features
|
| 66 |
-
- [x] Mixed precision training (FP16)
|
| 67 |
-
- [x] Distributed data parallel (DDP) training
|
| 68 |
-
- [x] Gradient accumulation
|
| 69 |
-
- [x] Learning rate scheduling (Eden optimizer)
|
| 70 |
-
- [x] Tensorboard logging
|
| 71 |
-
- [x] OOM sanity checking
|
| 72 |
-
- [x] Checkpoint resumption
|
| 73 |
-
- [x] Best model tracking
|
| 74 |
-
- [x] Validation monitoring
|
| 75 |
-
- [x] Diagnostic mode
|
| 76 |
-
|
| 77 |
-
## Model Variants
|
| 78 |
-
|
| 79 |
-
### Unfrozen Training
|
| 80 |
-
Full end-to-end training of XLSR encoder + decoder/joiner:
|
| 81 |
-
```bash
|
| 82 |
-
./xlsr_transducer/train.py \
|
| 83 |
-
--freeze-encoder False \
|
| 84 |
-
--base-lr 0.001 \
|
| 85 |
-
--max-duration 150
|
| 86 |
-
```
|
| 87 |
-
|
| 88 |
-
### Frozen Encoder
|
| 89 |
-
Only train decoder/joiner (faster, less memory):
|
| 90 |
-
```bash
|
| 91 |
-
./xlsr_transducer/train.py \
|
| 92 |
-
--freeze-encoder True \
|
| 93 |
-
--base-lr 0.005 \
|
| 94 |
-
--max-duration 200
|
| 95 |
-
```
|
| 96 |
-
|
| 97 |
-
## Configuration Options
|
| 98 |
-
|
| 99 |
-
### Essential
|
| 100 |
-
- `--encoder-name`: HuggingFace XLSR model
|
| 101 |
-
- `--freeze-encoder`: Freeze encoder weights
|
| 102 |
-
- `--exp-dir`: Experiment directory
|
| 103 |
-
- `--max-duration`: Batch size (in seconds)
|
| 104 |
-
- `--world-size`: Number of GPUs
|
| 105 |
-
- `--use-fp16`: Enable mixed precision
|
| 106 |
-
|
| 107 |
-
### Advanced
|
| 108 |
-
- `--encoder-dim`: XLSR output dimension (1024)
|
| 109 |
-
- `--decoder-dim`: Decoder dimension (512)
|
| 110 |
-
- `--joiner-dim`: Joiner dimension (512)
|
| 111 |
-
- `--context-size`: N-gram context (2 = trigram)
|
| 112 |
-
- `--prune-range`: Pruning range for RNN-T (5)
|
| 113 |
-
- `--accum-grad`: Gradient accumulation steps
|
| 114 |
-
|
| 115 |
-
See `TRAINING_GUIDE.md` for complete documentation.
|
| 116 |
-
|
| 117 |
-
## Training Pipeline
|
| 118 |
-
|
| 119 |
-
1. **Data Loading**: Load AMI cuts with duration filtering (0.2s - 25s)
|
| 120 |
-
2. **Batching**: Dynamic bucketing sampler for efficient GPU usage
|
| 121 |
-
3. **Encoding**: XLSR processes raw 16kHz waveforms → features
|
| 122 |
-
4. **Decoding**: Stateless prediction network processes BPE tokens
|
| 123 |
-
5. **Joint Network**: Combines encoder/decoder outputs
|
| 124 |
-
6. **Loss**: Pruned RNN-T loss (efficient memory usage)
|
| 125 |
-
7. **Optimization**: ScaledAdam with Eden scheduler
|
| 126 |
-
8. **Validation**: Periodic evaluation on dev_ihm
|
| 127 |
-
9. **Checkpointing**: Save models and optimizer state
|
| 128 |
-
|
| 129 |
-
## Performance
|
| 130 |
-
|
| 131 |
-
### Expected Results
|
| 132 |
-
- Training time: ~2-3 days on 4x V100 GPUs
|
| 133 |
-
- Memory usage: ~16GB per GPU (unfrozen, FP16)
|
| 134 |
-
- Memory usage: ~10GB per GPU (frozen, FP16)
|
| 135 |
-
|
| 136 |
-
### Optimization Tips
|
| 137 |
-
1. Use frozen encoder for faster iteration
|
| 138 |
-
2. Enable FP16 for 40% memory reduction
|
| 139 |
-
3. Adjust `--max-duration` based on GPU memory
|
| 140 |
-
4. Use gradient accumulation if batch size is limited
|
| 141 |
-
5. Monitor validation loss for early stopping
|
| 142 |
-
|
| 143 |
-
## Troubleshooting
|
| 144 |
-
|
| 145 |
-
### Common Issues
|
| 146 |
-
**"Expected raw waveforms (2D tensor), got features"**
|
| 147 |
-
- Ensure datamodule provides raw audio in `batch["inputs"]`
|
| 148 |
-
- Check that on_the_fly_feats is properly configured
|
| 149 |
-
|
| 150 |
-
**CUDA out of memory**
|
| 151 |
-
- Reduce `--max-duration`
|
| 152 |
-
- Enable `--freeze-encoder`
|
| 153 |
-
- Reduce `--world-size` if using small GPUs
|
| 154 |
-
|
| 155 |
-
**NaN loss**
|
| 156 |
-
- Reduce learning rate (`--base-lr`)
|
| 157 |
-
- Check gradient scaling
|
| 158 |
-
- Verify data quality
|
| 159 |
-
|
| 160 |
-
## File Structure
|
| 161 |
-
```
|
| 162 |
-
xlsr_transducer/
|
| 163 |
-
├── train.py # Main training script (THIS FILE)
|
| 164 |
-
├── xlsr_encoder.py # XLSR wrapper for HuggingFace Wav2Vec2
|
| 165 |
-
├── model.py # AsrModel integrating all components
|
| 166 |
-
├── decoder.py # Stateless prediction network
|
| 167 |
-
├── joiner.py # Joint network
|
| 168 |
-
├── asr_datamodule.py # AMI data loading
|
| 169 |
-
├── optim.py # ScaledAdam, Eden (symlink)
|
| 170 |
-
├── scaling.py # Scaled layers (symlink)
|
| 171 |
-
├── README.md # This file
|
| 172 |
-
└── TRAINING_GUIDE.md # Detailed guide
|
| 173 |
-
```
|
| 174 |
-
|
| 175 |
-
## Dependencies
|
| 176 |
-
- PyTorch >= 1.10
|
| 177 |
-
- transformers (HuggingFace)
|
| 178 |
-
- k2
|
| 179 |
-
- lhotse
|
| 180 |
-
- sentencepiece
|
| 181 |
-
- icefall
|
| 182 |
-
|
| 183 |
-
## References
|
| 184 |
-
- Based on: `egs/librispeech/SSL/zipformer/finetune.py`
|
| 185 |
-
- Adapted for: AMI dataset with XLSR encoder
|
| 186 |
-
- Architecture: Pruned RNN-Transducer
|
| 187 |
-
- Encoder: XLSR-53 (facebook/wav2vec2-large-xlsr-53)
|
| 188 |
-
|
| 189 |
-
## License
|
| 190 |
-
Apache 2.0 (see ../../../../LICENSE)
|
| 191 |
-
|
| 192 |
-
## Authors
|
| 193 |
-
Adapted for XLSR-Transducer training on AMI corpus.
|
| 194 |
-
Based on icefall team's SSL and transducer implementations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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