mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-09-25 12:40:41 +00:00
feat: use backend-native FP8 matmul when supported (#1916)
This commit is contained in:
parent
dc4000d9f8
commit
2540a4fc25
@ -3470,8 +3470,18 @@ public:
|
|||||||
ggml_tensor* w = params["weight"];
|
ggml_tensor* w = params["weight"];
|
||||||
ggml_tensor* weight_scale = has_weight_scale ? params["weight_scale"] : nullptr;
|
ggml_tensor* weight_scale = has_weight_scale ? params["weight_scale"] : nullptr;
|
||||||
if (w->type == GGML_TYPE_F8_E4M3 || w->type == GGML_TYPE_F8_E5M2) {
|
if (w->type == GGML_TYPE_F8_E4M3 || w->type == GGML_TYPE_F8_E5M2) {
|
||||||
|
bool supports_fp8_matmul = false;
|
||||||
|
if (ctx->backend != nullptr) {
|
||||||
|
ggml_tensor* fp8_matmul = ggml_mul_mat(ctx->ggml_ctx, w, x);
|
||||||
|
if (force_prec_f32) {
|
||||||
|
ggml_mul_mat_set_prec(fp8_matmul, GGML_PREC_F32);
|
||||||
|
}
|
||||||
|
supports_fp8_matmul = ggml_backend_supports_op(ctx->backend, fp8_matmul);
|
||||||
|
}
|
||||||
|
if (!supports_fp8_matmul) {
|
||||||
w = ggml_cast(ctx->ggml_ctx, w, GGML_TYPE_BF16);
|
w = ggml_cast(ctx->ggml_ctx, w, GGML_TYPE_BF16);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ggml_tensor* b = nullptr;
|
ggml_tensor* b = nullptr;
|
||||||
if (bias) {
|
if (bias) {
|
||||||
b = params["bias"];
|
b = params["bias"];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user