Skip to content

How Kompile Uses the Local Runtime ​

Kompile doesn't just use local-runtime for local chat — the same Eclipse DL4J / ND4J / SameDiff engine powers dense embeddings, semantic memory, local LLM serving, OCR/VLM pipelines, knowledge graph learning, and LoRA/QLoRA fine-tuning, all isolated into dedicated subprocesses so heavy ML workloads never destabilize the CLI or web UI.


Subprocess isolation: keeping the CLI & web UI fast ​

Neither the main kompile CLI nor the web apps load native GPU/ND4J libraries directly into their main process. Instead, every ML workload runs in a dedicated subprocess (re-executing the running native binary with --subprocess=<type>, or launching the bundled runtime JAR) protected by SubprocessMemoryWatchdog and writing per-run rotated logs to ~/.kompile/logs/subprocesses/<id>.log:

Subprocess (--subprocess=)EntrypointRole
servingServingSubprocessMainLocal LLM inference behind a loopback API (127.0.0.1) for kompile-local chat and kompile local-models start
embeddingEmbeddingSubprocessMainPersistent dense embedding worker for document crawls and hybrid RAG
pipeline-servingPipelineServingSubprocessMainReusable stdio runtime for folder-local model pipelines (OCR, VLM, extraction, custom SameDiff graphs)
graph-matrix (:8094)GraphMatrixSubprocessMainIsolated vector/graph store and probabilistic reasoning (embeddingDisabled=true so graph ops don't compete for embedding VRAM)
learningLearningSubprocessMainKnowledge graph embedding (KGE) and probabilistic rule-weight learning during crawls
ingest / vector-population / model-initIngestSubprocessMain etc.Document conversion/chunking, vector indexing, and model warm initialization
trainingTrainingSubprocessMainLoRA / QLoRA fine-tuning, distillation, and alignment (via kompile-model-staging)

Every launcher resolves its ND4J backend through SubprocessBackendResolver — searching the shipped bundle first (lib/backends/<backend>, lib), so a distribution never mixes incompatible backend libraries.


1. Dense embeddings & hybrid RAG ​

Document crawls & search (EmbeddingSubprocessMain) ​

When you crawl PDFs, Office docs, Slack, Confluence, or repositories, Kompile routes chunks to a persistent EmbeddingSubprocessMain worker over a priority queue:

  • Built-in SameDiff encoders: bge-base-en-v1.5 (768-dim), BGE small/large, BGE-M3 (multilingual, 8K context), Arctic Embed L, and E5-base-v2 (BgeSameDiffEncoder, ArcticEmbedSameDiffEncoder, GenericDenseSameDiffEncoder).
  • Cross-encoder rerankers: MS MARCO MiniLM L-6 and L-12 rerank hybrid BM25 + dense candidate sets for higher precision.
  • Persistent DSP warmup: The first batch for a new native build compiles and caches the encoder's DSP plan (~/.kompile/cache/dsp/dsp_plan_cache/); every subsequent launch hits disk cache (DSP disk cache HIT) immediately.

Persistent agent memory (SemanticMemoryEngine) ​

Kompile's memory tool watches .kompile/memory/, ~/.kompile/memory/, and project auto-memory directories (re-scanning every 60 seconds) and ranks recalls using a two-tier strategy:

  • With local-runtime: Uses bge-base-en-v1.5 (768-dim dense embeddings via GenericDenseSameDiffEncoder, cached under ~/.kompile/models/) for semantic recall across sessions.
  • Zero-surprise lazy startup: By default, the ND4J/GPU dense encoder does not eagerly boot at CLI startup (kompile.memory.dense.autostart=false) — it starts only when explicitly requested or enabled (KOMPILE_MEMORY_DENSE_AUTOSTART=true).
  • Automatic lightweight fallback: On slim cli-harness installs — or when you set KOMPILE_MEMORY_DENSE_ENABLED=false (or -Dkompile.memory.dense.enabled=false) — SemanticMemoryEngine seamlessly uses lock-free TF-IDF cosine similarity with zero native library load.

2. Local LLM execution (ServingSubprocessMain) ​

When you chat with --provider kompile-local or start a daemon with kompile local-models start, Kompile launches ServingSubprocessMain (KompileLocalServingBootstrap):

  • Supported formats: Consumes GGUF/GGML models directly (via runtime-quantized ggml_qmatmul) as well as converted SameDiff (.sdz / .sdnb / .fb) and ONNX models.
  • Shared VRAM lease pool (LocalServingRuntimePool): Chat turns, local subagents, and local crawls lease a shared runtime instead of spawning duplicate GPU processes. Defaults to 1 resident runtime (-Dkompile.model.pool.maxRuntimes=1), a 120-second keep-warm idle window (-Dkompile.model.pool.idleMs=120000), and 128 MB of local prompt-prefix cache.
  • Production decode features: Autoregressive DSP replay with KV-cache growth, INT8 quantized KV decode, streaming responses, session continuation, and constrained JSON / tool-call decoding so local models can drive Kompile's MCP tools reliably.

3. Folder-local pipelines, OCR & VLMs (model_runtime & PipelineServingSubprocessMain) ​

Agents can acquire, convert, optimize, and execute local models inside any project folder — without starting a Kompile web server — using the model_runtime MCP tool and PipelineServingSubprocessMain:

model_runtime ActionWhat It Does
statusInspects the project's local model inventory under <project>/data/models
bootstrap / importAcquires models from a configured remote source or binds an existing localPath in place
convertConverts local ONNX, TensorFlow/Keras, GGUF/GGML, or SafeTensors files into SameDiff artifacts (configurable weightDtype: fp32, fp16, bf16, fp8, fp8_e5m2, int8, int4)
optimizeRuns SameDiff's provider-neutral GraphOptimizer with profiles (FULL, BASIC, TRANSFORMER, GPU, NONE) or explicit selectedPasses

Once provisioned, unified pipelines (such as Florence-2 OCR / vision-language extraction, document classifiers, or custom SameDiff models) execute inside reusable PipelineServingSubprocessMain stdio workers.


4. Knowledge graph learning & model training ​

Because local-runtime is backed by SameDiff's full training engine rather than an inference-only wrapper, Kompile also runs learning workloads locally:

  • Knowledge Graph Embedding (KGE) & rule learning (LearningSubprocessMain): Runs automatically as part of document crawl pipelines to train link-prediction embeddings and probabilistic rule weights over your extracted fact sheets.
  • Fine-tuning, alignment, distillation & abliteration (TrainingSubprocessMain & AbliterationService via kompile-model-staging): Supports full SameDiff fine-tuning, 8 PEFT methods (LoRA, QLoRA via ggml_qmatmul_lora, AdaLoRA, DyLoRA, DoRA, IA³, Prompt Tuning, Prefix Tuning), Logit Knowledge Distillation (LOGIT_KD), 6 alignment algorithms (RLHF, DPO, KTO, ORPO, PPO, GRPO), and training-free weight abliteration. Promoted models hot-swap directly into the running server without a restart.

See Model Import, Optimization, Fine-Tuning & Abliteration for the full inline model_runtime MCP guide, all 23 GraphOptimizer passes, PEFT/alignment/abliteration options, and staging_* MCP tools.


Next steps ​

Released under the Apache-2.0 License.