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

Class CustomSampler

llama_cpp/_internals.py:644–672  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

642
643
644class CustomSampler:
645 def __init__(self, apply_func: Callable[[llama_cpp.llama_token_data_array], None]):
646 self.apply_func = apply_func
647
648 def apply_wrapper(
649 sampler: llama_cpp.llama_sampler_p,
650 cur_p: llama_cpp.llama_token_data_array_p,
651 ):
652 self.apply_func(cur_p)
653
654 def free_wrapper(sampler: llama_cpp.llama_sampler_p):
655 pass
656
657 sampler_i = llama_cpp.llama_sampler_i()
658 sampler_i.apply = llama_cpp.llama_sampler_i_apply(apply_wrapper)
659 self._apply_wrapper_ref = apply_wrapper
660
661 sampler_i.name = llama_cpp.llama_sampler_i_name(0)
662 sampler_i.accept = llama_cpp.llama_sampler_i_accept(0)
663 sampler_i.reset = llama_cpp.llama_sampler_i_reset(0)
664 sampler_i.clone = llama_cpp.llama_sampler_i_clone(0)
665 sampler_i.free = llama_cpp.llama_sampler_i_free(0)
666
667 self.sampler = llama_cpp.llama_sampler()
668 self.sampler.iface = ctypes.pointer(sampler_i)
669 self.sampler.ctx = None
670
671 def get_sampler(self) -> llama_cpp.llama_sampler_p:
672 return ctypes.pointer(self.sampler)
673
674
675class LlamaSampler:

Callers 1

add_customMethod · 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…