architecture
system_topology
Apah is a low-latency, high-throughput custom LLM inference engine designed from first principles to execute on NVIDIA GPUs with zero network egress:
+-------------------------------------------------------+
| Sovereign Workbench Agentic Applications |
+-------------------------------------------------------+
|
+----------------+----------------+
| |
OpenAI-Compatible API Ollama Native Shim
(/v1/chat/completions) (/api/chat, /api/embeddings)
| |
+----------------+----------------+
|
+----------------------+
| FastAPI Server Layer|
+----------------------+
|
+-------+-------+
| |
+--------------------+ +-------------------+
| Network & Airgap | | Tamper-Evident |
| Guard (Socket Patch| | Audit Logger |
+--------------------+ +-------------------+
|
+----------------+----------------+
| Continuous Batching Scheduler |
+---------------------------------+
|
+----------------+----------------+
| PagedAttention Memory Engine |
| (BlockPool & BlockTable) |
+---------------------------------+
|
+----------------+----------------+
| Tensor Parallel Execution |
| (NCCL AllReduce / Column-Row) |
+---------------------------------+
|
+----------------+----------------+
| CUDA Hardware Execution Engine |
+---------------------------------+
math_formalisms
core_algorithms
2.1 Autoregressive Decoding & KV-Cache Formulation
Let X = (x_1, x_2, ..., x_n) represent an input sequence of tokens. The autoregressive probability of generating sequence X is factorized as:
At generation step t, temperature-scaled Softmax over vocabulary size V produces next-token probabilities:
Key and Value activation matrices are appended per step without re-computing past tokens:
2.2 PagedAttention Memory Management Engine
Traditional padded allocation requires contiguous VRAM M_{padded} = 2 · B · L · H_{kv} · L_{max} · D · b_{bytes}, leading to memory waste:
Block table lookup maps logical token index i to physical block pool coordinates:
2.3 Multi-GPU Tensor Parallelism (Megatron-LM Style)
Column-parallel layers split projection weights along columns across N GPUs: W = [W_1, W_2, ..., W_N]. Each GPU computes Y_i = X · W_i independently.
Row-parallel layers split weights along rows: W = [W_1; W_2; ...; W_N]. Results are aggregated via an NCCL AllReduce-Sum:
2.4 Tamper-Evident Cryptographic SHA256 Hash Chain
Every inference request and system event is linked to previous hashes in a tamper-evident audit log:
airgap_isolation
network_hardening
- Socket Interception: When
APAH_AIRGAP_MODE=1is enabled, lower-level socket connections to external non-loopback IP addresses throwAirgapViolationError. - Loopback Exception: Connections to
127.0.0.1,localhost, and::1remain open for local agent IPC. - OS Sandbox: Systemd unit file enforces
PrivateNetwork=true,ProtectSystem=strict, andNoNewPrivileges=true.