| 1476 | } |
| 1477 | |
| 1478 | void llama_kv_cache::set_input_pos_bucket(ggml_tensor * dst, const llama_ubatch * ubatch) const { |
| 1479 | const int64_t n_tokens = ubatch->n_tokens; |
| 1480 | |
| 1481 | GGML_ASSERT(n_stream == 1 && "TODO: support multiple streams"); |
| 1482 | const auto & cells = v_cells[0]; |
| 1483 | |
| 1484 | GGML_ASSERT(ggml_backend_buffer_is_host(dst->buffer)); |
| 1485 | GGML_ASSERT(!ubatch->equal_seqs()); // TODO: use ubatch->n_seqs instead of failing |
| 1486 | |
| 1487 | int32_t * data = (int32_t *) dst->data; |
| 1488 | |
| 1489 | const int32_t n_kv = dst->ne[0]; |
| 1490 | |
| 1491 | for (int h = 0; h < 1; ++h) { |
| 1492 | for (int i = 0; i < n_tokens; ++i) { |
| 1493 | for (int j = 0; j < n_kv; ++j) { |
| 1494 | // the position when the cells is empty is irrelevant - it will be masked out later in the attention |
| 1495 | const llama_pos p0 = cells.is_empty(j) ? -1 : cells.pos_get(j); |
| 1496 | |
| 1497 | data[h*(n_kv*n_tokens) + i*n_kv + j] = llama_relative_position_bucket(p0, ubatch->pos[i], hparams.n_rel_attn_bkts, false); |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | size_t llama_kv_cache::total_size() const { |
| 1504 | size_t size = 0; |
no test coverage detected