llama_cpp_dart
Dart binding for llama.cpp --- high level wrappers for both Dart and Flutter
0.2.2
3.8K downloads/mo
#4242 most downloaded on pub.dev
netdur/llama_cpp_dart
What this package is like to depend on
Last release 22 days ago
01 Aug 2026
Release timing varies
gaps range from 2 weeks to 9 months
Nearly every release is documented
notes for 14 of 15 stable releases
Nothing withdrawn
no release was ever pulled
3 years old
22 releases · first in 2024
11 releases in the last 12 months
see the full history below
Release timeline
22 releases · Jan 2024 to Aug 2026Releases
latest 22-
0.9.0-dev.1201 Aug 2026 pre-releaseRelease notes
Open source →0.9.0-dev.12: Flutter plugin packaging, mobile API, deterministic tea…
…rdown
Release notes
Open source →Supersedes 0.9.0-dev.11, which was tagged and built but rejected by pub.dev at upload: only
build.dartandlink.dartare currently allowed underhook/. The AAR-extraction helper moved tolib/src/hook/android_native_assets.dartandhook/build.dartimports it by package URI. dev.11 was never published; its GitHub release assets are identical in content to this one.Same llama.cpp pin as dev.10 (
afeebe10, tagb10182) — no native rebuild required for behavior, but the artifacts are re-cut so the SwiftPM manifest and the bundled Android AAR match this tag.Added
- Android libraries are now bundled automatically. The package ships
a native-assets build hook (
hook/build.dart) that extracts the verified release AAR'sjni/<abi>/*.soand registers them as bundled code assets. Flutter apps no longer add anything to Gradle. Opt out withbundle_android: false, or point at a different artifact (for example the Snapdragon Hexagon AAR) withandroid_aar:, underhooks.user_defines.llama_cpp_dartin the app's pubspec. - Swift Package Manager support via
darwin/llama_cpp_dart, whose binary target is pinned to this release'sllama-xcframework.zip. This is how Flutter resolves the plugin now that SwiftPM is enabled by default on stable. CocoaPods is intentionally not supported. ContextParams.mobile()— smallnCtx/nBatch/nUbatchdefaults for phones and tablets, with the KV cache types overridable.LlamaModel.estimateVramBytes({int nCtx})— planning estimate for weights plus an f16 KV cache plus a 15% runtime-buffer allowance.isDisposedonLlamaModelandLlamaEngine.shiftPolicy/shiftonEngineChat.generate(), so long-reasoning chats can slide the context. Throws for multimodal histories, where media embeddings cannot be reconstructed after a shift.
Changed
LlamaEngine.spawn(libraryPath:)is now optional, defaulting to the platform library name. On Android that resolves the bundledlibllama.so. Existing calls that pass a path are unaffected.- Worker shutdown releases native memory deterministically. It now drains any in-flight generation, then disposes the mtmd context, llama context, and model explicitly instead of leaving them to process exit — the previous behavior leaked accelerator memory for apps that create and destroy engines over a session. Teardown failures are reported rather than swallowed, and every early-return path during worker init cleans up the partially constructed native state.
LlamaEngine.dispose()waits up to 30 seconds (was 2) for native teardown and now surfaces a teardown failure instead of discarding it.- SDK floor raised to Dart 3.10 / Flutter 3.44 for the native-assets hook API. Source reformatted with the newer Dart formatter.
Fixed
- The generated Android AAR no longer embeds an absolute build-host path
in
classes.jar. The placeholder entry was created from/tmp/..., so the cleanupzip -dnever matched it and the entry shipped in every AAR; on a Windows host it would have been the builder's home directory. Reported in #107.
Tooling
tool/package_apple_xcframework.shreplaces the inlinezipstep and usesdittoto preserve versioned-framework symlinks, then verifies the extracted archive'sInfo.plist,Versions/Currentsymlink, and code signature before it can be published.tool/check_android_aar_alignment.shgates every Android build on 16 KB ELFLOADalignment (see #107); CI additionally builds a throwaway Flutter app and asserts all five.sofiles reach the APK, and grepspub publish --dry-runso the AAR cannot drop out of the published package.- The test workflow resolves with the Flutter toolchain, since the package now declares a Flutter SDK constraint.
- Android libraries are now bundled automatically. The package ships
a native-assets build hook (
-
0.9.0-dev.1030 Jul 2026 pre-releaseRelease notes
Open source →release: 0.9.0-dev.10
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Release notes
Open source →Native rebuild required —
src/llama.cppmovedd6d0ce82→afeebe10(tagb10182), about seven weeks of upstream work.Changed
- Adapted to upstream
e6dd0e29a, which collapsed theuse_mmap/use_direct_io/use_mlockbooleans inllama_model_paramsinto a singlellama_load_modeenum.ModelParamskeeps its three booleans — they are mapped at the FFI boundary, so callers are unaffected. One semantic caveat: the enum has no direct-I/O-plus-mlock value, so when both are requested direct I/O wins and mlock is dropped.useDirectIokeeps its documented precedence overuseMmap. - Regenerated FFI bindings against the new pin. New upstream C API now
reachable but not yet wrapped:
llama_model_n_layer_nextn,llama_model_ftype,llama_ftype_name,llama_vocab_get_suppress_tokens, and the mtmd batch-encoding API (mtmd_batch_init/_add_chunk/_encode/_get_output_embd). mtmd_encodeis deprecated upstream in favor ofmtmd_encode_chunk. This package reaches multimodal viamtmd_helper_eval_chunksand never called it, so no change was needed.
Fixed
-
LlamaLibrary.disposenow clears the log callback.LlamaLog.silenceinstalls aPointer.fromFunctionbound to the isolate that registered it, but the slot it occupies lives in process-global llama.cpp/ggml state and outlives that isolate. The stale pointer stayed installed, so the next isolate to emit a log line invoked a callback owned by a dead isolate and the VM aborted with "Cannot invoke native callback from a different isolate". Surfaced by Dart 3.12's stricter cross-isolate check.Known remaining issue: parallel
dart teststill hits the concurrent variant of this race, where one isolate holds a live callback while another loads a model. Run the model-backed suite with-j 1untilsilence()stops using a Dart callback altogether.
Tooling
ffigen20.1.1 → 21.0.0,lints5.0.0 → 6.1.0 (dev dependencies). Note ffigen 21 requires Dart SDK ≥ 3.10 to run the generator; the package's ownsdk: ^3.5.0constraint for consumers is unchanged.- Fixed the ffigen
-resource-dircompiler-opt, which pointed at a clang 17 toolchain directory that no longer exists.
- Adapted to upstream
-
0.9.0-dev.910 Jun 2026 pre-releaseRelease notes
Open source →fix(build): disable MTMD_VIDEO across all native builds
The d6d0ce82 bump pulled in mtmd video decoding, which #includes
vendor/sheredom/subprocess.h and calls posix_spawn to launch ffmpeg. That
broke the Android CPU AAR build (posix_spawn isn't in the NDK at API 26),
and the feature is useless in every target we ship (it needs an ffmpeg
binary in PATH at runtime). MTMD_VIDEO defaults ON upstream; force it OFF
in all four build scripts. Only the mtmd_helper_video_* path drops out;
the bitmap-init symbols the binding uses are unaffected.Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Release notes
Open source →Native rebuild required —
src/llama.cppmoved6b4e4bd58→d6d0ce82(picks up Gemma-4 E2B/E4B MTP support, #24282).Removed: MTP / NextN speculative decoding
MtpSpeculativeDecoderis gone, along withContextType/ContextParams.ctxType. It relied on the NextN hidden-state staging API (llama_set_embeddings_nextn/llama_get_embeddings_nextn_ith, formerly*_pre_norm), which lives only in llama.cpp's private C++ header and had to be resolved by hand via C++-mangled symbols. That approach is ABI-fragile (broke on the upstreampre_norm→nextnrename; would not work under MSVC) and reaches past the public C API. The binding now uses only the ffigen-generated public C headers (llama.h+ mtmd). Classic target+draftSpeculativeDecoder(pure C API) is unaffected.
Changed
- Regenerated FFI bindings against the new pin:
llama_context_paramsgainsctx_other+n_outputs_max;llama_set_warmupis deprecated. - mtmd: adapt to the upstream video refactor —
mtmd_helper_bitmap_init_from_{file,buf}now take aplaceholderbool and return amtmd_helper_bitmap_wrapper(use.bitmap).
Native (Apple)
- The Apple xcframework now ships as a dynamic framework (was a static
archive). Consumers just Embed & Sign — no
-force_load, which fixes the iOSdlsym/dead-strip failure (#104) and a static-framework clean-build ordering trap. It bundlescommonand links Metal/Accelerate internally; the macOS slice uses the versioned bundle layout and each slice is signed with theorg.ggml.llamaidentifier so on-device installs validate.
-
0.9.0-dev.831 May 2026 pre-releaseRelease notes
Open source →Pure-Dart release on the same llama.cpp pin (tag
b9360, sha6b4e4bd58) — no native rebuild required.MTP (NextN) speculative decoding
MtpSpeculativeDecoder— self-speculative decoding driven by a model's own Multi-Token Prediction / NextN heads (no separate draft model). Pair a normal targetLlamaContextwith a draft context createdctxType: ContextType.mtpoff the same model. Mirrors upstream llama.cpp's MTP loop (PR #22673): the target emits pre-norm hidden states, the NextN head proposes tokens conditioned on them, and the target verifies a round in one pass. Output is byte-identical to plain greedy decoding.- Works on M-RoPE / multimodal models (Qwen3.6, etc.): rejected
drafts roll back via
PARTIAL_ONLY | ON_DEVICEstate checkpoints rather than partialseq_rm, which those models forbid. - Reads pre-norm hidden states through the
llama_set_embeddings_pre_norm/llama_get_embeddings_pre_norm_ithstaging symbols (resolved by hand since they are absent from the public header). This supersedes the dev.7 note that MTP-as-draft was blocked — it is now implemented. - Performance is hardware-dependent: high acceptance (85–92%, output
identical to greedy) but on Apple Metal it is ~break-even on MoE and
modestly slower on dense vs plain decode (per-submission overhead);
expected to win on cheaper-dispatch backends. Probe:
tool/probe_mtp.dart.
KV-cache quantization
KvCacheType.iq4_nl— exposesGGML_TYPE_IQ4_NL, the last upstream-supported KV cache type the binding was missing. ~4× compression likeq4_0but better quality from a non-linear codebook. See the README's KV-cache quantization section (incl. the symmetric_0integer-dot-product property and a note on fork-only TurboQuant).
-
0.9.0-dev.728 May 2026 pre-releaseRelease notes
Open source →llama.cpp submodule bumped from
gguf-v0.18.0-791-g5d56effdeto tagb9360(sha6b4e4bd58). 328 commits of upstream history, purely-additive C API delta (llama_context_type,llama_n_rs_seq, newllama_state_seq_flags,mtmd_get_cap_from_file, plus the context-params fieldsctx_type/n_rs_seq). Bindings regenerated; existing wrapper code unchanged.Embeddings
LlamaEngine.embed(text)— pooled and per-token embeddings via the worker isolate, with optional L2 normalization. ReturnsEmbeddingResultcovering both pooled (mean/cls/last/rank) and unpooled outputs.BatchEmbedder(sync) +LlamaEngine.embedBatch(texts)(off-thread) — embed N texts in a single decode pass by assigning each its own sequence id; amortizes per-token compute across the batch for RAG-style ingest. Requiresembeddings: true, a pooled pooling type, andnSeqMax >= texts.length.
Speculative decoding
SpeculativeDecoder— synchronous greedy and exact stochastic speculative decoding over a target + draftLlamaContextsharing a vocab. Greedy output is byte-identical to plain greedy on the target;temperature > 0runs themin(1, p/q)accept rule with residual resampling (distributionally identical to sampling the target), seed for reproducibility. Seeexample/probes/speculative_generate.dart. (MTP-as-draft is blocked upstream — it needs the non-publicllama_set_embeddings_pre_norm; the draft-model variant works today.)ContextType+nRsSeqonContextParams— build an MTP draft context against an MTP-capable target model for raw-FFI use.
New high-level surfaces
LlamaLora+LoraBinding, withLlamaContext.setLoraAdapters/clearLoraAdapters/setControlVector. LoRA stack swaps, metadata accessors, aLoRA invocation-token reads, and ReFT-style control vectors.MtmdBitmap/MtmdChunk/MtmdChunks/MtmdCapabilities— bitmap construction (raw RGB, raw audio, file decode, buffer decode),mtmd_input_chunksintrospection (kind, nTokens, nPos, id, text-token reads), plus a cheapmtmd_get_cap_from_fileprobe.
Context introspection and ops
nCtxSeq,nRsSeq, effectivepoolingType.- Runtime toggles:
setThreads,setEmbeddings,setCausalAttn,setWarmup,synchronize. - Memory ops:
memoryClear,memorySeqRm,memorySeqCp,memorySeqKeep,memorySeqAdd,memorySeqDiv,memorySeqPosMin/Max— covers forking, rollback, position shifting. - Logits & probs:
lastLogits,logitsAt,sampledTokenAt,sampledProbsAt,sampledCandidatesAt,sampledLogitsAt.
Diagnostics
ContextPerf/SamplerPerfsnapshots withperf()/resetPerf()/printPerf()onLlamaContextandSampler. Includes prompt/decoded tokens-per-second convenience getters.
Model / library accessors
LlamaModel:isDiffusion,isHybrid,nSwa,nEmbdInp,nEmbdOut,decoderStartToken,nClassifierOut,classifierLabel(i),ropeType(newRopeTypeenum),ropeFreqScaleTrain,metaCount+metaKeyAt/metaValueAt/metaValue(key)/metaEntries.LlamaLibrary:supportsMmap/Mlock/Rpc,maxParallelSequences,maxTensorBuftOverrides,timeUs,systemInfo(),initNuma(NumaStrategy.*).SplitPath.compose/decomposePrefixfor split-gguf filenames.
Sampler chain introspection
name,seed,chainCount,chainGet(i)(borrowed),chainRemove(i)(owned),clone(),apply(arr).
Session state
captureRawStateExt/restoreRawStateExtaccepting the newStateSeqFlags(mirrorsLLAMA_STATE_SEQ_FLAGS_*including the b9360 on-device snapshot bit).
Build
tool/build_native.shdisablesLLAMA_BUILD_SERVERandLLAMA_BUILD_APP: upstream b9360'stools/server/references mtmd symbols missing from its own public header. We ship neither target, so turning them off keeps--with-mtmdbuilding cleanly.
-
0.9.0-dev.630 Apr 2026 pre-releaseRelease notes
Open source →params: expose missing llama.cpp options across sampler/context/model
- SamplerParams: Mirostat (v1/v2), grammar (incl. lazy patterns), DRY,
XTC, dynamic temperature, adaptive-P, top-n-sigma, infill, logit
bias, shared min_keep. SamplerFactory.build now accepts model: for
vocab-dependent stages.
- ContextParams: RoPE scaling/freq, full YaRN knobs, pooling and
attention type, defrag threshold, no_perf, op_offload, swa_full,
kv_unified.
- ModelParams: split mode, main GPU, tensor split, device list, GGUF
kv overrides (int/float/bool/str), use_direct_io, use_extra_bufts,
no_host, no_alloc.
- README: link to aichat sample app.
- Bump to 0.9.0-dev.6 + CHANGELOG.Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Release notes
Open source →Closes the gap between the Dart binding's option surface and the underlying llama.cpp params. Purely additive — existing code keeps working with previous defaults.
Sampling —
SamplerParamsMirostatConfig(v1 + v2 withtau,eta,m). Terminal sampler when enabled — replaces thediststage.GrammarConfig— GBNF grammar plus optional lazy-trigger patterns and trigger tokens (llama_sampler_init_grammar/llama_sampler_init_grammar_lazy_patterns).DryConfig— DRY sampler (multiplier, base, allowed length, last-N, seq breakers).XtcConfig— XTC sampler (probability, threshold, min keep, seed).DynamicTempConfig— dynamic temperature (temp_ext: range, exponent).AdaptivePConfig— adaptive-P terminal sampler (target, decay, seed).LogitBiasEntrylist applied at the start of the chain.topNSigma,infill, and sharedminKeepfor top-p / min-p / typical / xtc.SamplerFactory.build(params, model: ...)—model:is now required when the chain uses grammar, DRY, infill, logit-bias, or Mirostat v1 (anything that needs the vocab orn_ctx_train).
Context —
ContextParamsRopeScalingType,PoolingType,AttentionTypeenums.ropeFreqBase,ropeFreqScale.- YaRN:
yarnExtFactor,yarnAttnFactor,yarnBetaFast,yarnBetaSlow,yarnOrigCtx. defragThreshold,noPerf,opOffload,swaFull,kvUnified.
Model —
ModelParamsSplitModeenum +mainGpu+tensorSplit(allocated tollama_max_devices()at load time).devices— list of backend device names (resolved fromLlamaBackends.list()).kvOverrides— int / float / bool / string GGUF metadata overrides with the standard NULL-terminated array layout.useDirectIo,useExtraBufts,noHost,noAlloc.
Docs
- README points at the
aichatsample app as a working Flutter integration reference.
Deferred (tracked for a later cycle)
progress_callback,cb_eval,abort_callback— need aNativeCallable.listenerwrapper with isolate-affinity rules.tensor_buft_overrides— needs a per-device buffer-type accessor inBackendDevicefirst.- Backend sampler chain (
llama_context_params.samplers) — still marked[EXPERIMENTAL]upstream.
-
0.9.0-dev.529 Apr 2026 pre-releaseRelease notes
Open source →Consolidates
0.9.0-dev.0through0.9.0-dev.5(none of dev.0–dev.4 were published to pub.dev). The 0.2.x line is a separate package shape — see MIGRATION.md.Highlights since 0.2.x
LlamaEngineworker isolate is the primary public API. Streaming token output viaStream<GenerationEvent>(sealed:TokenEvent|ShiftEvent|DoneEvent). Cancellation via stream subscription cancel.EngineSession(raw prompt) andEngineChat(message-history with chat template) on top of the engine isolate.- Multimodal (vision + audio) via llama.cpp's
mtmd. - Persistence:
EngineSession.saveState/loadStateandEngineChat.saveState/loadStatewith metadata-validated reload. llama-server-style context shift (ContextShiftPolicy.auto) gated onengine.canShift.- Three platform artifacts shipped from GitHub Releases:
- macOS dylib (for
dart test) - Apple xcframework (
ios-arm64,ios-arm64-simulator,macos-arm64) - Android AAR for
arm64-v8a, two flavors: CPU+mtmd (~2 MB) and Hexagon NPU + OpenCL + mtmd (~3.7 MB)
- macOS dylib (for
Validated end-to-end on real devices
- Galaxy S23 Ultra (Snapdragon 8 Gen 2, Android 14) — Hexagon NPU reachable from a third-party Flutter app on commercial firmware.
- Galaxy Fold7 (Snapdragon 8 Elite, Android 16) — same APK runs unchanged.
- MacBook Pro M1 Max (macOS 26) — Metal via dylib path.
- iPad M1 (iOS 26) — Metal + Accelerate BLAS via the bundled
CocoaPods
llama_cpp.podspec.
Bindings
- Backend inspection.
engine.devices(List<BackendDevice>),engine.hasAccelerator,engine.primaryAcceleratorName, and the pre-engineLlamaBackends.list(). Tells you which backends loaded on the current device. primaryAcceleratorNamepriority orders by registry name (HTP → Hexagon → Metal → CUDA → Vulkan) before type, so Snapdragon HTP wins over OpenCL even when ggml reports both astype=gpu.- KV-cache quantization.
ContextParams.typeK/typeVaccept any ofKvCacheType.{f32, f16, bf16, q8_0, q4_0, q4_1, q5_0, q5_1}.q8_0halves KV memory at small quality cost; useful on 8 GB Android devices with longer contexts. - Stderr capture.
LlamaLog.captureToFile(path)/LlamaLog.restoreStderr(). Toggleable redirect of llama.cpp/ggml log lines for Android, where stderr is not connected to logcat. - Auto
ADSP_LIBRARY_PATH.LlamaLibrary.load()reads/proc/self/mapson Android and exportsADSP_LIBRARY_PATHso FastRPC findslibggml-htp-v*.soskeleton libs without app-sideMethodChannelplumbing. LlamaBindingsis now exported. Lets callers using the raw FFI surface type variables / pass them around without reaching intosrc/.LlamaVersionis generated at build time. Exposes the package version, the llama.cpp submodule SHA + author date, and a runtimesystemInfo()wrapper aroundllama_print_system_info()(e.g.MTL : EMBED_LIBRARY = 1 | CPU : NEON = 1 | ACCELERATE = 1 | ...).
Removed since 0.2.x
- The
Llamagod-class. LlamaParent/LlamaChild/IsolateScope(replaced byLlamaEngine).LlamaServicemulti-session scheduler. Mobile apps do one conversation at a time; multi-session can be added back as a higher layer if needed.- The MCP client / server / agent surface.
TextChunker(RAG helper).- Hand-written chat-format classes (ChatML, Alpaca, Gemma, Harmony).
Modern llama.cpp embeds Jinja templates in the GGUF; we use
llama_chat_apply_templateinstead. - All non-mobile platform code: Linux, Windows, CUDA, Vulkan desktop. macOS is kept as a dev/test target.
- Bundled binary distribution. Native artifacts ship from GitHub Releases instead.
Known limitations
- Custom Jinja chat templates (some Unsloth quants) require manual prompt rendering. Real Jinja support is post-1.0.
- HTP only engages Q4_0 / Q8_0 quants in upstream ggml-hexagon.
K-quants (
Q4_K_*,Q5_K_*) and I-quants (IQ*) run on OpenCL+CPU. - HTP REPACK budget is ~2 GB per session; ≥7B-class models need a multi-session pattern not yet exposed by the binding.
- Multimodal generation does not auto-shift on context overflow
(matches
llama-server's behaviour). - Cosmetic:
ggml_metal_device_freeasserts at process exit because the worker doesn't dispose model/context. Harmless.
-
0.2.202 Jan 2026Release notes
Open source →- allow freeing the active slot by switching/detaching and reselecting a fallback
- ensure isolate child always replies on dispose/free, even when already torn down
- keep parent subscription alive through shutdown so free-slot confirmations are received
- cancel scope work before freeing slots to avoid in-flight races
- add opt-in KV auto-trim (sliding window) with example
example/auto_trim.dart
-
0.2.130 Dec 2025Release notes
Open source →- Android: Added OpenCL support for GPU acceleration (#91).
- Vision:
- Fixed crash in
mtmdcontext disposal. - Stable Qwen3-VL support.
- Fixed crash in
- Chat: Added experimental support for Qwen3-VL chat format (
_exportQwen3Jinja). - Fixes:
- Improved logging initialization (#88).
- Fixed stream processing crash in chat.
- Core: Updated
llama.cppsubmodule.
-
0.1.2+109 Nov 2025 -
0.1.109 Nov 2025Release notes
Open source →- State load / save
- llama.cpp 25ff6f7659f6a5c47d6a73eada5813f0495331f0
- harmony prompting syntax
- isolate has vision and verbose support
- mcp server / agent
- scope generation stopping
-
0.1.009 Jul 2025 -
0.0.925 Jun 2025Release notes
Open source →- Major internal refactoring to improve code organization and maintainability
- Fixed critical bug where subsequent prompts would fail due to batch seq_id memory management
- Improved position tracking for continuous conversation support
- Enhanced error handling and debugging capabilities
- Added foundation for future chat optimization features
- Breaking change: Internal API restructuring (public API remains stable)
-
0.0.805 Dec 2024Release notes
Open source →- disabled llava
- compatible with llama.cpp 42ae10bb
- add typed_isolate
- removed llama processor
-
0.0.727 Feb 2024 -
0.0.623 Jan 2024Release notes
Open source →- added initial support to load lora
- dart cli example
- fixed #3 by @danemadsen
-
0.0.521 Jan 2024Release notes
Open source →- removed assets defination
- added static property
Llama.libraryPathto set library path, in order to support linux and other platforms
-
0.0.419 Jan 2024Release notes
Open source →ModelParamsdisabled optionssplitsMode,tensorSplitandmetadataOverride
-
0.0.319 Jan 2024 -
0.0.219 Jan 2024 -
0.0.2+119 Jan 2024Nothing published for this version
-
0.0.116 Jan 2024