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/

相关推荐
智码看视界4 天前
开源大模型追踪:TurboQuant量化指南:128K上下文不再爆显存,KV缓存3-bit免重训
google·开源大模型·llama.cpp·显存优化·长上下文推理·turboquant·本地部署 开源大模型
神奇的代码在哪里7 天前
没有独显也能跑多模态:MiniCPM-V 4.7-1B 本地 OCR 实测(附源码)
ocr·多模态大模型·llama.cpp·gguf·minicpm-v
容沁风8 天前
llama.cpp浏览器访问404
win10·llama.cpp·web-ui
n1121217 天前
4G 显存老显卡怎么跑模型:llama.cpp 加 GGUF 配置
llama·llama.cpp·本地大模型·gguf
半甜柠檬20 天前
llama.cpp 部署 Qwen3.8-27B:无独显轻薄本实测
大模型·qwen·量化·本地部署·llama.cpp
智码看视界25 天前
开源大模型前沿:Baichuan 5 :单卡 H100 跑国产,长上下文 + 中文 Agentic 硬刚海外同档
开源·中文·llama.cpp·百川智能·国产大模型·baichuan 5
阆遤1 个月前
llama.cpp 0.4.0-dev 本地编译指南
ai·编译·llama.cpp
JiMoKuangXiangQu1 个月前
在 AllWinner T507 上部署 Qwen2.5-0.5B 大语言模型
人工智能·llama.cpp·推理引擎
智码看视界2 个月前
.NET 10 推理大模型TensorSharp 3.3.0 部署实测:纯.NET推理引擎反超llama.cpp 1.5倍,DFlash2提速62%
c#·.net·llama.cpp·.net 10·tensorsharp·本地大模型推理·开源推理引擎
容沁风2 个月前
使用ninja编译llama.cpp
llama.cpp·2080ti·gemma4·vbr