diff --git a/otherarch/qwen3tts/audio_tokenizer_decoder.cpp b/otherarch/qwen3tts/audio_tokenizer_decoder.cpp index c58798135..ac1dd5986 100644 --- a/otherarch/qwen3tts/audio_tokenizer_decoder.cpp +++ b/otherarch/qwen3tts/audio_tokenizer_decoder.cpp @@ -317,7 +317,7 @@ bool AudioTokenizerDecoder::load_model(const std::string & model_path) { if (!load_tensor_data_from_file(model_path, gguf_ctx, model_.ctx, model_.tensors, model_.buffer, error_msg_, - GGML_BACKEND_DEVICE_TYPE_IGPU)) { + qwen3tts_allowgpu)) { return false; } @@ -328,16 +328,6 @@ bool AudioTokenizerDecoder::load_model(const std::string & model_path) { } normalize_codebooks(); - // Codebooks are normalized in host memory; sync once to backend tensors. - auto upload_if_present = [](struct ggml_tensor * t) { - if (t && t->data) { - ggml_backend_tensor_set(t, t->data, 0, ggml_nbytes(t)); - } - }; - upload_if_present(model_.vq_first_codebook); - for (int i = 0; i < 15; ++i) { - upload_if_present(model_.vq_rest_codebook[i]); - } state_.backend = init_preferred_backend("AudioTokenizerDecoder", &error_msg_, qwen3tts_allowgpu); if (!state_.backend) { diff --git a/otherarch/qwen3tts/audio_tokenizer_encoder.cpp b/otherarch/qwen3tts/audio_tokenizer_encoder.cpp index 47a6d14a2..b3c138d2c 100644 --- a/otherarch/qwen3tts/audio_tokenizer_encoder.cpp +++ b/otherarch/qwen3tts/audio_tokenizer_encoder.cpp @@ -249,7 +249,7 @@ bool AudioTokenizerEncoder::load_model(const std::string & model_path) { } if (!load_tensor_data_from_file(model_path, gguf_ctx, model_.ctx, - model_.tensors, model_.buffer, error_msg_, qwen3tts_allowgpu?GGML_BACKEND_DEVICE_TYPE_GPU:GGML_BACKEND_DEVICE_TYPE_CPU)) { + model_.tensors, model_.buffer, error_msg_, qwen3tts_allowgpu)) { return false; } diff --git a/otherarch/qwen3tts/gguf_loader.cpp b/otherarch/qwen3tts/gguf_loader.cpp index 09b7a154f..84511cf4e 100644 --- a/otherarch/qwen3tts/gguf_loader.cpp +++ b/otherarch/qwen3tts/gguf_loader.cpp @@ -161,12 +161,10 @@ bool load_tensor_data_from_file( const std::map & tensors, ggml_backend_buffer_t & buffer, std::string & error_msg, - enum ggml_backend_dev_type preferred_backend_type + bool allowgpu ) { - ggml_backend_t backend = ggml_backend_init_by_type(preferred_backend_type, nullptr); - if (!backend && preferred_backend_type != GGML_BACKEND_DEVICE_TYPE_CPU) { - backend = ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr); - } + ggml_backend_t backend = init_preferred_backend("TensorLoader", &error_msg, allowgpu); + if (!backend) { error_msg = "Failed to initialize backend for GGUF tensor loader"; return false; @@ -176,7 +174,7 @@ bool load_tensor_data_from_file( buffer = ggml_backend_alloc_ctx_tensors(model_ctx, backend); if (!buffer) { error_msg = "Failed to allocate tensor buffer"; - ggml_backend_free(backend); + release_preferred_backend(backend); return false; } @@ -184,7 +182,7 @@ bool load_tensor_data_from_file( FILE * f = fopen(path.c_str(), "rb"); if (!f) { error_msg = "Failed to open file for reading: " + path; - ggml_backend_free(backend); + release_preferred_backend(backend); return false; } @@ -209,14 +207,14 @@ bool load_tensor_data_from_file( if (fseek(f, data_offset + offset, SEEK_SET) != 0) { error_msg = "Failed to seek to tensor data: " + std::string(name); fclose(f); - ggml_backend_free(backend); + release_preferred_backend(backend); return false; } if (fread(read_buf.data(), 1, nbytes, f) != nbytes) { error_msg = "Failed to read tensor data: " + std::string(name); fclose(f); - ggml_backend_free(backend); + release_preferred_backend(backend); return false; } @@ -224,7 +222,7 @@ bool load_tensor_data_from_file( } fclose(f); - ggml_backend_free(backend); + release_preferred_backend(backend); return true; } diff --git a/otherarch/qwen3tts/gguf_loader.h b/otherarch/qwen3tts/gguf_loader.h index 0fd45ec38..5ddfaf875 100644 --- a/otherarch/qwen3tts/gguf_loader.h +++ b/otherarch/qwen3tts/gguf_loader.h @@ -72,7 +72,7 @@ bool load_tensor_data_from_file( const std::map & tensors, ggml_backend_buffer_t & buffer, std::string & error_msg, - enum ggml_backend_dev_type preferred_backend_type = GGML_BACKEND_DEVICE_TYPE_GPU + bool allowgpu ); // Helper to initialize backend with GPU preference and CPU fallback