AI Skill Hub 推荐使用:LlamaCpp Elixir绑定 是一款优质的AI工具。AI 综合评分 7.5 分,在同类工具中表现稳健。如果你正在寻找可靠的AI工具解决方案,这是一个值得深入了解的选择。
运行LLM模型的Elixir绑定,支持Metal、CUDA、Vulkan或C
LlamaCpp Elixir绑定 是一款基于 Elixir 开发的开源工具,专注于 Elixir、LLM、CUDA 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
运行LLM模型的Elixir绑定,支持Metal、CUDA、Vulkan或C
LlamaCpp Elixir绑定 是一款基于 Elixir 开发的开源工具,专注于 Elixir、LLM、CUDA 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 克隆仓库 git clone https://github.com/nyo16/llama_cpp_ex cd llama_cpp_ex # 查看安装说明 cat README.md # 按 README 完成环境依赖安装后即可使用
# 查看帮助 llama_cpp_ex --help # 基本运行 llama_cpp_ex [options] <input> # 详细使用说明请查阅文档 # https://github.com/nyo16/llama_cpp_ex
# llama_cpp_ex 配置说明 # 查看配置选项 llama_cpp_ex --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export LLAMA_CPP_EX_CONFIG="/path/to/config.yml"
Elixir bindings for llama.cpp — run LLMs locally with Metal, CUDA, Vulkan, or CPU acceleration.
Built with C++ NIFs using fine for ergonomic resource management and elixir_make for the build system.
Streamenable_thinking support (Qwen3, Qwen3.5, etc.)| Quantization | RAM / VRAM | File size |
|---|---|---|
| Q4_K_M | ~20 GB | ~19 GB |
| Q8_0 | ~37 GB | ~36 GB |
| BF16 | ~70 GB | ~67 GB |
Add llama_cpp_ex to your list of dependencies in mix.exs:
def deps do
[
{:llama_cpp_ex, "~> 0.7.5"}
]
end
huggingface-cli download Qwen/Qwen3.5-35B-A3B-GGUF Qwen3.5-35B-A3B-Q4_K_M.gguf --local-dir models/ ```
```elixir
```elixir :ok = LlamaCppEx.init()
{:ok, model} = LlamaCppEx.load_model( Path.expand("~/Downloads/Qwen3.6-35B-A3B-MTP-Q4_K_M.gguf"), n_gpu_layers: 999 )
The examples/ directory contains runnable scripts demonstrating key features:
```bash
{:ok, ctx} = LlamaCppEx.Context.create(model, n_ctx: 4096) {:ok, sampler} = LlamaCppEx.Sampler.create(model, temp: 0.7, top_p: 0.9)
Stream.repeatedly(fn -> Process.sleep(200) s = LlamaCppEx.MTP.stats(mtp) IO.puts( "iters=#{s.iters} emitted=#{s.tokens_emitted} " <> "accept=#{Float.round(s.acceptance_rate * 100, 1)}% " <> "tok/s=#{Float.round(s.tokens_per_sec, 1)}" ) end) |> Stream.take_while(fn _ -> not Task.yield(gen_task, 0) |> match?({:ok, _}) end) |> Stream.run()
Task.await(gen_task, :infinity)
For in-band progress events (no separate process), use `stream_events/3` with `emit_stats_every`:
elixir mtp |> LlamaCppEx.MTP.stream_events("Write a sonnet:", max_tokens: 400, emit_stats_every: 32 ) |> Enum.each(fn {:token, _id, text} -> IO.write(text) {:stats, s} -> IO.puts("\n[stats] accept=#{Float.round(s.acceptance_rate * 100, 1)}%") {:done, final} -> IO.puts("\n[done]") {:eog, } -> IO.puts("\n[eog]") end) ```
LlamaCppEx.MTP.init/2:
:n_draft — draft tokens proposed per iteration (default 3). On NVIDIA, 2–4 is the sweet spot. On Apple Silicon, set this to 1 — see the Apple Silicon performance note above.:n_ctx, :n_threads, :flash_attn, :type_k/:type_v, :offload_kqv, … — any LlamaCppEx.Context option; applied to both target and draft contexts.LlamaCppEx.MTP.stream/3:
:max_tokens (default 256), plus all sampling options (:temp, :top_k, :top_p, :min_p, :seed, :penalty_*, :grammar).:emit_stats_every — when set, periodic {:stats, _} events become available via stream_events/3.{:ok, reply} = LlamaCppEx.chat(model, [ %{role: "user", content: "What is the capital of France?"} ], max_tokens: 256, enable_thinking: false, temp: 0.7, top_p: 0.8, top_k: 20, min_p: 0.0, penalty_present: 1.5) ```
For fine-grained control over the inference pipeline:
```elixir
Tokenize outside the GenServer to reduce contention under concurrent load:
model = LlamaCppEx.Server.get_model(server)
{:ok, tokens} = LlamaCppEx.Tokenizer.encode(model, prompt)
{:ok, text} = LlamaCppEx.Server.generate_tokens(server, tokens, max_tokens: 100)
Convert Ecto schema modules to JSON Schema automatically (requires {:ecto, "~> 3.0"} — optional dependency):
```elixir defmodule MyApp.Person do use Ecto.Schema
embedded_schema do field :name, :string field :age, :integer field :active, :boolean field :tags, {:array, :string} end end
LLAMA_MODEL_PATH=/path/to/model.gguf mix run examples/structured_output.exs
LlamaCppEx 是为 llama.cpp 提供的 Elixir 语言绑定库。它允许开发者直接在 Elixir 环境中加载并运行 GGUF 格式的模型,将强大的本地大语言模型推理能力无缝集成到 Elixir 应用生态中。
本项目支持直接从 Elixir 加载运行 GGUF 模型,并深度集成了 HuggingFace Hub,方便开发者搜索、列出及下载模型。在硬件加速方面,支持 Metal (macOS)、CUDA (NVIDIA)、Vulkan 及 CPU 运行。此外,它通过 lazy Stream 支持流式 Token 生成,并利用 RAII 资源管理机制,确保模型、Context 和 Sampler 等资源能被自动垃圾回收。
开发环境需要具备 C++17 编译器(如 GCC、Clang 或 MSVC)、CMake 3.14+ 以及用于管理 llama.cpp 子模块的 Git。硬件方面,请根据模型量化版本(如 Q4_K_M、Q8_0 或 BF16)预留足够的 RAM 或 VRAM 显存,例如运行 Q4_K_M 版本约需 20 GB 显存。
在项目中通过 mix.exs 添加 `{:llama_cpp_ex, "~> 0.7.5"}` 依赖即可完成安装。如果需要下载模型,建议安装 HuggingFace CLI(通过 `pip install huggingface-cli`),并使用命令行将指定的 GGUF 模型下载到本地目录中。
你可以通过 `LlamaCppEx.load_model/2` 加载本地模型,并设置 `n_gpu_layers` 参数来决定 GPU 卸载层数。对于简单的对话需求,可以使用 `LlamaCppEx.chat/4` 函数,它支持通过 `enable_thinking` 选项控制是否启用 Jinja 聊天模板中的思考过程(适用于 Qwen3 等模型)。
配置参数主要通过 `LlamaCppEx.MTP.init/2` 等函数进行设置。例如,`:n_draft` 参数在 NVIDIA 显卡上建议设为 2–4,而在 Apple Silicon 上建议设为 1。其他如 `:n_ctx`、`:n_threads`、`:flash_attn` 等 Context 参数均可根据推理需求进行精细化调整。
对于需要高并发或精细化控制的场景,本项目提供了更底层的 API。例如,你可以使用 `LlamaCppEx.Tokenizer.encode/2` 在 GenServer 外部进行预分词(Pre-Tokenized),以减少并发负载下的竞争,随后通过 `LlamaCppEx.Server.generate_tokens/3` 进行推理。
本项目提供了强大的 Ecto Schema 集成功能。通过配合 `ecto` 依赖,可以将 Ecto schema 模块自动转换为 JSON Schema。这使得开发者能够实现受约束的结构化输出生成(Constrained Generation),确保 LLM 返回的内容严格符合预定义的业务数据结构。
高质量的Elixir绑定,支持多种后端
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ Apache 2.0 — 宽松开源协议,可商用,需保留版权声明和 NOTICE 文件,含专利授权条款。
总体来看,LlamaCpp Elixir绑定 是一款质量良好的AI工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | llama_cpp_ex |
| 原始描述 | 开源AI工具: Elixir bindings for llama.cpp — run LLMs locally with Metal, CUDA, Vulkan, or C。⭐7 · Elixir |
| Topics | ElixirLLMCUDAMetalVulkan |
| GitHub | https://github.com/nyo16/llama_cpp_ex |
| License | Apache-2.0 |
| 语言 | Elixir |
收录时间:2026-05-29 · 更新时间:2026-05-30 · License:Apache-2.0 · AI Skill Hub 不对第三方内容的准确性作法律背书。