|
| 1 | +Mohawk Inference Engine — Architecture Spec |
| 2 | + |
| 3 | +Overview |
| 4 | + |
| 5 | +Goal: provide a production-grade inference engine that enables capabilities LM Studio does not: multi-device layer splitting, PQC-secured edge offload, and high-concurrency session management. This document describes the core subsystems, dataflows, APIs, security model, and implementation priorities for an MVP. |
| 6 | + |
| 7 | +1. Core concepts |
| 8 | + |
| 9 | +- Layer-splitting: partitioning a neural network at layer boundaries (or sub-layer blocks) so different partitions (slices) execute on different devices (GPU/NPU/CPU/edge). Each slice exposes a small runtime ABI for input/output activation tensors and metadata. |
| 10 | +- Offload: the act of sending one or more slices to a remote device for execution. Offloads must preserve confidentiality/integrity of model IP (weights) and activations as required by policy. |
| 11 | +- PQC-secured channel: post-quantum cryptography handshake + authenticated encryption for slice packages and RPC traffic. |
| 12 | +- Session manager: long-lived controller that maps client sessions to slice placements, manages QoS, adaptive batching, autoscaling, and failure recovery. |
| 13 | + |
| 14 | +2. High-level architecture |
| 15 | + |
| 16 | +Components: |
| 17 | +- Controller (central or local): plans partitioning, placement, and routes requests to workers. |
| 18 | +- Worker runtime: lightweight process on each device that accepts slice packages, registers capabilities (memory, device type), and executes slices. |
| 19 | +- Offload transport: secure RPC over TCP/QUIC with PQC handshake and integrity checks. |
| 20 | +- Session Manager: receives client requests, handles session state, batching, and QoS rules. |
| 21 | +- Scheduler: maps slices to workers, performs placement decisions using cost model and current telemetry. |
| 22 | +- Persistence: key/value store for slice metadata, session state, and logs (can be local filesystem or etcd for distributed setups). |
| 23 | + |
| 24 | +3. Layer-splitting design |
| 25 | + |
| 26 | +3.1 Partitioning model |
| 27 | +- Static split: for MVP, support deterministic splits at transformer block or attention/MLP block granularity. Input: model graph (ONNX, TorchScript), cost model, device inventory. Output: ordered list of slices with boundary tensor shapes and serialization descriptors. |
| 28 | +- Dynamic split (future): runtime re-partitioning based on latency/throughput signals. |
| 29 | + |
| 30 | +3.2 Slice format |
| 31 | +- Metadata: slice id, inputs/outputs shapes, parameter size, expected memory footprint, device hints, version, policy tags (private/public). |
| 32 | +- Artifact: serialized weights in compact format (FP16/int8 quantized optional) + small runtime glue to map tensor ops. |
| 33 | +- Transport container: authenticated envelope (PQC AEAD) + optional compression. |
| 34 | + |
| 35 | +3.3 Runtime ABI |
| 36 | +- Execute(slice_id, input_tensor, trace_id) -> output_tensor, metrics |
| 37 | +- Health(check) -> status |
| 38 | +- Preload(slice_id) -> ack |
| 39 | + |
| 40 | +3.4 Scheduling and placement |
| 41 | +- Cost model inputs: parameter size, compute FLOPs per-token, estimated activation sizes, device throughput and free memory, network latency. |
| 42 | +- Heuristics for MVP: place compute-heavy contiguous slices on GPU if available; place small parameter slices on CPU to lower memory duplication; prefer colocated slices to reduce network hops. |
| 43 | +- Backpressure: if a worker is loaded, controller routes slice to alternate worker or falls back to local execution. |
| 44 | + |
| 45 | +4. PQC-secured edge offload |
| 46 | + |
| 47 | +4.1 Security goals |
| 48 | +- Confidentiality of slice weights when policy requires (IP protection). |
| 49 | +- Integrity of slice artifacts and runtime RPCs. |
| 50 | +- Forward-secure key exchange resistant to quantum-capable adversaries. |
| 51 | + |
| 52 | +4.2 Keyflows and handshakes |
| 53 | +- Root authority: operator provides long-term signing key (classical/ECDSA) for worker identity; optionally use hardware TPM for key storage. |
| 54 | +- Session handshake: use a PQC KEM (e.g., Kyber or later NIST standard) to establish ephemeral symmetric AEAD keys per connection. Steps: |
| 55 | + 1. Controller/worker exchange identity-signed certificates (classical) and PQC KEM public values. |
| 56 | + 2. Both sides derive AEAD keys via HKDF over KEM shared secret and transcript. |
| 57 | + 3. Optionally request remote attestation token before accepting slices (attestation hooks, e.g., Intel SGX/SEV or MDS attestation APIs). |
| 58 | + |
| 59 | +4.3 Slice packaging & integrity |
| 60 | +- Each slice package: {manifest, weights.blob, signature, version} |
| 61 | +- Manifest contains policy tags; controller encrypts package with AEAD key and includes HMAC/signature for extra assurance. |
| 62 | +- Workers verify signature + AEAD before load. |
| 63 | + |
| 64 | +4.4 Performance considerations |
| 65 | +- PQC KEM handshake cost is paid per long-lived connection; reuse AEAD keys for multiple RPCs. |
| 66 | +- For high-throughput edge fleets, pre-provision slice packages to workers via provisioning channel to avoid repeated KEM costs. |
| 67 | + |
| 68 | +5. Session manager |
| 69 | + |
| 70 | +5.1 API (gRPC/HTTP) |
| 71 | +- StartSession(request {model, routingHints, qos, tenant}) -> session_id |
| 72 | +- Infer(session_id, input, options {sync|async}) -> response stream or token |
| 73 | +- EndSession(session_id) |
| 74 | +- GetSessionStats(session_id) -> metrics |
| 75 | + |
| 76 | +5.2 Session lifecycle |
| 77 | +- Session creation: controller allocates slices, populates placement plan, preloads prioritized slices on workers, returns session token. |
| 78 | +- Execution path: client -> session manager -> controller splits request across slices -> workers execute in pipeline -> session manager aggregates outputs. |
| 79 | +- Adaptive batching: session manager groups small inferences into micro-batches per slice based on configured latency budgets. |
| 80 | + |
| 81 | +5.3 QoS and isolation |
| 82 | +- Per-session resource caps (max concurrency, token rate). |
| 83 | +- Tenant isolation: per-tenant slice caching and optional model duplication flags. |
| 84 | +- Fair queuing or priority queues for low-latency sessions. |
| 85 | + |
| 86 | +6. Telemetry & metrics |
| 87 | +- Per-slice metrics: exec latency, memory usage, throughput, error rate. |
| 88 | +- Per-worker metrics: GPU util, free memory, network RTT, connection counts. |
| 89 | +- Per-session metrics: p50/p95/p99 latencies, batch sizes, tokens/sec. |
| 90 | +- Emit via Prometheus metrics endpoint and structured traces (OpenTelemetry) for tracing across slices. |
| 91 | + |
| 92 | +7. Failure modes and fallbacks |
| 93 | +- Worker failure: controller reroutes to alternate worker or triggers local fallback (single-node execution). Evict/restore policy for preloaded slices. |
| 94 | +- Network partition: fall back to local execution when possible; if offload required, return graceful degradation messages to client. |
| 95 | +- Mismatched versions: use manifest version checks to prevent executing incompatible slices. |
| 96 | + |
| 97 | +8. Interfaces & data formats |
| 98 | +- Model ingestion: accept ONNX and TorchScript (MVP) with translator that enumerates layer boundaries. |
| 99 | +- Slice artifact: gzipped protobuf or tar with manifest.json and weights.bin. |
| 100 | +- RPC: gRPC over QUIC (preferred) or HTTP/2 with AEAD wrapper. |
| 101 | + |
| 102 | +9. Testing & benchmarks |
| 103 | +- Unit tests: correctness of slice outputs vs baseline single-node for a suite of models. |
| 104 | +- Integration tests: end-to-end run across two devices (GPU + CPU) validating activations and outputs. |
| 105 | +- Load tests: simulate 1k concurrent sessions with synthetic clients, measure p95 latency and throughput. |
| 106 | +- Security tests: verify PQC handshake, replay protection, and attestation flows. |
| 107 | + |
| 108 | +10. MVP milestones and deliverables |
| 109 | +- Week 0–1: architecture doc, slice format, and prototype plan. (this doc) |
| 110 | +- Week 1–2: implement controller + worker minimal runtime and static partitioner that accepts a small transformer and emits slices. |
| 111 | +- Week 2–3: add PQC handshake, encrypted slice transport, and pre-provisioning flow. |
| 112 | +- Week 3–4: session manager with adaptive batching and basic QoS; run 1k simulated sessions. |
| 113 | +- Week 4–5: integration tests, telemetry dashboard, readme hero docs, and release prep. |
| 114 | + |
| 115 | +11. Open questions |
| 116 | +- Target PQC primitives (Kyber, CRYSTALS-Kyber; choose current NIST-recommended variant). Decide whether to include hybrid classical+PQC key exchange. |
| 117 | +- Attestation strategy for diverse edge hardware — what minimal attestation APIs should we support for MVP? |
| 118 | +- Benchmark targets: supply representative hardware profiles to set realistic throughput/latency goals. |
| 119 | + |
| 120 | +Appendix: quick dataflow |
| 121 | +1. `StartSession` -> controller computes split plan -> preloads slices to assigned workers (encrypted transfer). |
| 122 | +2. Client sends `Infer` -> session manager pipelines activations across workers over secure channels. |
| 123 | +3. Workers return outputs and metrics -> session manager aggregates and returns response. |
| 124 | + |
| 125 | +Next steps: implement the static partitioner and minimal worker runtime (Week 1 task). |
0 commit comments