| 444 | } |
| 445 | |
| 446 | void llama_kv_cache::seq_div(llama_seq_id seq_id, llama_pos p0, llama_pos p1, int d) { |
| 447 | GGML_ASSERT(seq_id >= 0 && (size_t) seq_id < seq_to_stream.size()); |
| 448 | GGML_ASSERT(hparams.n_pos_per_embd() == 1 && "seq_div() is only supported for n_pos_per_embd() == 1"); |
| 449 | |
| 450 | auto & cells = v_cells[seq_to_stream[seq_id]]; |
| 451 | |
| 452 | if (d == 1) { |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | if (p0 < 0) { |
| 457 | p0 = 0; |
| 458 | } |
| 459 | |
| 460 | if (p1 < 0) { |
| 461 | p1 = std::numeric_limits<llama_pos>::max(); |
| 462 | } |
| 463 | |
| 464 | // If there is no range then return early to avoid looping over the cache. |
| 465 | if (p0 == p1) { |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | for (uint32_t i = 0; i < cells.size(); ++i) { |
| 470 | if (!cells.pos_in(i, p0, p1)) { |
| 471 | continue; |
| 472 | } |
| 473 | |
| 474 | if (cells.seq_has(i, seq_id)) { |
| 475 | cells.pos_div(i, d); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | llama_pos llama_kv_cache::seq_pos_min(llama_seq_id seq_id) const { |
| 481 | GGML_ASSERT(seq_id >= 0 && (size_t) seq_id < seq_to_stream.size()); |
no test coverage detected