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

Method __init__

llama_cpp/_internals.py:531–546  ·  view source on GitHub ↗
(self, *, n_vocab: int)

Source from the content-addressed store, hash-verified

529
530class LlamaTokenDataArray:
531 def __init__(self, *, n_vocab: int):
532 self.n_vocab = n_vocab
533 self.candidates_data = np.recarray(
534 (self.n_vocab,),
535 dtype=np.dtype(
536 [("id", np.intc), ("logit", np.single), ("p", np.single)], align=True
537 ),
538 )
539 self.candidates = llama_cpp.llama_token_data_array(
540 data=self.candidates_data.ctypes.data_as(llama_cpp.llama_token_data_p),
541 size=self.n_vocab,
542 sorted=False,
543 )
544 self.default_candidates_data_id = np.arange(self.n_vocab, dtype=np.intc) # type: ignore
545 self.default_candidates_data_p = np.zeros(self.n_vocab, dtype=np.single)
546 self.sampler = None # LlamaTokenDataArray doesn't use samplers, but some cleanup code expects this attribute
547
548 def copy_logits(self, logits: npt.NDArray[np.single]):
549 self.candidates_data.id[:] = self.default_candidates_data_id

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected