MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / set_sampler

Method set_sampler

subprojects/llama.cpp/src/llama-context.cpp:1016–1058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1014}
1015
1016bool llama_context::set_sampler(llama_seq_id seq_id, llama_sampler * sampler) {
1017 if (!sampler && sampling.samplers.count(seq_id) == 0) {
1018 return true;
1019 }
1020
1021 LLAMA_LOG_DEBUG("%s: seq_id = %d, sampler = %p\n", __func__, (int) seq_id, (void *) sampler);
1022
1023 const bool can_offload =
1024 sampler &&
1025 sampler->iface->backend_init &&
1026 sampler->iface->backend_apply &&
1027 llama_sampler_chain_n(sampler) > 0;
1028
1029 if (sampler && can_offload) {
1030 auto * buft = ggml_backend_dev_buffer_type(model.dev_output());
1031
1032 sampler->iface->backend_init(sampler, buft);
1033
1034 sampling.samplers[seq_id] = sampler;
1035
1036 sched_need_reserve = true;
1037
1038 return true;
1039 }
1040
1041 if (sampler && !can_offload) {
1042 LLAMA_LOG_WARN("%s: sampler '%s' for seq_id = %d, cannot be offloaded to the backend\n", __func__, llama_sampler_name(sampler), seq_id);
1043
1044 if (sampling.samplers.count(seq_id) > 0) {
1045 sched_need_reserve = true;
1046 }
1047
1048 sampling.samplers.erase(seq_id);
1049
1050 return false;
1051 }
1052
1053 sampling.samplers.erase(seq_id);
1054
1055 sched_need_reserve = true;
1056
1057 return true;
1058}
1059
1060void llama_context::set_adapter_lora(
1061 llama_adapter_lora * adapter,

Callers 1

llama_set_samplerFunction · 0.80

Calls 6

llama_sampler_chain_nFunction · 0.85
llama_sampler_nameFunction · 0.85
dev_outputMethod · 0.80
backend_initMethod · 0.80
countMethod · 0.45

Tested by

no test coverage detected