How the Local Runtime Works
Under the hood, Kompile's local-runtime companion is powered by Eclipse DeepLearning4j (DL4J) / ND4J / SameDiff — a first-party native tensor, graph-compilation, and training engine maintained in tandem with Kompile.
This page explains why Kompile ships its own runtime alongside an agent harness, what platform spins and accelerators are supported, how DSP (DynamicShapePlan) and Kompile's compiler backends optimize models, and how everything plugs cleanly into the harness.
Why Kompile maintains a runtime alongside an agent harness
Most agent CLIs treat local inference as someone else's problem — telling users to install and manage Ollama, vLLM, or llama.cpp separately. Kompile intentionally builds and maintains its own native runtime alongside the harness for three reasons:
- We can train models, not just run inference. Inference-only wrappers cannot backpropagate. Because Kompile runs on SameDiff's full autodiff and graph engine, the exact same runtime that serves your local chat model also supports LoRA and QLoRA fine-tuning directly on quantized GGUF weights (keeping packed base weights frozen in memory instead of expanding them 4× to FP32), knowledge distillation, alignment, embeddings, OCR, and vision-language models.
- A seamless, zero-sidecar experience. Installing one overlay (
kompile install local-runtime) activates local LLMs, dense embeddings, cross-encoder rerankers, local document crawling, and knowledge graph reasoning together — sharing one VRAM budget (LocalServingRuntimePool), one model cache, and one CLI/MCP surface without juggling separate Python environments or background daemons. - Zero reliance on community runtime updates. When a new model architecture, MoE routing op, attention variant, quantization scheme, or structured tool-calling decode feature arrives, Kompile does not wait for upstream third-party engines to adopt it or work around mismatched op semantics. Ops are defined once in a unified native table and compiled across every supported backend (the legacy
llamacppplatform helper was retired once native CPU and GPU parity was reached).
Platform "spins" & supported hardware runtimes
Kompile separates the backend-agnostic CLI harness from platform-specific runtime spins, so every machine downloads only the native kernels that match its hardware.
Distribution spins & overlays
| Spin / Variant | Target | What It Ships |
|---|---|---|
cli-harness (default) | Linux, macOS, Windows | Slim native CLI binary (kompile) — zero Java, zero ND4J, zero GPU drivers. Works with cloud APIs, MCP agents, and kompile-peer. |
local-runtime overlay | Linux / macOS / Windows (cpu, cpu-avx2, cuda-12.6/12.9/13.1, vulkan, zluda, hexagon, tpu) | Backend-coupled companion (lib/kompile-local-runtime.jar) overlaid onto cli-harness via kompile install local-runtime --backend <profile>. |
Full platform spins (cpu-intel, cpu-arm, cuda, amd-zluda, full) | Workstations & servers | Complete platform bundle (kompile-server, kompile-chat, kompile-crawl-manager, kompile-model-staging, bundled runtime + backend natives). |
Mobile & embedded SDK spins (SDX / .sdz) | Android (Vulkan / Hexagon / Tensor), iOS, C/C++ | JVM-free native C runtime (libsdx) packaged as Android AARs or iOS XCFrameworks, plus GraalVM AOT sdx-llm binaries for desktop/server. |
Assistant Spins (.kspin) | Packaged personas | Signed, installable agent personas (kompile spin) that can bundle prompts, MCP tools, and a local GGUF model running on kompile-local. See Spins. |
Supported hardware & compiler engines
Rather than locking you to one vendor SDK, the runtime targets your accelerator through a dedicated execution/compilation engine:
| Hardware Target | Runtime & Compiler Engines | Notes |
|---|---|---|
| NVIDIA GPUs | CUDA + Triton + NVRTC / PTX + CUDA Graph replay | Triton compiles fused GPU kernels; NVRTC/PTX handles JIT segments; steady-state decode replays captured CUDA graphs. |
| AMD GPUs | ZLUDA / ROCm + Triton AMD lowering | Runs the GPU DSP/Triton pipeline on AMD hardware without requiring a separate model format. |
| Cross-vendor GPUs (Desktop & Android) | Vulkan (MLIR → SPIR-V) | Compiles fused SPIR-V compute shaders with persistent shader & pipeline disk caching; works across AMD, Intel, NVIDIA, and mobile GPUs. |
| Intel GPUs & CPUs | Level Zero (SPIR-V / Intel Triton), OpenVINO, oneDNN | Native Intel GPU dispatch and CPU/NPU graph optimization. |
| Apple Silicon | MLX (Metal) | Native Metal-backed execution on macOS arm64. |
| CPUs (x86_64 AVX2 & ARM64) | CPU-MLIR + native SIMD / OpenBLAS / oneDNN / Arm Compute Library | Multi-threaded execution on a shared worker pool with quantized matmul (ggml_qmatmul) for GGUF weights. |
| Mobile NPUs & Cloud Accelerators | Qualcomm Hexagon, Android NNAPI, Google TPU (StableHLO) | Edge NPU delegation and TPU graph execution for mobile and cluster deployments. |
How Kompile runs & optimizes models: DSP & Compilers
1. DynamicShapePlan (DSP)
In Kompile and DL4J, DSP stands for DynamicShapePlan (not digital signal processing).
Modern AI workloads — especially autoregressive LLM token decoding with a growing KV cache, vision-language models, and variable-length document embedding batches — execute the same graph topology thousands of times while tensor shapes shift on every step. Interpreting graphs op-by-op on every token adds heavy dispatch and allocation overhead.
DSP eliminates that overhead in three clean phases:
1. Warmup (SLOT_BY_SLOT)
Compiles graph wiring once into flat, array-indexed slots & segments
and observes live shapes across initial steps.
│
▼
2. Freeze & Compile (SHAPES_FROZEN)
Merges fusible segments, colors/reuses memory buffers (pointer-stable),
and compiles hot segments through the active hardware compiler backend.
│
▼
3. Steady-State Replay (REPLAYING)
Replays fused compiled kernels / native GPU graphs with minimal host
overhead — falling back safely to standard execution if needed.- Works for both inference and training: DSP accelerates token decoding (including INT8 KV cache and constrained JSON/tool-call decoding), embedding batches, and training loops (such as QLoRA forward/backward passes).
- Zero-copy buffer reuse: After freeze, buffer coloring reuses intermediate memory slots safely across steps instead of allocating and freeing GPU buffers per token.
2. Unified compiler lowering ("One Meta Emitter")
Historically, adding a new op or fusion rule across a dozen backends meant duplicating math and compiler plumbing everywhere. The runtime has converged on a single unified compiler model:
- One op definition (
KernelSpec): Each op's math and type rules are defined once, then lowered through a shared emitter architecture into the target engine's IR or bytecode — whether Triton (PTX/AMDGPU), NVRTC, MLIR → SPIR-V (Vulkan / Level Zero), CPU-MLIR, MLX, OpenVINO, oneDNN, or StableHLO. - Delegation + fusion: Subgraphs are fused into single GPU/CPU kernels wherever profitable, cutting memory bandwidth traffic between layers (e.g., RMSNorm + activation + projection chains and attention blocks).
3. Persistent disk caching (fast startup after the first run)
Compiling fused kernels (Triton PTX, Vulkan SPIR-V, NVRTC JIT modules, OpenVINO graphs) and building DSP plans takes a few seconds the very first time a model shape is seen. Kompile persists those compiled artifacts on disk across JVM restarts:
- Unified kernel artifact store (
KernelArtifactStore): Caches compiled binaries +.metaABI/version sidecars under~/.kompile/cache/, with LRU device-memory residency management so resident kernels stay within VRAM limits. - Persistent DSP plan cache (
DspPlanDiskCache): Saves compiled DSP plans under~/.kompile/cache/dsp/dsp_plan_cache/, keyed by native build fingerprint. Warmup happens once per native build — subsequent runs load straight from disk (DSP disk cache HIT) in milliseconds.
How it fits into the Kompile harness
Every local AI feature in Kompile flows through the same runtime stack:
kompile chat (--provider kompile-local / kompile-peer)
kompile crawl / rag_search / knowledge_graph / model_runtime
│
▼
LocalServingRuntimePool / kompile-model-staging (:8090)
(1 resident GPU runtime by default · 120s idle keep-warm · 128 MB prefix cache)
│
▼
SameDiff + DynamicShapePlan (DSP) + GGUF / ONNX / SDZ
│
▼
Unified Compiler & KernelArtifactStore (Triton / Vulkan / CPU-MLIR / MLX / ...)
│
▼
Host Hardware (CUDA · ROCm/ZLUDA · Vulkan · Metal · CPU · NPU)- Slim by default, heavy only where needed: Keep
cli-harnesslightweight on laptops, installlocal-runtimeon workstations or servers that have compute, and share GPU models across machines viakompile-peer. - Same models for agents and pipelines: Whether a model is answering a
kompile chatturn, acting as a local subagent worker (auth=none), embedding documents during a crawl, or running a LoRA fine-tune inkompile-model-staging, it runs on the exact same compiled execution engine.
Next steps
- Embeddings, Serving & Pipelines — how Kompile runs dense embeddings, semantic memory, local LLM serving, OCR/VLM pipelines, KGE learning, and QLoRA training across isolated subprocesses
- Local Models &
local-runtimeOverview — install commands,kompile local-models, VRAM lease pooling, andkompile-peer - Model Staging — GGUF/ONNX/TF conversion,
.karcharchives, LoRA/QLoRA training, and:8090REST serving - Kompile Spins — packaging prompts, MCP tools, and local GGUF models into installable
.kspinpersonas