Skip to content

Commit 5449367

Browse files
authored
Fix chunks being too small with small matrix sizes (#17526)
1 parent 1d594c2 commit 5449367

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ggml/src/ggml-cpu/repack.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,12 +1731,13 @@ template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS, ggml_type PAR
17311731
nchunk0 = (nr0 + min_chunk_size - 1) / min_chunk_size;
17321732
}
17331733

1734-
if (nth == 1 || nchunk0 < nth || disable_chunking) {
1734+
int64_t dr0 = (nr0 + nchunk0 - 1) / nchunk0;
1735+
// Only increase nchunk0 to nth if it won't make chunks too small
1736+
if (nth == 1 || ((nchunk0 < nth || disable_chunking) && (nr0 + nth - 1) / nth >= min_chunk_size)) {
17351737
nchunk0 = nth;
1738+
dr0 = (nr0 + nchunk0 - 1) / nchunk0;
17361739
}
17371740

1738-
const int64_t dr0 = (nr0 + nchunk0 - 1) / nchunk0;
1739-
17401741
// Ensure nchunk doesn't exceed the number of rows divided by minimum chunk size
17411742
// This prevents creating too many tiny chunks that could overlap after alignment
17421743
const int64_t max_nchunk = (nr0 + min_chunk_size - 1) / min_chunk_size;

0 commit comments

Comments
 (0)