diff --git a/src/llama-context.cpp b/src/llama-context.cpp index 9ee64b566779..d76503d524ba 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -3090,7 +3090,8 @@ class llama_io_write_device : public llama_io_write_i { for (const auto & winfo : winfos) { auto * buft = ggml_backend_buffer_get_type(winfo.tensor->buffer); - const int64_t n = winfo.size/ggml_element_size(winfo.tensor); + GGML_ASSERT(winfo.size % ggml_type_size(winfo.tensor->type) == 0); + const int64_t n = winfo.size/ggml_type_size(winfo.tensor->type)*ggml_blck_size(winfo.tensor->type); auto & mbuf = mbufs_new[buft]; @@ -3221,7 +3222,8 @@ class llama_io_read_device : public llama_io_read_i { for (const auto & rinfo : rinfos) { auto * buft = ggml_backend_buffer_get_type(rinfo.tensor->buffer); - const int64_t n = rinfo.size/ggml_element_size(rinfo.tensor); + GGML_ASSERT(rinfo.size % ggml_type_size(rinfo.tensor->type) == 0); + const int64_t n = rinfo.size/ggml_type_size(rinfo.tensor->type)*ggml_blck_size(rinfo.tensor->type); auto & mbuf = mbufs_new[buft]; @@ -3288,8 +3290,8 @@ class llama_io_read_device : public llama_io_read_i { const size_t n_copy = std::min(src_size - src_off, dst_size - dst_off); - const size_t el = ggml_element_size(src_t); - const int64_t n_el = (int64_t) (n_copy / el); + GGML_ASSERT(n_copy % ggml_type_size(src_t->type) == 0); + const int64_t n_el = n_copy / ggml_type_size(src_t->type) * ggml_blck_size(src_t->type); auto * src_v = ggml_view_1d(ctx_scratch, src_t, n_el, src_off); ggml_backend_view_init(src_v);