modify q3tts loader

This commit is contained in:
Concedo
2026-03-08 00:53:33 +08:00
parent 0df18d2ae2
commit ebe44e7819
4 changed files with 11 additions and 23 deletions
+1 -11
View File
@@ -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) {
@@ -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;
}
+8 -10
View File
@@ -161,12 +161,10 @@ bool load_tensor_data_from_file(
const std::map<std::string, struct ggml_tensor *> & 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;
}
+1 -1
View File
@@ -72,7 +72,7 @@ bool load_tensor_data_from_file(
const std::map<std::string, struct ggml_tensor *> & 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