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

Method apply_func

llama_cpp/llama.py:719–735  ·  view source on GitHub ↗
(token_data_array: llama_cpp.llama_token_data_array_p)

Source from the content-addressed store, hash-verified

717 if logits_processor is not None:
718 # Create and add a custom sampler
719 def apply_func(token_data_array: llama_cpp.llama_token_data_array_p):
720 size = token_data_array.contents.size
721 data_soa = token_data_array.contents.data
722 data_soa_address = ctypes.addressof(data_soa.contents)
723 # NOTE: This is probably broken
724 recarray = np.recarray(
725 shape=(size,),
726 dtype=np.dtype(
727 [("id", np.intc), ("logit", np.single), ("p", np.single)],
728 align=True,
729 ),
730 buf=(llama_cpp.llama_token_data * size).from_address(
731 data_soa_address
732 ),
733 )
734 for logit_processor in logits_processor:
735 recarray.logit[:] = logit_processor(self._input_ids, recarray.logit)
736
737 sampler.add_custom(apply_func)
738

Callers 1

apply_wrapperMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected