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

Method clone

llama_cpp/_internals.py:866–886  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

864 llama_cpp.llama_sampler_reset(self.sampler)
865
866 def clone(self):
867 # NOTE: Custom samplers cannot be cloned due to Python callback limitations
868 if self.custom_samplers:
869 raise NotImplementedError(
870 "Cannot clone LlamaSampler that contains custom samplers"
871 )
872
873 cloned_sampler = llama_cpp.llama_sampler_clone(self.sampler)
874 # Create a new wrapper around the cloned sampler
875 new_sampler = LlamaSampler.__new__(LlamaSampler)
876 new_sampler.sampler = cloned_sampler
877 new_sampler.custom_samplers = []
878 new_sampler._exit_stack = ExitStack()
879
880 def free_sampler():
881 if new_sampler.sampler is not None:
882 llama_cpp.llama_sampler_free(new_sampler.sampler)
883 new_sampler.sampler = None
884
885 new_sampler._exit_stack.callback(free_sampler)
886 return new_sampler

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected