vllm_omni.model_executor.models.cosyvoice3.cosyvoice3_code2wav ¶
CosyVoice3 Code2Wav Stage - Converts speech tokens to audio waveforms.
This module contains the code2wav (token-to-waveform) stage which uses: 1. DiT (Diffusion Transformer) with optimized attention backends 2. CFM (Conditional Flow Matching) for mel spectrogram generation 3. HiFiGAN vocoder for waveform synthesis
CosyVoice3Code2Wav ¶
Bases: Module
CosyVoice3 Code2Wav stage for token-to-waveform conversion.
This class encapsulates: - Flow matching decoder with DiT backbone (using diffusion attention) - HiFiGAN vocoder for mel-to-waveform conversion
Source code in vllm_omni/model_executor/models/cosyvoice3/cosyvoice3_code2wav.py
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 | |
flow_model instance-attribute ¶
flow_model = CausalMaskedDiffWithDiT(
input_size=config.flow["input_size"],
output_size=config.flow["output_size"],
spk_embed_dim=config.flow["spk_embed_dim"],
output_type=config.flow["output_type"],
vocab_size=config.flow["vocab_size"],
input_frame_rate=config.flow["input_frame_rate"],
only_mask_loss=config.flow["only_mask_loss"],
token_mel_ratio=config.flow["token_mel_ratio"],
pre_lookahead_len=config.flow["pre_lookahead_len"],
pre_lookahead_layer=pre_lookahead_layer,
decoder=decoder,
)
mel_overlap_len instance-attribute ¶
mel_overlap_len = int(
self.token_overlap_len
/ self.flow_model.input_frame_rate
* 22050
/ 256
)
forward ¶
forward(
token: Tensor,
prompt_token: Tensor,
prompt_feat: Tensor,
embedding: Tensor,
n_timesteps: int = 10,
) -> Tensor
Generate audio waveform from speech tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token | Tensor | Speech tokens from talker stage [batch, seq_len] | required |
prompt_token | Tensor | Prompt speech tokens [batch, prompt_len] | required |
prompt_feat | Tensor | Prompt mel features [batch, feat_len, mel_dim] | required |
embedding | Tensor | Speaker embedding [batch, spk_dim] | required |
n_timesteps | int | Number of diffusion steps | 10 |
Returns:
| Type | Description |
|---|---|
Tensor | Audio waveform [batch, 1, audio_len] |
Source code in vllm_omni/model_executor/models/cosyvoice3/cosyvoice3_code2wav.py
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 | |
load_weights ¶
load_weights(model_dir: str, device: device) -> None
Load flow.pt and hift.pt weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | str | Model directory containing flow.pt and hift.pt | required |
device | device | Device to load weights to | required |