]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
context : round n_tokens to next multiple of n_seqs when reserving (#14140)
authorcompilade <redacted>
Thu, 12 Jun 2025 06:56:04 +0000 (02:56 -0400)
committerGitHub <redacted>
Thu, 12 Jun 2025 06:56:04 +0000 (02:56 -0400)
This fixes RWKV inference which otherwise failed
when the worst case ubatch.n_seq_tokens rounded to 0.

src/llama-context.cpp

index b130b484bcf6fd4c2c38a1b64de13962efe55be6..525a00d8adb952b0f5b034b15e48b54e2e1576f8 100644 (file)
@@ -1332,7 +1332,7 @@ ggml_cgraph * llama_context::graph_reserve(uint32_t n_tokens, uint32_t n_seqs, u
     LLAMA_LOG_DEBUG("%s: reserving a graph for ubatch with n_tokens = %4u, n_seqs = %2u, n_outputs = %4u\n", __func__, n_tokens, n_seqs, n_outputs);
 
     if (n_tokens % n_seqs != 0) {
-        n_tokens = (n_tokens / n_seqs) * n_seqs;
+        n_tokens = ((n_tokens + (n_seqs - 1)) / n_seqs) * n_seqs; // round to next multiple of n_seqs
         n_outputs = std::min(n_outputs, n_tokens);
 
         LLAMA_LOG_DEBUG("%s: making n_tokens a multiple of n_seqs - n_tokens = %u, n_seqs = %u, n_outputs = %u\n", __func__, n_tokens, n_seqs, n_outputs);