@@ -1938,9 +1938,22 @@ int llama_context::decode(const llama_batch & batch_inp) {
19381938
19391939 const uint32_t n_embd = hparams.n_embd_out ();
19401940 float * embd_nextn_out = embd_nextn.data + offset*n_embd;
1941+ const size_t n_bytes = (size_t ) n_rows*n_embd*sizeof (float );
19411942
19421943 GGML_ASSERT ((offset + n_rows)*n_embd <= (int64_t ) embd_nextn.size );
1943- ggml_backend_tensor_get_async (backend_h, t_h_nextn, embd_nextn_out, 0 , n_rows*n_embd*sizeof (float ));
1944+ if (n_bytes > ggml_nbytes (t_h_nextn)) {
1945+ LLAMA_LOG_ERROR (
1946+ " %s: nextn embedding tensor is too small: masked=%d, n_rows=%lld, offset=%lld, "
1947+ " n_embd=%u, want=%zu bytes, have=%zu bytes, ne=[%lld, %lld, %lld, %lld], "
1948+ " ubatch.n_tokens=%u, n_outputs=%d, n_outputs_prev=%lld, n_tokens_prev=%lld\n " ,
1949+ __func__, (int ) masked, (long long ) n_rows, (long long ) offset,
1950+ n_embd, n_bytes, ggml_nbytes (t_h_nextn),
1951+ (long long ) t_h_nextn->ne [0 ], (long long ) t_h_nextn->ne [1 ],
1952+ (long long ) t_h_nextn->ne [2 ], (long long ) t_h_nextn->ne [3 ],
1953+ ubatch.n_tokens , n_outputs, (long long ) n_outputs_prev, (long long ) n_tokens_prev);
1954+ return -3 ;
1955+ }
1956+ ggml_backend_tensor_get_async (backend_h, t_h_nextn, embd_nextn_out, 0 , n_bytes);
19441957 }
19451958 }
19461959
0 commit comments