| 1199 | } |
| 1200 | |
| 1201 | void llama_kv_cache::set_input_v_idxs(ggml_tensor * dst, const llama_ubatch * ubatch, const slot_info & sinfo) const { |
| 1202 | const uint32_t n_tokens = ubatch->n_tokens; |
| 1203 | GGML_ASSERT(n_tokens == (int64_t) sinfo.size()*sinfo.n_stream()); |
| 1204 | |
| 1205 | GGML_ASSERT(ggml_backend_buffer_is_host(dst->buffer)); |
| 1206 | int64_t * data = (int64_t *) dst->data; |
| 1207 | |
| 1208 | if (!v_trans) { |
| 1209 | for (uint32_t s = 0; s < sinfo.n_stream(); ++s) { |
| 1210 | const int64_t offs = sinfo.strm[s]*get_size(); |
| 1211 | |
| 1212 | for (uint32_t i = 0; i < sinfo.size(); ++i) { |
| 1213 | data[s*sinfo.size() + i] = offs + sinfo.idxs[s][i]; |
| 1214 | } |
| 1215 | } |
| 1216 | } else { |
| 1217 | // note: the V cache is transposed when not using flash attention |
| 1218 | const int64_t kv_size = get_size(); |
| 1219 | |
| 1220 | const int64_t n_embd_v_gqa = hparams.n_embd_v_gqa_max(); |
| 1221 | |
| 1222 | for (uint32_t s = 0; s < sinfo.n_stream(); ++s) { |
| 1223 | const int64_t offs = sinfo.strm[s]*kv_size*n_embd_v_gqa; |
| 1224 | |
| 1225 | for (uint32_t i = 0; i < sinfo.size(); ++i) { |
| 1226 | for (uint32_t j = 0; j < n_embd_v_gqa; ++j) { |
| 1227 | data[s*sinfo.size()*n_embd_v_gqa + i*n_embd_v_gqa + j] = offs + j*kv_size + sinfo.idxs[s][i]; |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | void llama_kv_cache::set_input_k_shift(ggml_tensor * dst) const { |
| 1235 | GGML_ASSERT(ggml_backend_buffer_is_host(dst->buffer)); |
no test coverage detected