]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
Fix chunks being too small with small matrix sizes (llama/17526)
authorAlberto Cabrera Pérez <redacted>
Wed, 26 Nov 2025 21:14:54 +0000 (21:14 +0000)
committerGeorgi Gerganov <redacted>
Thu, 11 Dec 2025 13:32:46 +0000 (15:32 +0200)
src/ggml-cpu/repack.cpp

index d1321191358936868679473e0d5b7fd657d73513..875faedf2df34644126bb2f14f00d018fa0d4098 100644 (file)
@@ -1731,12 +1731,13 @@ template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS, ggml_type PAR
             nchunk0 = (nr0 + min_chunk_size - 1) / min_chunk_size;
         }
 
-        if (nth == 1 || nchunk0 < nth || disable_chunking) {
+        int64_t dr0 = (nr0 + nchunk0 - 1) / nchunk0;
+        // Only increase nchunk0 to nth if it won't make chunks too small
+        if (nth == 1 || ((nchunk0 < nth || disable_chunking) && (nr0 + nth - 1) / nth >= min_chunk_size)) {
             nchunk0 = nth;
+            dr0 = (nr0 + nchunk0 - 1) / nchunk0;
         }
 
-        const int64_t dr0 = (nr0 + nchunk0 - 1) / nchunk0;
-
         // Ensure nchunk doesn't exceed the number of rows divided by minimum chunk size
         // This prevents creating too many tiny chunks that could overlap after alignment
         const int64_t max_nchunk = (nr0 + min_chunk_size - 1) / min_chunk_size;