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

Function llama_kv_cache_seq_shift

llama.cpp:1819–1847  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1817}
1818
1819static void llama_kv_cache_seq_shift(
1820 struct llama_kv_cache & cache,
1821 llama_seq_id seq_id,
1822 llama_pos p0,
1823 llama_pos p1,
1824 llama_pos delta) {
1825 uint32_t new_head = cache.size;
1826
1827 if (p0 < 0) p0 = 0;
1828 if (p1 < 0) p1 = std::numeric_limits<llama_pos>::max();
1829
1830 for (uint32_t i = 0; i < cache.size; ++i) {
1831 if (cache.cells[i].has_seq_id(seq_id) && cache.cells[i].pos >= p0 && cache.cells[i].pos < p1) {
1832 cache.has_shift = true;
1833 cache.cells[i].pos += delta;
1834 cache.cells[i].delta += delta;
1835
1836 if (cache.cells[i].pos < 0) {
1837 cache.cells[i].pos = -1;
1838 cache.cells[i].seq_id.clear();
1839 if (new_head == cache.size) new_head = i;
1840 }
1841 }
1842 }
1843
1844 // If we freed up a slot, set head to it so searching can start there.
1845 // Otherwise we just start the next search from the beginning.
1846 cache.head = new_head != cache.size ? new_head : 0;
1847}
1848
1849//
1850// model loading and saving

Callers 3

mainFunction · 0.85
update_slotsMethod · 0.85
mainFunction · 0.85

Calls 3

maxFunction · 0.85
has_seq_idMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected