Cider.Native
0.1.13
See the version list below for details.
dotnet add package Cider.Native --version 0.1.13
NuGet\Install-Package Cider.Native -Version 0.1.13
<PackageReference Include="Cider.Native" Version="0.1.13" />
<PackageVersion Include="Cider.Native" Version="0.1.13" />
<PackageReference Include="Cider.Native" />
paket add Cider.Native --version 0.1.13
#r "nuget: Cider.Native, 0.1.13"
#:package Cider.Native@0.1.13
#addin nuget:?package=Cider.Native&version=0.1.13
#tool nuget:?package=Cider.Native&version=0.1.13
Cider.Native
In-process GGUF v3 weight loader, selective $K$-row LM-head engine, and libllama CPU/GPU (Metal, Vulkan, CUDA) backend for Cider.NET.
Cider.Native runs System One decisions (Choice, Score, Noul) directly in-process from .gguf files or local Ollama model blobs (~/.ollama/models/blobs/) without requiring an external inference server.
Installation
dotnet add package Cider.Native
Key Components
LlamaCppBackend: Direct@DllImport("llama")P/Invoke backend with GPU offload (Metal on Apple silicon, Vulkan on Linux and Windows x64, CUDA when you supply it; see GPU backends) and CPU execution. Evaluates the sharedSystem + Stateprefix once onseq_id = 0and reuses/branches prefix KV and recurrent SSM states (llama_memory_seq_rm/llama_state_seq_get_data_ext) across all question suffixes.SelectiveLmHead: Projects the final normalized hidden state $h_{\text{last}} \in \mathbb{R}^d$ only against the $K \le 255$ permitted option token rows (F32,F16,BF16,Q8_0,Q4_0,Q4_K,Q6_K) rather than all151,936vocabulary rows (~38,000×output-head speedup).GgufFile&GgufTokenizer: Zero-dependency memory-mapped GGUF v2/v3 parser and byte-level BPE tokenizer with Qwen ChatML special-token support.Qwen3ManagedBackend: Pure managed G# GGUF execution backend powered bySelectiveLmHead.LlamaSession/LlamaSampler/TokenGenerator: In-process token generation for constrained and checked decoding:- llama.cpp sampler chains (greedy, temperature, top-k, top-p, min-p, seed), GBNF grammars and a
TokenMask(allow, deny, bias) applied before sampling. - Tokenize and detokenize, with partial-UTF-8-safe streaming (
Utf8PieceDecoder). - KV snapshot and rollback (
seq_rmtruncation or a state copy). - A streaming loop whose per-step callback can stop, roll back to a checkpoint, or change the mask.
- llama.cpp sampler chains (greedy, temperature, top-k, top-p, min-p, seed), GBNF grammars and a
Quick Start (G#)
package Demo
import Cider
import Cider.Native
import System
// Resolves local Ollama GGUF blob for "qwen3:0.6b" automatically without needing `ollama serve`
using let backend = LlamaCppBackend("qwen3:0.6b", nGpuLayers: -1)
let client = DecisionClient(backend, "qwen3:0.6b")
let pRefund = client.DecideNoul(
"Returns are allowed within 30 days. Purchase was 12 days ago.",
"Is this purchase eligible for a return?"
)
Console.WriteLine("P(eligible) = $pRefund")
Generation Quick Start (G#)
using let session = LlamaSession("/models/qwen3-0.6b.gguf", nGpuLayers: -1)
using let sampler = session.CreateSampler(
SamplingOptions.Greedy().WithGrammar("root ::= \"let \" [a-z]+ \" = \" [0-9]+ \"\\n\"")
)
let gen = TokenGenerator(session, sampler)
var lineStart GenerationCheckpoint? = nil
let result = gen.Run(session.Tokenize(prompt, false, true), GenerationOptions(), step -> {
if step.TextDelta.Contains("\n") {
// Statement boundary: check the prefix, then keep it (checkpoint) or roll back and ban.
lineStart = step.Generator.Checkpoint()
}
StepAction.Continue
})
Console.WriteLine(result.Text)
GPU backends
Cider.Native.Runtime.<rid> bundles the official llama.cpp b12110 release libraries. llama.cpp loads each
backend module it finds next to libllama at startup and skips any whose driver is missing, so one package
runs on the CPU everywhere and on the GPU where it can:
| RID | Bundled backends |
|---|---|
linux-x64, win-x64 |
CPU (runtime-selected AVX/AVX2/AVX-512 variants), Vulkan (NVIDIA, AMD and Intel GPUs; needs the GPU driver's Vulkan loader, libvulkan.so.1 / vulkan-1.dll) |
osx-arm64 |
CPU, Metal, BLAS (Accelerate) |
osx-x64 |
CPU, BLAS (llama.cpp publishes no Metal build for Intel Macs) |
linux-arm64, win-arm64 |
CPU |
Choosing a device
LlamaCppBackend, LlamaSession (and so TokenGenerator) take nGpuLayers and an optional
device: LlamaDeviceOptions:
// Default: offload every layer to the best GPU (discrete before integrated; CUDA before Metal/ROCm
// before Vulkan for the same card), otherwise run on the CPU and say why.
using let auto = LlamaSession(path, nGpuLayers: -1)
Console.WriteLine(auto.Placement.Describe()) // "vulkan on Vulkan1 (NVIDIA GeForce RTX 4060 Laptop GPU), gpu layers all"
using let cpu = LlamaSession(path, device: LlamaDeviceOptions.Cpu())
using let vk = LlamaCppBackend(path, device: LlamaDeviceOptions.Gpu("vulkan"))
using let one = LlamaSession(path, device: LlamaDeviceOptions.Gpu("Vulkan1", gpuLayers: 20, requireGpu: true))
LlamaDeviceOptions.Backend:auto,cpu, or a ggml backend name (vulkan,cuda,metal, ...).Device: ggml device names, comma-separated (Vulkan1,CUDA0,CUDA1).GpuLayers:-1all,0none.RequireGpu: throw instead of falling back to the CPU.- With the defaults, the
CIDER_LLAMA_BACKENDandCIDER_LLAMA_DEVICEenvironment variables choose instead (for exampleCIDER_LLAMA_BACKEND=cpu). Placement(on both classes) reports the devices the model was given andFallbackReasonwhen a GPU was requested but the model runs on the CPU (no GPU device, an unknown backend or device, or a GPU load that failed and was retried on the CPU). Cider also writes each fallback reason to stderr once per process (CIDER_LLAMA_QUIET=1silences it).BackendName/Name()reportllamacpp-cpu,llamacpp-vulkan,llamacpp-cudaorllamacpp-metal.LlamaRuntime.Devices(),RegisteredBackends(),BackendLoadErrors()andDescribe()show what the process loaded, and why a bundled GPU module did not load.cider-server --list-devicesprints the same.
CUDA
CUDA is not bundled: llama.cpp's ggml-cuda module is 160-600 MB and needs NVIDIA's cuBLAS (another
~870 MB), which would exceed NuGet's package size limit and repeat in the Cider.Server tool. On NVIDIA
GPUs the bundled Vulkan backend works without the CUDA toolkit. To use CUDA, take the module and runtime
from the same llama.cpp release (b12110; modules from other builds, such as Ollama's, fail with
undefined symbols) and point GGML_BACKEND_PATH at the module:
- Linux x64: from
llama-b12110-bin-ubuntu-cuda-12.8-x64.tar.gztakelibggml-cuda.so; fromcudart-llama-b12110-bin-ubuntu-cuda-12.8-x64.tar.gz(or an installed CUDA 12 toolkit) putlibcudart.so.12,libcublas.so.12andlibcublasLt.so.12onLD_LIBRARY_PATH. ThenGGML_BACKEND_PATH=/path/to/libggml-cuda.so. - Windows x64: from
llama-b12110-bin-win-cuda-13.4-x64.zip(or-cuda-12.4-) takeggml-cuda.dll, and from the matchingcudart-llama-bin-win-cuda-*-x64.zipput thecudart64_*.dll,cublas64_*.dllandcublasLt64_*.dllfiles onPATH. ThenGGML_BACKEND_PATH=C:\path\to\ggml-cuda.dll.
The CUDA and Vulkan devices of one card are then both listed; auto prefers CUDA.
License
MIT — see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Cider.NET (>= 0.1.13)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Cider.Native:
| Package | Downloads |
|---|---|
|
Hyperplane.Cider
Optional reader adapter for Hyperplane.NET: CiderEmbedder turns any Cider.NET IEmbeddingBackend (including Cider.Native's in-process llama.cpp LlamaEmbedder over GGUF models) into a Hyperplane IEmbedder with an honest, provenance-derived experimental profile. |
GitHub repositories
This package is not used by any popular GitHub repositories.