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/

相关推荐
king135987455021 小时前
Clipstral 视频语义检索:FFmpeg PTS 验证、向量索引与端侧部署
人工智能·ffmpeg·音视频·大语言模型·llama·本地部署·llama.cpp
智码看视界1 天前
深度学习32:端侧部署——llama.cpp / GGUF 量化与手机运行
模型部署·量化·ollama·llama.cpp·gguf·端侧大模型
RuoyiOffice1 个月前
llama.cpp + SpringBoot3:本地部署 Qwen3.8,接入 AgentOS 企业办公智能体
spring boot·springboot3·llama.cpp·spring ai·qwen3.8·agentos
AI_Gump1 个月前
模型篇|llama.cpp 推理引擎深度解读:从一人练手到 LLM 端侧的事实标准
llama·llama.cpp
智码看视界1 个月前
开源大模型追踪:TurboQuant量化指南:128K上下文不再爆显存,KV缓存3-bit免重训
google·开源大模型·llama.cpp·显存优化·长上下文推理·turboquant·本地部署 开源大模型
神奇的代码在哪里2 个月前
没有独显也能跑多模态:MiniCPM-V 4.7-1B 本地 OCR 实测(附源码)
ocr·多模态大模型·llama.cpp·gguf·minicpm-v
容沁风2 个月前
llama.cpp浏览器访问404
win10·llama.cpp·web-ui
n112122 个月前
4G 显存老显卡怎么跑模型:llama.cpp 加 GGUF 配置
llama·llama.cpp·本地大模型·gguf
半甜柠檬2 个月前
llama.cpp 部署 Qwen3.8-27B:无独显轻薄本实测
大模型·qwen·量化·本地部署·llama.cpp
智码看视界2 个月前
开源大模型前沿:Baichuan 5 :单卡 H100 跑国产,长上下文 + 中文 Agentic 硬刚海外同档
开源·中文·llama.cpp·百川智能·国产大模型·baichuan 5