llama.cpp Sampling API

llama.cpp Sampling API

llama.cpp
https://github.com/ggerganov/llama.cpp

1. Sampling API

/home/yongqiang/llm_work/llama_cpp_25_01_05/llama.cpp/include/llama.h

复制代码
    //
    // Sampling API
    //
    // Sample usage:
    //
    //    // prepare the sampling chain at the start
    //    auto sparams = llama_sampler_chain_default_params();
    //
    //    llama_sampler * smpl = llama_sampler_chain_init(sparams);
    //
    //    llama_sampler_chain_add(smpl, llama_sampler_init_top_k(50));
    //    llama_sampler_chain_add(smpl, llama_sampler_init_top_p(0.9, 1));
    //    llama_sampler_chain_add(smpl, llama_sampler_init_temp (0.8));
    //
    //    // typically, the chain should end with a sampler such as "greedy", "dist" or "mirostat"
    //    // this sampler will be responsible to select the actual token
    //    llama_sampler_chain_add(smpl, llama_sampler_init_dist(seed));
    //
    //    ...
    //
    //    // decoding loop:
    //    while (...) {
    //        ...
    //
    //        llama_decode(ctx, batch);
    //
    //        // sample from the logits of the last token in the batch
    //        const llama_token id = llama_sampler_sample(smpl, ctx, -1);
    //
    //        // accepting the token updates the internal state of certain samplers (e.g. grammar, repetition, etc.)
    //        llama_sampler_accept(smpl, id);
    //        ...
    //    }
    //
    //    llama_sampler_free(smpl);
    //
    // TODO: In the future, llama_sampler will be utilized to offload the sampling to the backends (e.g. GPU).
    // TODO: in the future, the entire sampling API that uses llama_model should start using llama_vocab
    //
  • Autoregressive generation

/home/yongqiang/llm_work/llama_cpp_25_01_05/llama.cpp/examples/simple/simple.cpp

/home/yongqiang/llm_work/llama_cpp_25_01_05/llama.cpp/src/llama-sampling.h
/home/yongqiang/llm_work/llama_cpp_25_01_05/llama.cpp/src/llama-sampling.cpp

References

1 Yongqiang Cheng, https://yongqiang.blog.csdn.net/

相关推荐
容沁风11 天前
使用ninja编译llama.cpp
llama.cpp·2080ti·gemma4·vbr
撞强16 天前
AMM:一套支持 llama.cpp / vLLM / Diffusers 的 AI 模型统一调度平台
diffusers·vllm·llama.cpp·amm·6000d
寒水馨1 个月前
Linux下载、安装llama.cpp-b10068(附安装包llama-b10068-bin-ubuntu-vulkan-x64.tar.gz)
linux·ubuntu·llm·llama·本地部署·llama.cpp·推理引擎
Briwisdom1 个月前
Speculative Decoding:用小模型给大模型“打草稿“,推理加速 2-3×
模型部署·vllm·eagle·llama.cpp·prefill·speculative·decoding
SNOWPIAOP2 个月前
RTX 5090 本地部署 Qwen3-Coder-30B-A3B 实测:90 Tokens/s,128K 上下文,仅占用 22.4GB 显存
llama.cpp·5090·qwen3coder
Ki13813 个月前
N记消费/专业级Blackwell架构GPU,以编译方式安装llama.cpp
人工智能·llama.cpp·rtx pro 4000
碳基硅坊3 个月前
MTP在vLLM与llama.cpp上的性能对比:Qwen3.6与Gemma4实测
人工智能·vllm·llama.cpp·模型加速·mtp
cooldream20093 个月前
利用网络算力使用 Unsloth 实现llama大模型的微调部署调用
大模型微调·llama.cpp·unsloth
JOJO___3 个月前
【2026】记录在windows编译llama.cpp步骤,AMD CPU本地部署千问3.5本地大模型,内存占用低
windows·cpu·amd·llama.cpp·llama.cpp编译·千问3.5·本地大语言模型
曦云沐3 个月前
MacOS 上使用 Metal GPU 加速编译 llama.cpp 完整指南
macos·llama.cpp