Commit 396ed2cce for llama.cpp

commit 396ed2ccea7dc5e02adde8f154261b9f6d1047f0
Author: Eddie Zhou <e.zhou@chocolat.chaud.io>
Date:   Tue Nov 24 07:03:20 2026 -0700

    model : Inkling 2 Mini mix() weighted sum with the scores as src0 (#32855)

    * model : Inkling 2 Mini mix() weighted sum with the scores as src0

    The weighted sum over the depth states has K = # of states so the old operand order ran one small mat-vec per token. Putting scores first makes n_embd the long dimension and speeds up prefill by 14-18% on MI300X and 25-37% on B200.

    * model : return the mix() output in its matmul layout

diff --git a/src/models/inkling2.cpp b/src/models/inkling2.cpp
index 4a685fd16..febb6e185 100644
--- a/src/models/inkling2.cpp
+++ b/src/models/inkling2.cpp
@@ -184,7 +184,7 @@ ggml_tensor * llama_model_inkling2::graph::mix(const std::vector<ggml_tensor *>
     ggml_tensor * scores = ggml_mul_mat(ctx0, states, queries);
     scores = ggml_soft_max_ext(ctx0, scores, nullptr, 1.0f/sqrtf(n_embd), 0.0f);

-    return ggml_mul_mat(ctx0, ggml_cont(ctx0, ggml_transpose(ctx0, states)), scores);
+    return ggml_mul_mat(ctx0, scores, ggml_cont(ctx0, ggml_transpose(ctx0, states))); // [n_queries, n_embd, n_tokens]
 }

 // causal short convolution with a residual; dynamic adds input-dependent taps per head
@@ -281,7 +281,7 @@ ggml_tensor * llama_model_inkling2::graph::build_layer(int il, int ip, ggml_tens

     // the message of controller ctrl, [n_embd, n_tokens]
     auto message = [&](int ctrl) {
-        return ggml_cont(ctx0, ggml_view_2d(ctx0, messages, n_embd, n_tokens, messages->nb[2], ctrl*messages->nb[1]));
+        return ggml_reshape_2d(ctx0, ggml_cont(ctx0, ggml_view_3d(ctx0, messages, 1, n_embd, n_tokens, messages->nb[1], messages->nb[2], ctrl*messages->nb[0])), n_embd, n_tokens);
     };

     ggml_tensor * state   = recr->mctx->get_r_l(il);
@@ -295,7 +295,7 @@ ggml_tensor * llama_model_inkling2::graph::build_layer(int il, int ip, ggml_tens
     if (layer.attn_res_query) {
         ggml_tensor * mixed = mix(blocks, cur, layer.attn_res_query);
         for (int j = 0; j < 3; ++j) {
-            inputs[j] = ggml_cont(ctx0, ggml_view_2d(ctx0, mixed, n_embd, n_tokens, mixed->nb[2], (is_swa ? 0 : j)*mixed->nb[1]));
+            inputs[j] = ggml_reshape_2d(ctx0, ggml_cont(ctx0, ggml_view_3d(ctx0, mixed, 1, n_embd, n_tokens, mixed->nb[1], mixed->nb[2], (is_swa ? 0 : j)*mixed->nb[0])), n_embd, n_tokens);
         }
     }

diff --git a/src/models/models.h b/src/models/models.h
index 3b4f04c19..2944e74bb 100644
--- a/src/models/models.h
+++ b/src/models/models.h
@@ -2563,7 +2563,7 @@ struct llama_model_inkling2 : public llama_model_base {

         // the inputs and the token embeddings
         ggml_tensor * build_inputs();
-        // cache slot il of physical layer ip; messages [n_embd, LOOP_CTRL_COUNT, n_tokens] are mixed into its inputs
+        // cache slot il of physical layer ip; messages [LOOP_CTRL_COUNT, n_embd, n_tokens] are mixed into its inputs
         ggml_tensor * build_layer(int il, int ip, ggml_tensor * cur, std::vector<ggml_tensor *> & blocks,
                 ggml_tensor * messages = nullptr, const loop_layer * loop = nullptr);
         void build_output(ggml_tensor * cur, const std::vector<ggml_tensor *> & blocks);