From 845941f522c49b5964f017a4fefd43e77586a718 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 27 Oct 2026 21:17:42 +0100 Subject: [PATCH] metal: cand_blocks ran the block maxima and returned before the block selection: contexts past 16K tokens read an unwritten candidate list (needle lost at 17K+) --- src/dsv41/ds4_kernels.cu | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dsv41/ds4_kernels.cu b/src/dsv41/ds4_kernels.cu index 4c71cdea..13bda6e8 100644 --- a/src/dsv41/ds4_kernels.cu +++ b/src/dsv41/ds4_kernels.cu @@ -2379,8 +2379,9 @@ void cand_blocks(const float* score, long long stride, int T, const Rows& r, int nb_max = rb.n[t] > nb_max ? rb.n[t] : nb_max; } #if defined(STRATA_METAL) - // block_max_kernel on the Metal dispatch; the launch below is the fallback - if (strata::dsv41::metal_host::block_max(score, stride, T, &r, blk, bm, bm_stride, nb_max)) return; + // block_max_kernel on the Metal dispatch; the launch below is the fallback. The selection of the best blocks (topk) follows either way: + // returning here skipped it, the candidate list stayed unwritten and every context past 16K tokens (4,096 compressed rows) read garbage. + if (!strata::dsv41::metal_host::block_max(score, stride, T, &r, blk, bm, bm_stride, nb_max)) #endif strata_ds4_launch(block_max_kernel, dim3(cdiv(nb_max, kThreads), T), kThreads, 0, s, score, stride, r, blk, bm, bm_stride); topk(bm, bm_stride, T, rb, nullptr, 0, 1, out, out_stride, s);