MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / state_write

Method state_write

smallthinker/src/llama-kv-cache-recurrent.cpp:680–716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

678}
679
680void llama_kv_cache_recurrent::state_write(llama_io_write_i & io, llama_seq_id seq_id) const {
681 std::vector<std::pair<uint32_t, uint32_t>> cell_ranges; // ranges, from inclusive, to exclusive
682 uint32_t cell_count = 0;
683
684 // Count the number of cells with the specified seq_id
685 // Find all the ranges of cells with this seq id (or all, when -1)
686 uint32_t cell_range_begin = size;
687 for (uint32_t i = 0; i < size; ++i) {
688 const auto & cell = cells[i];
689 if ((seq_id == -1 && !cell.is_empty()) || cell.has_seq_id(seq_id)) {
690 ++cell_count;
691 if (cell_range_begin == size) {
692 cell_range_begin = i;
693 }
694 } else {
695 if (cell_range_begin != size) {
696 cell_ranges.emplace_back(cell_range_begin, i);
697 cell_range_begin = size;
698 }
699 }
700 }
701 if (cell_range_begin != size) {
702 cell_ranges.emplace_back(cell_range_begin, size);
703 }
704
705 // DEBUG CHECK: Sum of cell counts in ranges should equal the total cell count
706 uint32_t cell_count_check = 0;
707 for (const auto & range : cell_ranges) {
708 cell_count_check += range.second - range.first;
709 }
710 GGML_ASSERT(cell_count == cell_count_check);
711
712 io.write(&cell_count, sizeof(cell_count));
713
714 state_write_meta(io, cell_ranges, seq_id);
715 state_write_data(io, cell_ranges);
716}
717
718void llama_kv_cache_recurrent::state_read(llama_io_read_i & io, llama_seq_id seq_id) {
719 uint32_t cell_count;

Callers

nothing calls this directly

Calls 3

is_emptyMethod · 0.45
has_seq_idMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected