| 229 | } |
| 230 | w.down_proj = weights.store->load_tensor(source, prefix + ".mlp.down_proj.weight", storage_type, {config.hidden_size, config.intermediate_size}); |
| 231 | weights.layers.push_back(std::move(w)); |
| 232 | } |
| 233 | weights.norm = weights.store->load_f32_tensor(source, model_prefix + ".norm.weight", {config.hidden_size}); |
| 234 | const std::string lm_head_name = assets.config.hf_transformers_layout |
| 235 | ? "lm_head.weight" |
| 236 | : "thinker.lm_head.weight"; |
| 237 | // Fine-tuned checkpoints saved with tied embeddings (e.g. QwenCleo-ASR) can omit |
| 238 | // thinker.lm_head.weight in the legacy layout; the official checkpoints still ship it. |
| 239 | const bool tie_output = assets.config.tie_word_embeddings && |
| 240 | (assets.config.hf_transformers_layout || !source.has_tensor(lm_head_name)); |
| 241 | if (tie_output) { |
| 242 | if (config.output_size != config.vocab_size) { |
| 243 | throw std::runtime_error("Qwen3 ASR tied output embedding requires output_size == vocab_size"); |
| 244 | } |
| 245 | weights.lm_head = weights.token_embedding; |
| 246 | } else { |
| 247 | weights.lm_head = weights.store->load_tensor( |
| 248 | source, |
| 249 | lm_head_name, |
| 250 | storage_type, |
| 251 | {config.output_size, config.hidden_size}); |
| 252 | } |
| 253 | weights.store->upload(); |
| 254 | return weights; |
| 255 | } |
| 256 | |
| 257 | int32_t argmax_index(const std::vector<float> & values) { |
| 258 | if (values.empty()) { |
| 259 | throw std::runtime_error("Qwen3 ASR thinker cannot select from empty logits"); |
| 260 | } |
| 261 | size_t best = 0; |
| 262 | for (size_t i = 1; i < values.size(); ++i) { |
| 263 | if (values[i] > values[best]) { |
| 264 | best = i; |
| 265 | } |
| 266 | } |
| 267 | return static_cast<int32_t>(best); |
| 268 | } |
| 269 | |
| 270 | bool is_eos(const Qwen3ASRTextDecoderConfig & config, int32_t token) { |
| 271 | return std::find(config.eos_token_ids.begin(), config.eos_token_ids.end(), static_cast<int64_t>(token)) != |
| 272 | config.eos_token_ids.end(); |
| 273 | } |
| 274 | |
| 275 | class ThinkerWeightsRuntime { |
| 276 | public: |
| 277 | ThinkerWeightsRuntime( |
| 278 | std::shared_ptr<const Qwen3ASRAssets> assets, |
| 279 | core::ExecutionContext & execution, |
| 280 | size_t weight_context_bytes, |
| 281 | assets::TensorStorageType storage_type, |
| 282 | const Qwen3ASRPerfSettings & perf) |
| 283 | : assets_(std::move(assets)), |
| 284 | backend_(execution.backend()), |
| 285 | backend_type_(execution.backend_type()), |
| 286 | threads_(std::max(1, execution.config().threads)), |
no test coverage detected