Running Local LLMs with 'llama.cpp' Backend
Overview
Provides R bindings to the 'llama.cpp' library for running large language models. The package uses a lightweight architecture where the C++ backend library is downloaded at runtime rather than bundled with the package. Package features include text generation, reproducible generation, and parallel inference.
New Functions
- **
model_metadata(model)** — returns all GGUF key-value metadata as a named character vector. Useful for inspecting model architecture, quantization type, and embedded chat template. Example:model_metadata(model)["tokenizer.chat_template"].
Bug Fixes
- **Fixed
apply_chat_template()failing for Gemma 4 models** — Gemma 4 uses a<|turn>/<turn|>chat format not recognized byllama_chat_apply_template()(returns -1). The fallback now callscommon_chat_templates_apply()fromcommon/chat.cpp, which executes the Jinja2 template embedded in the model's GGUF directly. This works for any model with a valid Jinja2 template regardless of the C API whitelist.enable_thinkingdefaults totrue, so Gemma 4 generates thinking content naturally without a pre-closed thought block. Tool calls and multimodal content are not handled. - **Fixed stop token leaking in
generate()andgenerate_parallel()for ChatML models (OLMo, Llama 3)** — Two separate issues fixed: - *Windowed find*: OLMo tokenizes
<|im_end|>as 6 separate pieces, with the last piece being>\n(merging>and newline). The previous exact-suffix check failed because the response ended with<|im_end|>\ninstead of exactly<|im_end|>. Changed to a windowedfind()that searches within the laststop.size() + 4bytes and truncates at the match position. Applied to bothgenerate()andgenerate_parallel(). - *
<|start_header_id|>loop*: Llama 3.2 3B sometimes omits<|eot_id|>and jumps directly to<|start_header_id|>to begin a new turn, causing infinite repetition. Added<|start_header_id|>totext_stop_stringsin both functions. generate()'s stop list also expanded from{"<turn|>", "<end_of_turn>"}to{"<turn|>", "<end_of_turn>", "<|eot_id|>", "<|im_end|>", "<|start_header_id|>"}to matchgenerate_parallel().
Backend
- **Upgraded llama.cpp backend from b8664 → b8766** — 102 builds of improvements. Gemma 4 audio conformer encoder support, various bug fixes. The Gemma 4 template issue is not fixed upstream in this version; our local fallback is the active workaround.
Bug Fixes
- **Fixed verbosity not forwarded in
quick_llama()** —verbosityparameter was accepted but silently dropped when passed through to.generate_single()and.generate_multiple(), so backend logging level had no effect duringquick_llama()calls. Now correctly forwarded togenerate()andgenerate_parallel().
Show all changes in 1.3.0Hide the rest of the changes in 1.3.0
- **Fixed backend errors crashing R instead of being catchable** — All
Rcpp::stop()calls insrc/interface.cppreplaced withRf_error().stop()throws a C++ exception which crosses the C boundary (.Call()registration) and triggersstd::terminate(), killing the R process.Rf_error()useslongjmpwhich R's condition system can intercept, sotryCatch()now works correctly for all backend errors including the OOM guard. - **Fixed model-loading progress dots leaking to stderr with
verbosity = 0** —llama_model_load_from_file()has its ownprogress_callbackthat prints dots to stderr independently of the log callback system. Now set to a no-op whenverbosity < 2inlocalllm_model_load_safe(). Model loading is fully silent at the default generation verbosity.
Behavior Changes
- **
generate_parallel(progress)now defaults tointeractive()** — previously defaulted toTRUE, which printed carriage-return-based progress bars to log files andR CMD checkoutput. The new default shows the progress bar only in interactive R sessions and suppresses it in scripts and automated checks. - **
quick_llama(progress)now defaults tointeractive()** — same rationale as above; no effect on single-prompt calls.
API Changes
- **Removed
quick_llama(stream)parameter** — thestreamargument was present in the function signature but was never passed to any downstream function (it was placeholder code with a comment "available for future use"). Removed to avoid user confusion.
Backend
- **New
localllm_set_verbosity()C API** — added to the backend binary and wired through the proxy layer (proxy.h/cpp,interface.cpp,init.cpp). Enables per-call verbosity control at the C level (integer 0–3, negative = fully silent). Called automatically bygenerate(),generate_parallel(),model_load(), andcontext_create()before each C invocation. - **C-layer OOM crash guard in
localllm_model_load_safe()** — added a last-resort memory check that fires even whencheck_memory = FALSE. If the model file is larger than total physical RAM, the function now returns a clean error ("Model file (X.X GB) exceeds total physical RAM (Y.Y GB)...") instead of proceeding tollama_model_load_from_file()and letting macOS OOM-kill the R process silently. The guard only blocks provably-impossible loads (file size > total RAM) and does not interfere with the existing R-layer check. Supported on macOS (sysctl hw.memsize), Linux (/proc/meminfo MemTotal), and Windows (GlobalMemoryStatusEx).
Known Issues
- **R-layer
model_load()messages not suppressed byverbosity = 0** — Two R-levelmessage()calls inapi.R("Using cached model: ..." and the GPU/unified-memory info line) print unconditionally regardless ofverbosity. Theverbosityparameter controls only the C backend log level; these R-layer informational messages are a separate code path not yet gated on verbosity. Confirmed against Gemma 4 26B-A4B (IQ2_XXS) on 2026-04-12.
Documentation
- **Verbosity dual-default design now documented** —
generate()andgenerate_parallel()roxygen entries now explain why they default to0L(called in loops, per-call logs would be noisy) and cross-referencemodel_load()/context_create()(default1L, run once per session, warnings should be visible).
---
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK14 OK2026-04-22
- ERROR13 OK, 1 ERROR2026-04-18
- OK14 OK2026-03-10
Documentation
- Help pages
- 34 (1 internal)includes a package overview page
- Examples that run
- 13%2 run in a plain check · 1 only when donttest examples are enabled (R CMD check --as-cran) · 13 never run
- Exported functions with examples
- 50%
- Documented parameters
- 96%
- Return-value docs
- 100%
- Help pages citing references
- 3%
Downloads
Repository
- PRs merged (all time)
- 100%
- Median days to close, 50 most recently updated closed issues
- 18
- Median days to close, 50 most recently updated closed PRs
- 2
Stars over time
Forks over time
Releases over time
Issues over time
PRs over time
7 development-tooling and community-health practices detected across 5 families in the upstream repository
Checks run against github.com/eddieyang211/localllm on 2026-10-18.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2026-04-13 · The repository has a site deploy workflow
Show all practicesHide 1 practice
This repository shows signs of AI coding tools.
- GitHub Copilotfirst seen 2026-01-28Pull request: opened by its own account
- Claude Codefirst seen 2026-02-16Named in .gitignore: .claudeCommits: at least 3 crediting it in the message
- Claude Sonnet 4.63 commits · Apr 2026
Dependencies
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- 1.3.0Latest
- RR 4.6.0 released · 2026-04-24
- 1.2.12026-02-26 · diff ↗
- 1.2.02026-02-17 · diff ↗
- 1.1.02025-12-17 · diff ↗ ·
added 9 exports
hardware_profile, list_ollama_models, explore, annotation_sink_csv, document_start, document_end, compute_confusion_matrices, intercoder_reliability, validate - 1.0.12025-10-15
- RR 4.5.0 released · 2025-04-11
Package metadata
- First published
- 2025-10-15
- Total releases
- 5 / 1 yrs
- License
- MIT + file LICENSE OSI
- Minimum R
- ≥ 3.6.0
- Bundled data
- 11 KB / 1 file
- Download size
- 187 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("localLLM")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-21, which the citation names so these numbers can be found later. More on citing and the projects behind them.