| 1066 | } |
| 1067 | |
| 1068 | ggml_tensor * llama_kv_cache::cpy_k(ggml_context * ctx, ggml_tensor * k_cur, ggml_tensor * k_idxs, int32_t il, const slot_info & sinfo) const { |
| 1069 | GGML_UNUSED(sinfo); |
| 1070 | |
| 1071 | const int32_t ikv = map_layer_ids.at(il); |
| 1072 | |
| 1073 | ggml_tensor * k = layers[ikv].k; |
| 1074 | |
| 1075 | const int64_t n_embd_head = k_cur->ne[0]; |
| 1076 | const int64_t n_head = k_cur->ne[1]; |
| 1077 | const int64_t n_tokens = k_cur->ne[2]; |
| 1078 | |
| 1079 | const int64_t n_embd_gqa = n_embd_head*n_head; |
| 1080 | |
| 1081 | // we can merge dims 0 and 1 |
| 1082 | // TODO: add ggml helper function for this? |
| 1083 | GGML_ASSERT(ggml_row_size(k_cur->type, n_embd_head) == k_cur->nb[1]); |
| 1084 | |
| 1085 | k_cur = ggml_view_2d(ctx, k_cur, n_embd_gqa, n_tokens, k_cur->nb[2], 0); |
| 1086 | |
| 1087 | const int64_t n_stream = k->ne[2]; |
| 1088 | |
| 1089 | if (n_stream > 1) { |
| 1090 | const int64_t kv_size = get_size(); |
| 1091 | |
| 1092 | assert(n_embd_gqa == k->ne[0]); |
| 1093 | assert(kv_size == k->ne[1]); |
| 1094 | |
| 1095 | // merge the buffer across all streams because the idxs are global |
| 1096 | k = ggml_reshape_2d(ctx, k, n_embd_gqa, kv_size*n_stream); |
| 1097 | } |
| 1098 | |
| 1099 | // store the current K values into the cache |
| 1100 | return ggml_set_rows(ctx, k, k_cur, k_idxs); |
| 1101 | } |
| 1102 | |
| 1103 | ggml_tensor * llama_kv_cache::cpy_v(ggml_context * ctx, ggml_tensor * v_cur, ggml_tensor * v_idxs, int32_t il, const slot_info & sinfo) const { |
| 1104 | GGML_UNUSED(sinfo); |
no test coverage detected