File size: 9,725 Bytes
a7c2243 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | Configuration Files
===================
The SpeechLM2 models use YAML configuration files to define model architecture, training parameters, and data settings.
This page describes the configuration structure and important parameters for each model type in the collection.
Configuration Structure
-----------------------
SpeechLM2 configuration files typically have the following high-level structure:
.. code-block:: yaml
model:
# Model architecture settings
...
trainer:
# PyTorch Lightning trainer settings
...
exp_manager:
# Experiment logging settings
...
data:
# Dataset settings
...
SALM Configuration
------------------
The SALM (Speech-Augmented Language Model) configuration includes settings for the pretrained LLM, audio perception module, and training parameters.
See the `SALM paper <https://arxiv.org/abs/2310.09424>`_ for more details.
.. code-block:: yaml
model:
# Pretrained model paths
pretrained_llm: "TinyLlama/TinyLlama_v1.1" # HF model path
pretrained_asr: "stt_en_fastconformer_hybrid_large_streaming_80ms" # NeMo checkpoint name
pretrained_weights: True # Whether to load weights or just architecture
# Special token settings
audio_locator_tag: "<audio>" # Tag to replace with audio embeddings
# Freezing parameters
freeze_params:
- "^llm\\.model\\.layers\\.[0-4]\\..+$" # Regex patterns for parameters to freeze
prevent_freeze_params: [] # Override freeze_params for specific submodules
# Optional LoRA settings for efficient fine-tuning
lora:
task_type: CAUSAL_LM
r: 8
lora_alpha: 32
lora_dropout: 0.1
# Audio perception module configuration
perception:
target: nemo.collections.speechlm2.modules.perception.AudioPerceptionModule
preprocessor:
normalize: 'NA'
encoder:
self_attention_model: rel_pos
att_context_size: [-1, -1]
conv_context_size: regular
conv_norm_type: batch_norm
modality_adapter:
_target_: nemo.collections.asr.modules.ConformerEncoder
feat_in: 1024
feat_out: -1
n_layers: 2
d_model: 1024
subsampling: dw_striding
subsampling_factor: 1
subsampling_conv_channels: 256
causal_downsampling: false
ff_expansion_factor: 4
self_attention_model: rel_pos
n_heads: 8
att_context_size: [-1, -1]
att_context_style: regular
xscaling: true
untie_biases: true
pos_emb_max_len: 5000
conv_kernel_size: 9
conv_norm_type: batch_norm
conv_context_size: null
dropout: 0
dropout_pre_encoder: 0
dropout_emb: 0.0
DuplexS2SModel Configuration
-----------------------------
The DuplexS2SModel adds speech generation capabilities to the configuration:
.. code-block:: yaml
model:
# Pretrained model paths
pretrained_llm: "TinyLlama/TinyLlama_v1.1"
pretrained_audio_codec: "path/to/audio_codec.nemo"
pretrained_asr: "stt_en_fastconformer_hybrid_large_streaming_80ms"
scoring_asr: "stt_en_fastconformer_transducer_large" # used only in validation
# Loss weights
audio_loss_weight: 4
text_loss_weight: 3
# Perception module config (similar to SALM)
perception:
# ... (similar to SALM perception module)
DuplexS2SSpeechDecoderModel Configuration
-----------------------------------------
The DuplexS2SSpeechDecoderModel is similar to DuplexS2SModel, but focuses on an additional speech generation transformer decoder:
.. code-block:: yaml
model:
# Pretrained model paths
pretrained_llm: "TinyLlama/TinyLlama_v1.1"
pretrained_audio_codec: "path/to/audio_codec.nemo"
pretrained_asr: "stt_en_fastconformer_hybrid_large_streaming_80ms"
# Speech decoder settings
speech_decoder:
target: nemo.collections.speechlm2.modules.speech_generation.TransformerARSpeechDecoder
d_model: 1024
n_layers: 12
n_heads: 16
d_kv: 64
d_ff: 4096
max_seq_len: 2048
dropout: 0.1
layernorm_epsilon: 1e-5
activation_function: "gelu_new"
init_method_std: 0.02
use_cache: True
# ... other settings
DuplexSTTModel Configuration
--------------------------------------
The DuplexSTTModel is a speech-to-text model that processes duplex audio conversations and generates agent text responses:
.. code-block:: yaml
model:
# Pretrained model paths
pretrained_llm: "TinyLlama/TinyLlama_v1.1"
pretrained_asr: "stt_en_fastconformer_hybrid_large_streaming_80ms"
# ... other settings
Trainer Configuration
---------------------
The trainer section contains PyTorch Lightning Trainer settings:
.. code-block:: yaml
trainer:
devices: 1
num_nodes: 1
accelerator: gpu
precision: bf16-true
logger: false
enable_checkpointing: false # handled by exp_manager
replace_sampler_ddp: false # handled by lhotse
max_epochs: null
max_steps: 100000
log_every_n_steps: 10
val_check_interval: 2000
accumulate_grad_batches: 1
gradient_clip_val: 1.0
Experiment Manager Configuration
--------------------------------
The exp_manager section contains settings for experiment logging and model checkpointing:
.. code-block:: yaml
exp_manager:
explicit_log_dir: path/to/output_dir
exp_dir: null
name: ${name}
create_wandb_logger: false # set to true if you want to use wandb
wandb_logger_kwargs:
project: null
name: null
resume_if_exists: true
resume_ignore_no_checkpoint: true
create_checkpoint_callback: true
checkpoint_callback_params:
monitor: val_loss
filename: "{step}" # checkpoint name will be step=<step>.ckpt
save_top_k: 1
mode: min
create_tensorboard_logger: false # set to true if you want to use tensorboard
version: null
Data Configuration
------------------
The data section defines dataset paths, preprocessing, and data loading parameters:
.. code-block:: yaml
data:
train_ds:
sample_rate: ${data.target_sample_rate}
input_cfg:
- type: lhotse_shar
shar_path: /path/to/train_data
seed: 42
shard_seed: "randomized"
num_workers: 4
batch_size: 16
# Optional bucketing settings
# batch_duration: 100
# bucket_duration_bins: [8.94766,10.1551,11.64118,19.30376,42.85]
# use_bucketing: true
# num_buckets: 5
# bucket_buffer_size: 5000
validation_ds:
datasets:
val_set_name:
shar_path: /path/to/validation_data
sample_rate: ${data.target_sample_rate}
batch_size: 1
seed: 42
shard_seed: "randomized"
Depending on the model, there may be additional options available under ``data`` namespace that are passed to the corresponding Dataset class.
For example, S2S models have:
.. code-block:: yaml
data:
frame_length: 0.08
source_sample_rate: 16000
target_sample_rate: 22050
input_roles: ["user", "User"]
output_roles: ["agent", "Assistant"]
train_ds: ...
Important Configuration Parameters
-----------------------------------
Model Parameters
^^^^^^^^^^^^^^^^
- **pretrained_llm**: Path to the pretrained HuggingFace LLM
- **pretrained_asr**: Name of the pretrained NeMo ASR model used for perception
- **pretrained_audio_codec**: Path to the pretrained audio codec model (for speech generation)
- **freeze_params**: Regex patterns of parameters to freeze during training
- **audio_loss_weight/text_loss_weight**: Weighting of different loss components
Perception Module
^^^^^^^^^^^^^^^^^
- **self_attention_model**: Type of attention mechanism ("rel_pos" or "abs_pos")
- **att_context_size**: Context window size for attention ([left, right])
- **conv_context_size**: Context type for convolutions ("causal" or "regular")
- **n_layers**: Number of encoder layers
- **d_model**: Model dimension size
Data Parameters
^^^^^^^^^^^^^^^
- **frame_length**: Frame duration in seconds
- **source_sample_rate/target_sample_rate**: Sample rates for input/output audio
- **input_roles/output_roles**: Speaker roles for input and output
- **batch_size**: Number of samples per batch
- **use_bucketing**: Whether to use length-based bucketing for efficient batching
Example Configuration Files
---------------------------
Example configurations for all model types can be found in the example directory:
- SALM: `examples/speechlm2/conf/salm.yaml`
- DuplexS2SModel: `examples/speechlm2/conf/s2s_duplex.yaml`
- DuplexS2SSpeechDecoderModel: `examples/speechlm2/conf/s2s_duplex_speech_decoder.yaml`
- DuplexSTTModel: `examples/speechlm2/conf/duplex_stt.yaml`
Using Configuration Files
-------------------------
You can use these configurations with the training scripts by specifying the config path:
.. code-block:: bash
# Train SALM model
python examples/speechlm2/salm_train.py \
--config-path=conf \
--config-name=salm
You can also override configuration values from the command line:
.. code-block:: bash
python examples/speechlm2/salm_train.py \
--config-path=conf \
--config-name=salm \
model.pretrained_llm="different/llm/path" \
trainer.max_steps=1000 \
data.train_ds.batch_size=8 |