| 1245 | } |
| 1246 | return best_token; |
| 1247 | } |
| 1248 | std::discrete_distribution<size_t> distribution(weights.begin(), weights.end()); |
| 1249 | return indices[distribution(rng)]; |
| 1250 | } |
| 1251 | |
| 1252 | void apply_main_talker_processors( |
| 1253 | std::vector<float> & logits, |
| 1254 | const Qwen3TTSTalkerConfig & config, |
| 1255 | const std::vector<int32_t> & generated_first_codes, |
| 1256 | int64_t step, |
| 1257 | float repetition_penalty) { |
| 1258 | if (static_cast<int64_t>(logits.size()) != config.vocab_size) { |
| 1259 | throw std::runtime_error("Qwen3 talker logits size mismatch"); |
| 1260 | } |
| 1261 | if (step < 2 && config.codec_eos_token_id >= 0 && config.codec_eos_token_id < config.vocab_size) { |
| 1262 | logits[static_cast<size_t>(config.codec_eos_token_id)] = -std::numeric_limits<float>::infinity(); |
| 1263 | } |
| 1264 | const int64_t suppress_start = std::max<int64_t>(0, config.vocab_size - 1024); |
| 1265 | for (int64_t token = suppress_start; token < config.vocab_size; ++token) { |
| 1266 | if (token != config.codec_eos_token_id) { |
| 1267 | logits[static_cast<size_t>(token)] = -std::numeric_limits<float>::infinity(); |
| 1268 | } |
| 1269 | } |
| 1270 | if (repetition_penalty == 1.0F) { |
| 1271 | return; |
| 1272 | } |
| 1273 | if (repetition_penalty <= 0.0F) { |
| 1274 | throw std::runtime_error("Qwen3 talker repetition penalty must be positive"); |
| 1275 | } |
| 1276 | std::unordered_set<int32_t> seen_tokens; |
| 1277 | for (const int32_t token : generated_first_codes) { |
| 1278 | if (token < 0 || token >= config.vocab_size) { |
| 1279 | continue; |
| 1280 | } |
| 1281 | if (!seen_tokens.insert(token).second) { |
| 1282 | continue; |
| 1283 | } |
| 1284 | float & value = logits[static_cast<size_t>(token)]; |
| 1285 | value = value < 0.0F ? value * repetition_penalty : value / repetition_penalty; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | std::vector<float> frame_embedding( |
| 1290 | const Qwen3TalkerFrameCodes & frame, |
| 1291 | const std::vector<float> & text_hidden, |
| 1292 | const Qwen3TalkerWeights & weights, |
| 1293 | const Qwen3TTSTalkerConfig & config) { |
| 1294 | if (static_cast<int64_t>(frame.codes.size()) != config.num_code_groups) { |
| 1295 | throw std::runtime_error("Qwen3 talker frame code group count mismatch"); |
| 1296 | } |
| 1297 | if (static_cast<int64_t>(text_hidden.size()) != config.hidden_size) { |
nothing calls this directly
no test coverage detected