Docs
Concept in 60 seconds
Every time an LLM thinks, the reasoning is reconstructed from token statistics. NPCoT replaces that with: think once, cache the program, look it up forever. A library entry is a 5-tuple(init, transform, reduce, post_scale, offset)plus a normalized hidden-state signature. Lookups are cosine similarity, execution is a length-L arithmetic loop. Total cost per reasoning step at inference: ~4 ns.
Architecture
1. Train (one-time, GPU)
from ncpu.self_optimizing.array_executable_thought_head import (
ArrayExecutableThoughtHead, ArrayExecutableThoughtHeadConfig,
build_array_thought_smoke_batch, run_array_thought_smoke_train,
)
head = ArrayExecutableThoughtHead(ArrayExecutableThoughtHeadConfig(hidden_dim=16))
hidden, arrays, lengths, targets, _ = build_array_thought_smoke_batch(
hidden_dim=16, samples_per_op=12, operations=("sum", "min"),
)
run_array_thought_smoke_train(
head, hidden_state=hidden, array_inputs=arrays,
lengths=lengths, targets=targets, steps=500,
)2. Crystallize into library (gradient-free)
from ncpu.self_optimizing.program_library_session import (
ProgramLibrarySession, ProgramLibrarySessionConfig,
)
session = ProgramLibrarySession(
ProgramLibrarySessionConfig(
library_path="~/.nCPU_program_library.json",
convergence_gap_threshold=1.0,
)
)
session.begin_task("demo")
session.apply_converged_program(head, hidden, arrays, lengths=lengths)
summary = session.end_task()3. Consult at inference (CPU, WASM, or embedded)
# Python
from ncpu.self_optimizing.array_program_library import ArrayProgramLibrary
lib = ArrayProgramLibrary.load("my_library.json")
entry = lib.lookup(hidden_state)
result = entry.program.execute(arrays, lengths)
# Rust
let lib = load_library_from_json_bytes(&fs::read(path)?)?;
let result = consult_library_native(&lib.1, &hidden, &array, length);
# Browser (WASM)
const rt = new NpcotRuntime(await (await fetch('/lib.json')).text());
const result = rt.consult(hidden, array, length);Compliance
Every cached program is run through a static analyzer that proves termination, division safety, overflow bounds, and product stability. The compliance report aggregates to a singlesafe / warn / high verdict that your CI / release pipeline uses as a deployment gate.
python3 -m scripts.cli.npcot_compliance my_library.json --markdown python3 -m scripts.cli.npcot_compliance my_library.json --json > audit.json # Exit codes: 0=safe/warn, 2=missing file, 3=high risk (block deployment).
Privacy
Before publishing a library, a curator can run Gaussian perturbation on every signature to satisfy approximate (ε,δ)-DP:
from ncpu.self_optimizing.library_privacy import dp_perturb_library perturbed, cert = dp_perturb_library(lib, epsilon=1.0, delta=1e-5) print(cert) # DPCertificate(epsilon=1.0, delta=1e-5, sigma=X, sensitivity=2.0, ...)
Federation
Two libraries in the same domain can be merged by a broker. The broker never touches training data — only the libraries themselves.
from ncpu.self_optimizing.array_program_library import merge_libraries
merged = merge_libraries(
[alice_library, bob_library],
conflict_resolution="keep_more_hits",
)
print(merged.fingerprint()) # npcot1:<32-hex>