Cider.Native 0.1.13

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cider.Native" Version="0.1.13" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cider.Native" Version="0.1.13" />
                    
Directory.Packages.props
<PackageReference Include="Cider.Native" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cider.Native --version 0.1.13
                    
#r "nuget: Cider.Native, 0.1.13"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Cider.Native@0.1.13
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cider.Native&version=0.1.13
                    
Install as a Cake Addin
#tool nuget:?package=Cider.Native&version=0.1.13
                    
Install as a Cake Tool

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 shared System + State prefix once on seq_id = 0 and 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 all 151,936 vocabulary 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 by SelectiveLmHead.
  • 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_rm truncation or a state copy).
    • A streaming loop whose per-step callback can stop, roll back to a checkpoint, or change the mask.

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: -1 all, 0 none. RequireGpu: throw instead of falling back to the CPU.
  • With the defaults, the CIDER_LLAMA_BACKEND and CIDER_LLAMA_DEVICE environment variables choose instead (for example CIDER_LLAMA_BACKEND=cpu).
  • Placement (on both classes) reports the devices the model was given and FallbackReason when 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=1 silences it). BackendName / Name() report llamacpp-cpu, llamacpp-vulkan, llamacpp-cuda or llamacpp-metal.
  • LlamaRuntime.Devices(), RegisteredBackends(), BackendLoadErrors() and Describe() show what the process loaded, and why a bundled GPU module did not load. cider-server --list-devices prints 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.gz take libggml-cuda.so; from cudart-llama-b12110-bin-ubuntu-cuda-12.8-x64.tar.gz (or an installed CUDA 12 toolkit) put libcudart.so.12, libcublas.so.12 and libcublasLt.so.12 on LD_LIBRARY_PATH. Then GGML_BACKEND_PATH=/path/to/libggml-cuda.so.
  • Windows x64: from llama-b12110-bin-win-cuda-13.4-x64.zip (or -cuda-12.4-) take ggml-cuda.dll, and from the matching cudart-llama-bin-win-cuda-*-x64.zip put the cudart64_*.dll, cublas64_*.dll and cublasLt64_*.dll files on PATH. Then GGML_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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
0.1.52 0 12/4/2026
0.1.51 0 12/4/2026
0.1.35 103 11/29/2026
0.1.34 218 11/28/2026
0.1.33 295 11/25/2026
0.1.13 118 11/18/2026
0.1.11 128 11/16/2026
0.1.9 126 11/16/2026
0.1.8 127 11/16/2026
0.1.5 112 11/14/2026
0.1.2 115 11/13/2026