11import numpy as np
22from typing import Union , List , Optional , Dict , Any , Tuple
3- import llama_cpp .llama_cpp as llama_cpp
3+ import llama_cpp .llama_cpp as llama_cpp_lib
44from .llama_types import Embedding
55from .llama import Llama
66# Pooling types from .llama_cpp
@@ -141,7 +141,7 @@ def embed(
141141
142142 # Determine the output dimension
143143 if is_rank :
144- out_dim = llama_cpp .llama_model_n_cls_out (self ._model .model )
144+ out_dim = llama_cpp_lib .llama_model_n_cls_out (self ._model .model )
145145 else :
146146 out_dim = self .n_embd ()
147147
@@ -166,9 +166,9 @@ def embed(
166166
167167 # Reset Context and Batch
168168 if self .verbose :
169- llama_cpp .llama_perf_context_reset (ctx )
169+ llama_cpp_lib .llama_perf_context_reset (ctx )
170170 self ._batch .reset ()
171- llama_cpp .llama_memory_clear (llama_cpp .llama_get_memory (ctx ), True )
171+ llama_cpp_lib .llama_memory_clear (llama_cpp_lib .llama_get_memory (ctx ), True )
172172
173173 # Initialize State Variables
174174 results : List [Any ] = []
@@ -190,7 +190,7 @@ def _decode_batch():
190190 doc_tokens_embd = []
191191 for _ in range (seq_len ):
192192 # Get the vector of the i-th token
193- ptr = llama_cpp .llama_get_embeddings_ith (ctx , curr_token_idx )
193+ ptr = llama_cpp_lib .llama_get_embeddings_ith (ctx , curr_token_idx )
194194 if ptr is None :
195195 # Fallback: append zero vector or skip (here we zero-pad to keep shape)
196196 doc_tokens_embd .append ([0.0 ] * out_dim )
@@ -207,7 +207,7 @@ def _decode_batch():
207207 else :
208208 for i in range (len (batch_seq_lens )):
209209 # Obtain the vector of the i-th sequence.
210- ptr = llama_cpp .llama_get_embeddings_seq (ctx , i )
210+ ptr = llama_cpp_lib .llama_get_embeddings_seq (ctx , i )
211211 data = ptr [:out_dim ]
212212
213213 if not is_rank :
@@ -219,7 +219,7 @@ def _decode_batch():
219219 results .append (data )
220220
221221 self ._batch .reset ()
222- llama_cpp .llama_memory_clear (llama_cpp .llama_get_memory (ctx ), True )
222+ llama_cpp_lib .llama_memory_clear (llama_cpp_lib .llama_get_memory (ctx ), True )
223223 batch_seq_lens = []
224224
225225 # Main Streaming Loop
@@ -272,7 +272,7 @@ def _decode_batch():
272272 _decode_batch ()
273273
274274 if self .verbose :
275- llama_cpp .llama_perf_context_print (ctx )
275+ llama_cpp_lib .llama_perf_context_print (ctx )
276276
277277 final_result = results [0 ] if is_single else results
278278
0 commit comments