diff --git a/ggml/src/ggml-alloc.c b/ggml/src/ggml-alloc.c index a71838eafc69..61e0def9788e 100644 --- a/ggml/src/ggml-alloc.c +++ b/ggml/src/ggml-alloc.c @@ -1184,7 +1184,7 @@ static ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors_from_buft_impl( this_size = GGML_PAD(ggml_backend_buft_get_alloc_size(buft, t), alignment); } - if (cur_buf_size > 0 && (cur_buf_size + this_size) > max_size) { + if (cur_buf_size > 0 && this_size > 0 && (cur_buf_size + this_size) > max_size) { // allocate tensors in the current buffer if (!no_alloc && !alloc_tensor_range(ctx, first, t, buft, cur_buf_size, &buffers, &n_buffers)) { return NULL;