MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / PartitionedAttentionMemoryPolicy

Class PartitionedAttentionMemoryPolicy

examples/server/server.py:12813–12854  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12811
12812
12813class PartitionedAttentionMemoryPolicy(AttentionMemoryPolicy):
12814 def can_admit(self, request: CompletionRequest) -> bool:
12815 match_seq_id, match_length = self.match_prefix(request.prompt_tokens)
12816 match_length = request.prompt_plan.clamp_to_reusable_boundary(match_length)
12817 request.match_sequence_id = match_seq_id
12818 request.match_length = match_length
12819 claimable = match_seq_id in self.scheduler.free_sequences
12820 required_sequence_ids = request.internal_completion_count - int(claimable)
12821 reuse_len = self.reuse_len_for_request(request, match_length)
12822 if self.try_set_sequence_cache_match(
12823 request,
12824 resident_reuse_len=reuse_len,
12825 required_sequence_ids=request.internal_completion_count,
12826 ):
12827 return True
12828 if len(self.scheduler.unused_sequences) >= required_sequence_ids:
12829 return True
12830 best_free = match_seq_id if claimable else None
12831 for seq_id in self.reclaim_order(best_free):
12832 self.scheduler.delete_free_sequence(seq_id)
12833 if len(self.scheduler.unused_sequences) >= required_sequence_ids:
12834 request.match_sequence_id, request.match_length = self.match_prefix(
12835 request.prompt_tokens,
12836 )
12837 request.match_length = request.prompt_plan.clamp_to_reusable_boundary(
12838 request.match_length
12839 )
12840 return True
12841 return False
12842
12843 def copy_prompt_state(
12844 self,
12845 source_sequence_id: int,
12846 dest_sequence_id: int,
12847 keep_len: int,
12848 ) -> None:
12849 self.scheduler.copy_sequence_state(
12850 source_sequence_id,
12851 dest_sequence_id,
12852 keep_len,
12853 copy_all_state=True,
12854 )
12855
12856
12857class CheckpointMemoryPolicy(MemoryPolicy):

Callers 1

build_memory_policyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…