mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-11 03:24:30 +00:00
fix: merge LoRAs in F32 when convert changes the tensor type (#2302)
This commit is contained in:
1 parent
d22dcda1cf
commit
cfdf3cf037
1 file changed
+7
-3
+7
-3
@@ -463,11 +463,15 @@ static bool load_model_into_memory(ModelLoader& model_loader,
|
|||||||
const ggml_type export_type = get_export_tensor_type(model_loader, storage, output_type, type_rules);
|
const ggml_type export_type = get_export_tensor_type(model_loader, storage, output_type, type_rules);
|
||||||
const bool quant_src = ggml_is_quantized(storage.type);
|
const bool quant_src = ggml_is_quantized(storage.type);
|
||||||
const bool quant_dst = ggml_is_quantized(export_type);
|
const bool quant_dst = ggml_is_quantized(export_type);
|
||||||
|
const bool half_src = storage.type == GGML_TYPE_F16 || storage.type == GGML_TYPE_BF16;
|
||||||
if (quant_src && quant_dst) {
|
if (quant_src && quant_dst) {
|
||||||
load_type = GGML_TYPE_F16;
|
load_type = GGML_TYPE_F16;
|
||||||
} else if (quant_src || quant_dst) {
|
} else if (quant_src) {
|
||||||
load_type = quant_src ? export_type : storage.type;
|
load_type = export_type;
|
||||||
} else if (storage.type == GGML_TYPE_F32 || export_type == GGML_TYPE_F32) {
|
} else if (storage.type == GGML_TYPE_F32 || export_type == GGML_TYPE_F32 ||
|
||||||
|
(half_src && export_type != storage.type)) {
|
||||||
|
// LoRA deltas can be smaller than half an F16/BF16 ulp of the weight. Merge in F32
|
||||||
|
// when the export converts the tensor again, so the merged weight is rounded once.
|
||||||
load_type = GGML_TYPE_F32;
|
load_type = GGML_TYPE_F32;
|
||||||
}
|
}
|
||||||
ggml_tensor* tensor = ggml_new_tensor(ctx, load_type, storage.n_dims, storage.ne);
|
ggml_tensor* tensor = ggml_new_tensor(ctx, load_type, storage.n_dims, storage.ne);
|
||||||
|
|||||||
Reference in new issue
Block a user