Commit b2e5f28 for stable-diffusion.cpp
commit b2e5f28bbd3741fe8911af0b90fb8aec05ecbdc8
Author: Pento <pentolo@outlook.com>
Date: Thu Dec 3 14:48:57 2026 +0100
fix: probe parameter op support on a detached tensor copy (#2498)
diff --git a/src/model_manager.cpp b/src/model_manager.cpp
index cba1ca8..a8ac9b8 100644
--- a/src/model_manager.cpp
+++ b/src/model_manager.cpp
@@ -72,10 +72,18 @@ static bool device_supports_param_op(ggml_backend_dev_t device,
if (op == GGML_OP_NONE) {
return true;
}
- if (device == nullptr || weight == nullptr || buft == nullptr || weight->buffer != nullptr) {
+ if (device == nullptr || weight == nullptr || buft == nullptr) {
return false;
}
+ // Probe a detached copy so resident weights can be checked without touching their buffer.
+ ggml_tensor probe = *weight;
+ probe.buffer = nullptr;
+ probe.view_src = nullptr;
+ probe.view_offs = 0;
+ probe.data = nullptr;
+ probe.extra = nullptr;
+
ggml_init_params params;
params.mem_size = ggml_tensor_overhead() * 2;
params.mem_buffer = nullptr;
@@ -88,25 +96,24 @@ static bool device_supports_param_op(ggml_backend_dev_t device,
ggml_tensor* op_tensor = nullptr;
if (op == GGML_OP_GET_ROWS) {
ggml_tensor* indices = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, 1);
- op_tensor = ggml_get_rows(ctx, weight, indices);
+ op_tensor = ggml_get_rows(ctx, &probe, indices);
} else if (op == GGML_OP_CUSTOM) {
op_tensor = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 1);
op_tensor->op = op;
- op_tensor->src[0] = weight;
+ op_tensor->src[0] = &probe;
}
if (op_tensor == nullptr) {
ggml_free(ctx);
return false;
}
- weight->buffer = ggml_backend_buft_alloc_buffer(buft, 0);
- if (weight->buffer == nullptr) {
+ probe.buffer = ggml_backend_buft_alloc_buffer(buft, 0);
+ if (probe.buffer == nullptr) {
ggml_free(ctx);
return false;
}
bool supported = ggml_backend_dev_supports_op(device, op_tensor);
- ggml_backend_buffer_free(weight->buffer);
- weight->buffer = nullptr;
+ ggml_backend_buffer_free(probe.buffer);
ggml_free(ctx);
return supported;
}