Commit 800ae7e23 for llama.cpp
commit 800ae7e238eb42785f97e0d83e76b728d7d4e399
Author: Georgi Gerganov <ggerganov@gmail.com>
Date: Wed Dec 2 10:55:34 2026 +0200
ggml : rename the mul_mat scale arguments after their operands (#33431)
ggml_mul_mat_ext and ggml_mul_mat_id_ext take the scale side-cars as
scale_weight and scale_activations, which describes them by how LLM models
happen to use the operands. Name them after the operands they scale
instead: scale_a and scale_b, scale_as and scale_b. This matches the
internal ggml_get_src_scale(op, i) helper, which already indexes the
side-cars by operand.
Rename-only, no behavior change: the two GGML_LOG_ERROR messages and the
CPU scale-epilogue comments are reworded to drop the same wording.
Assisted-by: dsh:llama.cpp/ggml-org/Qwen3.8-Flash-Next-GGUF (MacBook, M5 Max, 128GB)
diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h
index 80eb71f28..5ddfac509 100644
--- a/ggml/include/ggml.h
+++ b/ggml/include/ggml.h
@@ -1323,15 +1323,16 @@ extern "C" {
struct ggml_tensor * a,
struct ggml_tensor * b);
- // scale_weight is F32, either a scalar or one value per output channel.
- // scale_activations is an optional F32 scalar for activation quantization.
- // Divide activations by the scale before quantization, then multiply the matmul result by the scale.
+ // matrix multiplication with optional quantization scales
+ // scale_a is F32, either a scalar or one value per output channel.
+ // scale_b is an optional F32 scalar, the quantization scale of b.
+ // Divide b by the scale before quantization, then multiply the matmul result by the scale.
GGML_API struct ggml_tensor * ggml_mul_mat_ext(
struct ggml_context * ctx,
struct ggml_tensor * a,
struct ggml_tensor * b,
- struct ggml_tensor * scale_weight,
- struct ggml_tensor * scale_activations);
+ struct ggml_tensor * scale_a,
+ struct ggml_tensor * scale_b);
// change the hint of a matrix multiplication
GGML_API void ggml_mul_mat_set_hint(
@@ -1346,15 +1347,16 @@ extern "C" {
struct ggml_tensor * b,
struct ggml_tensor * ids);
- // scale_weight: [1], [n_as] or [n_out, n_as], selected by ids
- // scale_activations: [1] or [n_as], selected by ids
+ // indirect matrix multiplication with optional quantization scales
+ // scale_as: F32, [1], [n_as] or [n_out, n_as], selected by ids
+ // scale_b: F32, [1] or [n_as], selected by ids
GGML_API struct ggml_tensor * ggml_mul_mat_id_ext(
struct ggml_context * ctx,
struct ggml_tensor * as,
struct ggml_tensor * b,
struct ggml_tensor * ids,
- struct ggml_tensor * scale_weight,
- struct ggml_tensor * scale_activations);
+ struct ggml_tensor * scale_as,
+ struct ggml_tensor * scale_b);
// A: m columns, n rows,
// B: p columns, n rows,
diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.c
index 39920c77b..56943f0cd 100644
--- a/ggml/src/ggml-cpu/ggml-cpu.c
+++ b/ggml/src/ggml-cpu/ggml-cpu.c
@@ -1306,7 +1306,7 @@ static void ggml_cpu_bf16_to_vec_dot_type(const ggml_bf16_t * x, void * y, int64
}
}
-// apply the weight scale (src[2]) carried by ggml_mul_mat_ext, broadcast over dst
+// apply the scale of a (src[2]) carried by ggml_mul_mat_ext, broadcast over dst
static void ggml_compute_forward_mul_mat_scale(
const struct ggml_compute_params * params,
struct ggml_tensor * dst) {
@@ -1643,7 +1643,7 @@ static void * incr_ptr_aligned(void ** p, size_t size, size_t align) {
return ptr;
}
-// apply the weight scale (src[3]) carried by ggml_mul_mat_id_ext: per-tensor [1],
+// apply the scale of as (src[3]) carried by ggml_mul_mat_id_ext: per-tensor [1],
// per-expert [n_expert] or per-channel-per-expert [n_out, n_expert], indexed via ids
static void ggml_compute_forward_mul_mat_id_scale(
const struct ggml_compute_params * params,
diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c
index 6a0835b62..485995e50 100644
--- a/ggml/src/ggml.c
+++ b/ggml/src/ggml.c
@@ -3399,7 +3399,7 @@ struct ggml_tensor * ggml_mul_mat(
struct ggml_tensor * a,
struct ggml_tensor * b) {
if (ggml_needs_scale(a->type)) {
- GGML_LOG_ERROR("%s: tensor type %s requires a weight scale; use ggml_mul_mat_ext instead\n",
+ GGML_LOG_ERROR("%s: tensor type %s requires a scale for a; use ggml_mul_mat_ext instead\n",
__func__, ggml_type_name(a->type));
GGML_ABORT("fatal error");
}
@@ -3411,18 +3411,18 @@ struct ggml_tensor * ggml_mul_mat_ext(
struct ggml_context * ctx,
struct ggml_tensor * a,
struct ggml_tensor * b,
- struct ggml_tensor * scale_weight,
- struct ggml_tensor * scale_activations) {
+ struct ggml_tensor * scale_a,
+ struct ggml_tensor * scale_b) {
GGML_ASSERT(ggml_can_mul_mat(a, b));
GGML_ASSERT(!ggml_is_transposed(a));
- GGML_ASSERT(!ggml_needs_scale(a->type) || scale_weight != NULL);
+ GGML_ASSERT(!ggml_needs_scale(a->type) || scale_a != NULL);
if (ggml_needs_scale(b->type)) {
- GGML_LOG_ERROR("%s: scaled tensor type %s currently cannot be used as the activation tensor\n",
+ GGML_LOG_ERROR("%s: tensor type %s is currently not supported as operand b\n",
__func__, ggml_type_name(b->type));
GGML_ABORT("fatal error");
}
- GGML_ASSERT(scale_weight == NULL || scale_weight->type == GGML_TYPE_F32);
- GGML_ASSERT(scale_activations == NULL || scale_activations->type == GGML_TYPE_F32);
+ GGML_ASSERT(scale_a == NULL || scale_a->type == GGML_TYPE_F32);
+ GGML_ASSERT(scale_b == NULL || scale_b->type == GGML_TYPE_F32);
const int64_t ne[4] = { a->ne[1], b->ne[1], b->ne[2], b->ne[3] };
struct ggml_tensor * result = ggml_new_tensor(ctx, GGML_TYPE_F32, 4, ne);
@@ -3431,14 +3431,14 @@ struct ggml_tensor * ggml_mul_mat_ext(
result->src[0] = a;
result->src[1] = b;
- if (scale_weight) {
- GGML_ASSERT(ggml_is_scalar(scale_weight) || (ggml_is_vector(scale_weight) && scale_weight->ne[0] == a->ne[1]));
- result->src[2] = scale_weight;
+ if (scale_a) {
+ GGML_ASSERT(ggml_is_scalar(scale_a) || (ggml_is_vector(scale_a) && scale_a->ne[0] == a->ne[1]));
+ result->src[2] = scale_a;
}
- if (scale_activations) {
- GGML_ASSERT(ggml_is_scalar(scale_activations));
- result->src[3] = scale_activations;
+ if (scale_b) {
+ GGML_ASSERT(ggml_is_scalar(scale_b));
+ result->src[3] = scale_b;
}
return result;
@@ -3476,7 +3476,7 @@ struct ggml_tensor * ggml_mul_mat_id(
struct ggml_tensor * b,
struct ggml_tensor * ids) {
if (ggml_needs_scale(as->type)) {
- GGML_LOG_ERROR("%s: tensor type %s requires a weight scale; use ggml_mul_mat_id_ext instead\n",
+ GGML_LOG_ERROR("%s: tensor type %s requires a scale for as; use ggml_mul_mat_id_ext instead\n",
__func__, ggml_type_name(as->type));
GGML_ABORT("fatal error");
}
@@ -3489,18 +3489,18 @@ struct ggml_tensor * ggml_mul_mat_id_ext(
struct ggml_tensor * as,
struct ggml_tensor * b,
struct ggml_tensor * ids,
- struct ggml_tensor * scale_weight,
- struct ggml_tensor * scale_activations) {
+ struct ggml_tensor * scale_as,
+ struct ggml_tensor * scale_b) {
GGML_ASSERT(!ggml_is_transposed(as));
GGML_ASSERT(ids->type == GGML_TYPE_I32);
if (ggml_needs_scale(b->type)) {
- GGML_LOG_ERROR("%s: scaled tensor type %s currently cannot be used as the activation tensor\n",
+ GGML_LOG_ERROR("%s: tensor type %s is currently not supported as operand b\n",
__func__, ggml_type_name(b->type));
GGML_ABORT("fatal error");
}
- GGML_ASSERT(!ggml_needs_scale(as->type) || scale_weight != NULL);
- GGML_ASSERT(scale_weight == NULL || scale_weight->type == GGML_TYPE_F32);
- GGML_ASSERT(scale_activations == NULL || scale_activations->type == GGML_TYPE_F32);
+ GGML_ASSERT(!ggml_needs_scale(as->type) || scale_as != NULL);
+ GGML_ASSERT(scale_as == NULL || scale_as->type == GGML_TYPE_F32);
+ GGML_ASSERT(scale_b == NULL || scale_b->type == GGML_TYPE_F32);
GGML_ASSERT(as->ne[3] == 1); // as is 3d (one matrix per expert)
GGML_ASSERT(b->ne[3] == 1); // b is 3d
@@ -3517,8 +3517,8 @@ struct ggml_tensor * ggml_mul_mat_id_ext(
result->src[1] = b;
result->src[2] = ids;
- if (scale_weight) {
- struct ggml_tensor * s = scale_weight;
+ if (scale_as) {
+ struct ggml_tensor * s = scale_as;
const bool per_tensor = ggml_is_scalar(s);
const bool per_expert = ggml_is_vector(s) && s->ne[0] == as->ne[2];
const bool per_ch_exp = s->ne[0] == as->ne[1] && s->ne[1] == as->ne[2] && s->ne[2] == 1 && s->ne[3] == 1;
@@ -3526,12 +3526,12 @@ struct ggml_tensor * ggml_mul_mat_id_ext(
result->src[3] = s;
}
- if (scale_activations) {
- const struct ggml_tensor * s = scale_activations;
+ if (scale_b) {
+ struct ggml_tensor * s = scale_b;
const bool per_tensor = ggml_is_scalar(s);
const bool per_expert = ggml_is_vector(s) && s->ne[0] == as->ne[2];
GGML_ASSERT(per_tensor || per_expert);
- result->src[4] = scale_activations;
+ result->src[4] = s;
}
return result;