MCPcopy Index your code
hub / github.com/abetlen/llama-cpp-python / decode_batch

Method decode_batch

llama_cpp/llama.py:1108–1134  ·  view source on GitHub ↗
(seq_sizes: List[int])

Source from the content-addressed store, hash-verified

1106 data: Union[List[List[float]], List[List[List[float]]]] = []
1107
1108 def decode_batch(seq_sizes: List[int]):
1109 self._ctx.kv_cache_clear()
1110 self._ctx.decode(self._batch)
1111 self._batch.reset()
1112
1113 # store embeddings
1114 if pooling_type == llama_cpp.LLAMA_POOLING_TYPE_NONE:
1115 pos: int = 0
1116 for i, size in enumerate(seq_sizes):
1117 ptr = llama_cpp.llama_get_embeddings(self._ctx.ctx)
1118 embedding: List[List[float]] = [
1119 ptr[pos + j * n_embd : pos + (j + 1) * n_embd]
1120 for j in range(size)
1121 ]
1122 if normalize:
1123 embedding = [
1124 internals.normalize_embedding(e) for e in embedding
1125 ]
1126 data.append(embedding)
1127 pos += size
1128 else:
1129 for i in range(len(seq_sizes)):
1130 ptr = llama_cpp.llama_get_embeddings_seq(self._ctx.ctx, i)
1131 embedding: List[float] = ptr[:n_embd]
1132 if normalize:
1133 embedding = internals.normalize_embedding(embedding)
1134 data.append(embedding)
1135
1136 # init state
1137 total_tokens = 0

Callers

nothing calls this directly

Calls 4

kv_cache_clearMethod · 0.80
appendMethod · 0.80
decodeMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected