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

Method copy

examples/server/server.py:1099–1134  ·  view source on GitHub ↗
(
        self,
        source_sequence_id: int,
        dest_sequence_id: int,
        source_length: int,
        keep_len: int,
    )

Source from the content-addressed store, hash-verified

1097 return sum(increments[:keep_len])
1098
1099 def copy(
1100 self,
1101 source_sequence_id: int,
1102 dest_sequence_id: int,
1103 source_length: int,
1104 keep_len: int,
1105 ) -> None:
1106 assert source_sequence_id >= 0
1107 assert dest_sequence_id >= 0
1108 assert source_sequence_id in self._tails
1109 assert dest_sequence_id not in self._tails
1110 assert 0 <= keep_len <= source_length
1111 node = self._tails[source_sequence_id]
1112 path: List[SequenceHistory.Node] = []
1113 for _ in range(source_length - keep_len):
1114 parent = node.parent
1115 assert parent is not None
1116 node = parent
1117 while node is not self._root:
1118 path.append(node)
1119 parent = node.parent
1120 assert parent is not None
1121 node = parent
1122 parent = self._root
1123 position_length = 0
1124 for child in reversed(path):
1125 parent.children[dest_sequence_id] = child
1126 child.sequences.add(dest_sequence_id)
1127 position_length += child.position_increment
1128 parent = child
1129 if keep_len == 0:
1130 self._tails.pop(dest_sequence_id, None)
1131 self._position_lengths.pop(dest_sequence_id, None)
1132 else:
1133 self._tails[dest_sequence_id] = path[0]
1134 self._position_lengths[dest_sequence_id] = position_length
1135
1136 def truncate(
1137 self,

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected