Commit 103b19e9f for llama.cpp

commit 103b19e9ffff215509c9066a128dfea86cf68069
Author: Masashi Yoshimura <yoshimura.masashi.frbs@gmail.com>
Date:   Tue Dec 1 17:22:15 2026 +0900

    webgpu: split the GDN replay into a separate pipeline (#33289)

    * add replay pipeline to GDN

    * add switching between 1-pass and 2-pass path depding on the maxStorageBuffersPerShaderStage of the platform.

diff --git a/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp b/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp
index fe0865e81..a0c99fa6f 100644
--- a/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp
+++ b/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp
@@ -86,6 +86,7 @@ struct ggml_webgpu_shader_lib_context {
     ggml_tensor * dst_fuse;

     uint32_t    max_wg_size;
+    uint32_t    max_storage_buffers      = 0;
     size_t      wg_mem_limit_bytes       = 0;
     bool        supports_subgroups       = false;
     bool        supports_subgroup_matrix = false;
@@ -448,16 +449,26 @@ struct ggml_webgpu_im2col_pipeline_key_hash {
 };

 /** Gated Delta Net **/
+
+// check whether the replay of pending tokens runs in a separate pass
+// the single pass binds 7 inputs (q, k, v, g, beta, dst, state), the fused cache and the 4 replay inputs
+inline bool ggml_webgpu_gated_delta_net_split_replay(const ggml_tensor * op,
+                                                     bool                fused_cache,
+                                                     uint32_t            max_storage_buffers) {
+    return op->src[6] != nullptr && 7u + (fused_cache ? 1u : 0u) + 4u > max_storage_buffers;
+}
+
 struct ggml_webgpu_gated_delta_net_pipeline_key {
     int  type;
     int  s_v;
     int  kda;
     bool fused_cache;
     bool replay;
+    bool replay_split;

     bool operator==(const ggml_webgpu_gated_delta_net_pipeline_key & other) const {
         return type == other.type && s_v == other.s_v && kda == other.kda && fused_cache == other.fused_cache &&
-               replay == other.replay;
+               replay == other.replay && replay_split == other.replay_split;
     }
 };

@@ -468,6 +479,7 @@ struct ggml_webgpu_gated_delta_net_pipeline_key_hash {
         ggml_webgpu_hash_combine(seed, key.s_v);
         ggml_webgpu_hash_combine(seed, key.kda);
         ggml_webgpu_hash_combine(seed, key.replay);
+        ggml_webgpu_hash_combine(seed, key.replay_split);
         return seed;
     }
 };
@@ -1320,12 +1332,16 @@ class ggml_webgpu_shader_lib {
                        webgpu_pipeline,
                        ggml_webgpu_gated_delta_net_pipeline_key_hash>
         gated_delta_net_pipelines;  // type/S_v/kda
+    std::unordered_map<ggml_webgpu_gated_delta_net_pipeline_key,
+                       webgpu_pipeline,
+                       ggml_webgpu_gated_delta_net_pipeline_key_hash>
+        gated_delta_net_replay_pipelines;  // type/S_v/kda
     std::unordered_map<ggml_webgpu_pad_pipeline_key, webgpu_pipeline, ggml_webgpu_pad_pipeline_key_hash>
-        pad_pipelines;              // circular/non-circular
+        pad_pipelines;                     // circular/non-circular
     std::unordered_map<ggml_webgpu_binary_pipeline_key, webgpu_pipeline, ggml_webgpu_binary_pipeline_key_hash>
-        binary_pipelines;           // type/op/inplace/overlap/src_overlap
+        binary_pipelines;                  // type/op/inplace/overlap/src_overlap
     std::unordered_map<ggml_webgpu_add_id_pipeline_key, webgpu_pipeline, ggml_webgpu_add_id_pipeline_key_hash>
-        add_id_pipelines;           // inplace
+        add_id_pipelines;                  // inplace
     std::unordered_map<ggml_webgpu_mul_mat_scale_pipeline_key,
                        webgpu_pipeline,
                        ggml_webgpu_mul_mat_scale_pipeline_key_hash>
@@ -2047,6 +2063,8 @@ class ggml_webgpu_shader_lib {
         key.kda                                      = context.src3->ne[0] == context.src2->ne[0];
         key.fused_cache                              = context.dst_fuse != nullptr;
         key.replay                                   = context.dst->src[6] != nullptr;
+        key.replay_split =
+            ggml_webgpu_gated_delta_net_split_replay(context.dst, key.fused_cache, context.max_storage_buffers);

         auto it = gated_delta_net_pipelines.find(key);
         if (it != gated_delta_net_pipelines.end()) {
@@ -2074,7 +2092,10 @@ class ggml_webgpu_shader_lib {
             variant += "_fused_cache";
         }

-        if (key.replay) {
+        if (key.replay_split) {
+            defines.push_back("REPLAY_SPLIT");
+            variant += "_replay_split";
+        } else if (key.replay) {
             defines.push_back("REPLAY");
             variant += "_replay";
         }
@@ -2088,6 +2109,43 @@ class ggml_webgpu_shader_lib {
         return gated_delta_net_pipelines[key];
     }

+    webgpu_pipeline get_gated_delta_net_replay_pipeline(const ggml_webgpu_shader_lib_context & context) {
+        ggml_webgpu_gated_delta_net_pipeline_key key = {};
+        key.type                                     = context.dst->type;
+        key.s_v                                      = (int) context.src2->ne[0];
+        key.kda                                      = context.src3->ne[0] == context.src2->ne[0];
+        key.replay                                   = true;
+
+        auto it = gated_delta_net_replay_pipelines.find(key);
+        if (it != gated_delta_net_replay_pipelines.end()) {
+            return it->second;
+        }
+
+        std::vector<std::string> defines;
+        std::string              variant = "gated_delta_net_replay";
+
+        switch (key.type) {
+            case GGML_TYPE_F32:
+                variant += "_f32";
+                break;
+            default:
+                GGML_ABORT("Unsupported type for gated_delta_net_replay shader");
+        }
+
+        if (key.kda) {
+            defines.push_back("KDA");
+            variant += "_kda";
+        }
+
+        defines.push_back("S_V=" + std::to_string(key.s_v) + "u");
+        defines.push_back("WG_SIZE=" + std::to_string(key.s_v) + "u");
+
+        auto            processed             = preprocessor.preprocess(wgsl_gated_delta_net_replay, defines);
+        webgpu_pipeline pipeline              = ggml_webgpu_create_pipeline(device, processed, variant);
+        gated_delta_net_replay_pipelines[key] = pipeline;
+        return gated_delta_net_replay_pipelines[key];
+    }
+
     webgpu_pipeline get_arange_pipeline(const ggml_webgpu_shader_lib_context & context) {
         auto it = arange_pipelines.find(1);
         if (it != arange_pipelines.end()) {
diff --git a/ggml/src/ggml-webgpu/ggml-webgpu.cpp b/ggml/src/ggml-webgpu/ggml-webgpu.cpp
index b95419322..47eec2c11 100644
--- a/ggml/src/ggml-webgpu/ggml-webgpu.cpp
+++ b/ggml/src/ggml-webgpu/ggml-webgpu.cpp
@@ -1569,11 +1569,6 @@ static webgpu_encoded_op ggml_webgpu_ssm_scan(webgpu_context & ctx,
     return ggml_backend_webgpu_build(ctx, pipeline, params, entries, wg_x, wg_y);
 }

-// storage buffers of the gated delta net shader: q, k, v, g, beta, state and dst, the fused cache, then the replay inputs
-static uint32_t ggml_webgpu_gated_delta_net_n_storage_buffers(const ggml_tensor * op, bool fused_cache) {
-    return 7 + (fused_cache ? 1 : 0) + (op->src[6] != nullptr ? 4 : 0);
-}
-
 static webgpu_encoded_op ggml_webgpu_gated_delta_net(webgpu_context & ctx,
                                                      ggml_tensor *    src0,
                                                      ggml_tensor *    src1,
@@ -1591,7 +1586,8 @@ static webgpu_encoded_op ggml_webgpu_gated_delta_net(webgpu_context & ctx,
     shader_lib_ctx.src4                           = src4;
     shader_lib_ctx.dst                            = dst;
     shader_lib_ctx.dst_fuse                       = dst_fuse;
-    shader_lib_ctx.max_wg_size = ctx->global_ctx->capabilities.limits.maxComputeInvocationsPerWorkgroup;
+    shader_lib_ctx.max_wg_size         = ctx->global_ctx->capabilities.limits.maxComputeInvocationsPerWorkgroup;
+    shader_lib_ctx.max_storage_buffers = ctx->global_ctx->capabilities.limits.maxStorageBuffersPerShaderStage;

     webgpu_pipeline pipeline = ctx->shader_lib->get_gated_delta_net_pipeline(shader_lib_ctx);

@@ -1635,8 +1631,8 @@ static webgpu_encoded_op ggml_webgpu_gated_delta_net(webgpu_context & ctx,
         dst_fuse ? (uint32_t) (dst_fuse->nb[2] / ggml_type_size(dst_fuse->type)) : 0,
         dst_fuse ? (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, dst_fuse) / ggml_type_size(dst_fuse->type)) : 0,

-        pend_k ? (uint32_t) ggml_get_op_params_i32(dst, 1) : 0,
-        pend_k ? (uint32_t) ggml_get_op_params_i32(dst, 2) : 0,
+        pend_k ? (uint32_t) ggml_get_op_params_i32(dst, 1) : 0,  // n_pend
+        pend_k ? (uint32_t) ggml_get_op_params_i32(dst, 2) : 0,  // keep

         pend_k ? (uint32_t) (pend_k->nb[1] / ggml_type_size(pend_k->type)) : 0,
         pend_k ? (uint32_t) (pend_k->nb[2] / ggml_type_size(pend_k->type)) : 0,
@@ -1654,23 +1650,63 @@ static webgpu_encoded_op ggml_webgpu_gated_delta_net(webgpu_context & ctx,
     std::vector<wgpu::BindGroupEntry> entries = {
         ggml_webgpu_make_tensor_bind_group_entry(ctx, 0, src0), ggml_webgpu_make_tensor_bind_group_entry(ctx, 1, src1),
         ggml_webgpu_make_tensor_bind_group_entry(ctx, 2, src2), ggml_webgpu_make_tensor_bind_group_entry(ctx, 3, src3),
-        ggml_webgpu_make_tensor_bind_group_entry(ctx, 4, src4), ggml_webgpu_make_tensor_bind_group_entry(ctx, 5, src5),
-        ggml_webgpu_make_tensor_bind_group_entry(ctx, 6, dst),
+        ggml_webgpu_make_tensor_bind_group_entry(ctx, 4, src4), ggml_webgpu_make_tensor_bind_group_entry(ctx, 5, dst),
     };

     if (dst_fuse) {
-        entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, 7, dst_fuse));
+        entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, 6, dst_fuse));
     }

-    if (pend_k) {
-        const uint32_t binding = dst_fuse ? 8 : 7;
-        entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, binding + 0, pend_k));
-        entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, binding + 1, pend_v));
-        entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, binding + 2, pend_gb));
-        entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, binding + 3, n_rep));
+    if (!ggml_webgpu_gated_delta_net_split_replay(dst, dst_fuse != nullptr, shader_lib_ctx.max_storage_buffers)) {
+        entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, entries.size(), src5));
+        if (pend_k) {
+            entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, entries.size(), pend_k));
+            entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, entries.size(), pend_v));
+            entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, entries.size(), pend_gb));
+            entries.push_back(ggml_webgpu_make_tensor_bind_group_entry(ctx, entries.size(), n_rep));
+        }
+        return ggml_backend_webgpu_build(ctx, pipeline, params, entries, h, n_seqs);
     }

-    return ggml_backend_webgpu_build(ctx, pipeline, params, entries, h, n_seqs);
+    // split replay: a first pass runs the pending tokens and writes the state where the main pass starts
+    webgpu_pipeline replay_pipeline = ctx->shader_lib->get_gated_delta_net_replay_pipeline(shader_lib_ctx);
+
+    ggml_tensor * state_dst = dst_fuse ? dst_fuse : dst;
+
+    std::vector<uint32_t> replay_params = {
+        h,
+        (uint32_t) src0->ne[1],
+        dst_fuse ? (uint32_t) (ggml_webgpu_tensor_misalignment(ctx, dst_fuse) / ggml_type_size(dst_fuse->type)) :
+                   s_v * h * n_tokens * n_seqs,
+        (uint32_t) ggml_get_op_params_i32(dst, 1),  // n_pend
+
+        (uint32_t) (pend_k->nb[1] / ggml_type_size(pend_k->type)),
+        (uint32_t) (pend_k->nb[2] / ggml_type_size(pend_k->type)),
+        (uint32_t) (pend_k->nb[3] / ggml_type_size(pend_k->type)),
+
+        (uint32_t) (pend_v->nb[1] / ggml_type_size(pend_v->type)),
+        (uint32_t) (pend_v->nb[2] / ggml_type_size(pend_v->type)),
+        (uint32_t) (pend_v->nb[3] / ggml_type_size(pend_v->type)),
+
+        (uint32_t) (pend_gb->nb[1] / ggml_type_size(pend_gb->type)),
+        (uint32_t) (pend_gb->nb[2] / ggml_type_size(pend_gb->type)),
+        (uint32_t) (pend_gb->nb[3] / ggml_type_size(pend_gb->type)),
+    };
+
+    std::vector<wgpu::BindGroupEntry> replay_entries = {
+        ggml_webgpu_make_tensor_bind_group_entry(ctx, 0, src5),
+        ggml_webgpu_make_tensor_bind_group_entry(ctx, 1, pend_k),
+        ggml_webgpu_make_tensor_bind_group_entry(ctx, 2, pend_v),
+        ggml_webgpu_make_tensor_bind_group_entry(ctx, 3, pend_gb),
+        ggml_webgpu_make_tensor_bind_group_entry(ctx, 4, n_rep),
+        ggml_webgpu_make_tensor_bind_group_entry(ctx, 5, state_dst),
+    };
+
+    return ggml_backend_webgpu_build_multi(
+        ctx, {
+                 { replay_pipeline, std::move(replay_params), std::move(replay_entries), { h, n_seqs } },
+                 { pipeline,        std::move(params),        std::move(entries),        { h, n_seqs } },
+    });
 }

 static std::optional<webgpu_encoded_op> ggml_webgpu_set_rows(webgpu_context & ctx,
@@ -3910,9 +3946,7 @@ static std::optional<webgpu_encoded_op> ggml_webgpu_encode(webgpu_context ctx,
             return ggml_webgpu_ssm_scan(ctx, src0, src1, src2, node->src[3], node->src[4], node->src[5], node->src[6],
                                         node);
         case GGML_OP_GATED_DELTA_NET:
-            if (ggml_webgpu_gated_delta_net_n_storage_buffers(node, true) <=
-                    ctx->global_ctx->capabilities.limits.maxStorageBuffersPerShaderStage &&
-                ggml_webgpu_can_fuse_gdn_cache(ctx->global_ctx, cgraph, node_idx, num_encoded_ops)) {
+            if (ggml_webgpu_can_fuse_gdn_cache(ctx->global_ctx, cgraph, node_idx, num_encoded_ops)) {
                 ggml_tensor * dst_fuse = cgraph->nodes[node_idx + num_encoded_ops - 1]->src[1];
                 return ggml_webgpu_gated_delta_net(ctx, src0, src1, src2, node->src[3], node->src[4], node->src[5],
                                                    node, dst_fuse);
@@ -5459,9 +5493,7 @@ static bool ggml_backend_webgpu_device_supports_op(ggml_backend_dev_t dev, const
                               src2->type == GGML_TYPE_F32 && op->src[3]->type == GGML_TYPE_F32 &&
                               op->src[4]->type == GGML_TYPE_F32 && op->src[5]->type == GGML_TYPE_F32 &&
                               s_v <= ctx->webgpu_global_ctx->capabilities.limits.maxComputeInvocationsPerWorkgroup &&
-                              ggml_are_same_stride(src0, src1) &&
-                              ggml_webgpu_gated_delta_net_n_storage_buffers(op, false) <=
-                                  ctx->webgpu_global_ctx->capabilities.limits.maxStorageBuffersPerShaderStage;
+                              ggml_are_same_stride(src0, src1);
             }
             break;
         case GGML_OP_CLAMP:
diff --git a/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net.wgsl b/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net.wgsl
index 1a5b3208b..dac07d639 100644
--- a/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net.wgsl
+++ b/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net.wgsl
@@ -14,40 +14,44 @@ var<storage, read_write> src_g: array<f32>;
 var<storage, read_write> src_beta: array<f32>;

 @group(0) @binding(5)
-var<storage, read_write> src_state: array<f32>;
-
-@group(0) @binding(6)
 var<storage, read_write> dst: array<f32>;

 #ifdef FUSED_CACHE
-@group(0) @binding(7)
+@group(0) @binding(6)
 var<storage, read_write> dst_fuse: array<f32>;
 #define DST_SNAP dst_fuse
-#define NEXT_BINDING 8
+#define NEXT_BINDING 7
 #else
 #define DST_SNAP dst
-#define NEXT_BINDING 7
+#define NEXT_BINDING 6
 #endif

-#ifdef REPLAY
-// pending tokens to run before the new ones (see ggml_gated_delta_net_ext)
+// REPLAY runs the pending tokens of ggml_gated_delta_net_ext in this pass. REPLAY_SPLIT runs them in the separate pipeline.
+#ifdef REPLAY_SPLIT
+#define PARAMS_BINDING NEXT_BINDING
+#else
 @group(0) @binding(NEXT_BINDING)
-var<storage, read_write> pend_k: array<f32>;
+var<storage, read_write> src_state: array<f32>;

+#ifdef REPLAY
 @group(0) @binding(NEXT_BINDING + 1)
-var<storage, read_write> pend_v: array<f32>;
+var<storage, read_write> pend_k: array<f32>;

 @group(0) @binding(NEXT_BINDING + 2)
-var<storage, read_write> pend_gb: array<f32>;
+var<storage, read_write> pend_v: array<f32>;

 @group(0) @binding(NEXT_BINDING + 3)
+var<storage, read_write> pend_gb: array<f32>;
+
+@group(0) @binding(NEXT_BINDING + 4)
 var<storage, read_write> n_rep: array<i32>;

 var<workgroup> wg_n_rep: u32;

-#define PARAMS_BINDING (NEXT_BINDING + 4)
+#define PARAMS_BINDING (NEXT_BINDING + 5)
 #else
-#define PARAMS_BINDING NEXT_BINDING
+#define PARAMS_BINDING (NEXT_BINDING + 1)
+#endif
 #endif

 struct Params {
@@ -125,7 +129,12 @@ fn main(

     var state: array<f32, S_V>;
     for (var i = 0u; i < S_V; i++) {
+#ifdef REPLAY_SPLIT
+        // each thread reads back the row it alone wrote in the replay pass, and overwrites it at most once below
+        state[i] = DST_SNAP[snap_off + state_out_base + col * S_V + i];
+#else
         state[i] = src_state[state_in_base + col * S_V + i];
+#endif
     }

 #ifdef REPLAY
@@ -256,7 +265,7 @@ fn main(
         workgroupBarrier();
     }

-#ifdef REPLAY
+#if defined(REPLAY) || defined(REPLAY_SPLIT)
     // replay with keep: the state output is the state after the replay
     let write_state = params.K == 1u && params.keep == 0u;
 #else
diff --git a/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net_replay.wgsl b/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net_replay.wgsl
new file mode 100644
index 000000000..3ff5a81de
--- /dev/null
+++ b/ggml/src/ggml-webgpu/wgsl-shaders/gated_delta_net_replay.wgsl
@@ -0,0 +1,118 @@
+@group(0) @binding(0)
+var<storage, read_write> src_state: array<f32>;
+
+@group(0) @binding(1)
+var<storage, read_write> pend_k: array<f32>;
+
+@group(0) @binding(2)
+var<storage, read_write> pend_v: array<f32>;
+
+@group(0) @binding(3)
+var<storage, read_write> pend_gb: array<f32>;
+
+@group(0) @binding(4)
+var<storage, read_write> n_rep: array<i32>;
+
+// dst of the gdn op, or the fused cache view
+@group(0) @binding(5)
+var<storage, read_write> dst_state: array<f32>;
+
+struct Params {
+    h: u32,
+    neq1: u32,
+    state_off: u32,
+    n_pend: u32,
+
+    spk1: u32,
+    spk2: u32,
+    spk3: u32,
+
+    spv1: u32,
+    spv2: u32,
+    spv3: u32,
+
+    spg1: u32,
+    spg2: u32,
+    spg3: u32,
+};
+
+@group(0) @binding(6)
+var<uniform> params: Params;
+
+var<workgroup> sh_k: array<f32, S_V>;
+var<workgroup> sh_g: array<f32, S_V>;
+var<workgroup> wg_n_rep: u32;
+
+@compute @workgroup_size(WG_SIZE)
+fn main(
+    @builtin(workgroup_id) workgroup_id: vec3<u32>,
+    @builtin(local_invocation_id) local_id: vec3<u32>
+) {
+    let head_id = workgroup_id.x;
+    let seq_id = workgroup_id.y;
+    let col = local_id.x;
+
+    let iq1 = head_id % params.neq1;
+
+    let state_base = (seq_id * params.h + head_id) * S_V * S_V;
+
+    var state: array<f32, S_V>;
+    for (var i = 0u; i < S_V; i++) {
+        state[i] = src_state[state_base + col * S_V + i];
+    }
+
+    if (col == 0u) {
+        wg_n_rep = u32(n_rep[seq_id]);
+    }
+    let n_r = workgroupUniformLoad(&wg_n_rep);
+
+    for (var t = 0u; t < n_r; t++) {
+        let k_off = seq_id * params.spk3 + t * params.spk2 + iq1 * params.spk1;
+        let v_off = seq_id * params.spv3 + t * params.spv2 + head_id * params.spv1;
+        let g_off = seq_id * params.spg3 + t * params.spg2 + head_id * params.spg1;
+
+        sh_k[col] = pend_k[k_off + col];
+
+#ifdef KDA
+        sh_g[col] = exp(pend_gb[g_off + col]);
+#endif
+
+        workgroupBarrier();
+
+        let v_val = pend_v[v_off + col];
+        let beta_val = pend_gb[g_off + params.n_pend * params.spg2];
+
+        var kv_col = 0.0;
+        var delta_col = 0.0;
+
+#ifdef KDA
+        for (var i = 0u; i < S_V; i++) {
+            kv_col += (sh_g[i] * state[i]) * sh_k[i];
+        }
+
+        delta_col = (v_val - kv_col) * beta_val;
+
+        for (var i = 0u; i < S_V; i++) {
+            state[i] = sh_g[i] * state[i] + sh_k[i] * delta_col;
+        }
+#else
+        let g_val = exp(pend_gb[g_off]);
+
+        for (var i = 0u; i < S_V; i++) {
+            kv_col += state[i] * sh_k[i];
+        }
+
+        delta_col = (v_val - g_val * kv_col) * beta_val;
+
+        for (var i = 0u; i < S_V; i++) {
+            state[i] = g_val * state[i] + sh_k[i] * delta_col;
+        }
+#endif
+
+        workgroupBarrier();
+    }
+
+    for (var i = 0u; i < S_V; i++) {
+        dst_state[params.state_off + state_base + col * S_V + i] = state[i];
+    }
+}
diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp
index 37519b2e8..310b014b9 100644
--- a/tests/test-backend-ops.cpp
+++ b/tests/test-backend-ops.cpp
@@ -16367,6 +16367,10 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_perf() {
     test_cases.emplace_back(new test_gated_delta_net(GGML_TYPE_F32, 4, 128, 8192, 1));
     test_cases.emplace_back(new test_gated_delta_net(GGML_TYPE_F32, 20, 128, 1536, 1));
     test_cases.emplace_back(new test_gated_delta_net(GGML_TYPE_F32, 20, 128, 2048, 1));
+    // GDN replay of pending tokens (27B shape): decode, MTP verify (keep), prefill
+    test_cases.emplace_back(new test_gated_delta_net_replay(16, 128,   1, 1, 3, false, 4, false));
+    test_cases.emplace_back(new test_gated_delta_net_replay(16, 128,   4, 1, 3, false, 4, true));
+    test_cases.emplace_back(new test_gated_delta_net_replay(16, 128, 512, 1, 3, false, 4, false));

     // lightning_indexer
     for (int kv : { 256, 4096, 65536 }) {