Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,19 @@ jobs:
tests/inference_engine/setup/ \
tests/inference_engine/bridge/ \
tests/inference_engine/distributed/ \
tests/inference_engine/network/ \
tests/sdk/python/ \
tests/training/repr_align/ \
tests/backends/mlx/test_env.py \
--junitxml=junit.xml \
-v
coverage report \
--include='inference_engine/server/auth.py,inference_engine/server/config.py,inference_engine/server/errors.py,inference_engine/server/grpc_app.py,inference_engine/server/metrics.py,inference_engine/server/schemas.py,inference_engine/server/proto_gen/**/*.py,inference_engine/memory/*,inference_engine/bridge/*,inference_engine/distributed/*,inference_engine/scheduler/config.py,inference_engine/scheduler/session.py,inference_engine/pipeline/*,inference_engine/session/store.py,inference_engine/setup/*,sdks/python/kakeya/__init__.py,sdks/python/kakeya/errors.py,training/repr_align/*' \
--include='inference_engine/server/auth.py,inference_engine/server/config.py,inference_engine/server/errors.py,inference_engine/server/grpc_app.py,inference_engine/server/metrics.py,inference_engine/server/schemas.py,inference_engine/server/proto_gen/**/*.py,inference_engine/memory/*,inference_engine/bridge/*,inference_engine/distributed/*,inference_engine/network/*,inference_engine/scheduler/config.py,inference_engine/scheduler/session.py,inference_engine/pipeline/*,inference_engine/session/store.py,inference_engine/setup/*,sdks/python/kakeya/__init__.py,sdks/python/kakeya/errors.py,training/repr_align/*' \
--omit='inference_engine/distributed/prefill_cache_runtime.py' \
--fail-under=100
coverage xml -o coverage.xml \
--include='inference_engine/server/auth.py,inference_engine/server/config.py,inference_engine/server/errors.py,inference_engine/server/grpc_app.py,inference_engine/server/metrics.py,inference_engine/server/schemas.py,inference_engine/server/proto_gen/**/*.py,inference_engine/memory/*,inference_engine/bridge/*,inference_engine/distributed/*,inference_engine/scheduler/config.py,inference_engine/scheduler/session.py,inference_engine/pipeline/*,inference_engine/session/store.py,inference_engine/setup/*,sdks/python/kakeya/__init__.py,sdks/python/kakeya/errors.py,training/repr_align/*'
--include='inference_engine/server/auth.py,inference_engine/server/config.py,inference_engine/server/errors.py,inference_engine/server/grpc_app.py,inference_engine/server/metrics.py,inference_engine/server/schemas.py,inference_engine/server/proto_gen/**/*.py,inference_engine/memory/*,inference_engine/bridge/*,inference_engine/distributed/*,inference_engine/network/*,inference_engine/scheduler/config.py,inference_engine/scheduler/session.py,inference_engine/pipeline/*,inference_engine/session/store.py,inference_engine/setup/*,sdks/python/kakeya/__init__.py,sdks/python/kakeya/errors.py,training/repr_align/*' \
--omit='inference_engine/distributed/prefill_cache_runtime.py'

- name: Upload coverage artifact
if: always()
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ jobs:
# requirements.txt rather than an editable `-e .` (which errors with
# "does not appear to be a Python project").
python3 -m pip install -r requirements.txt
# The integration suite exercises the legacy dllm-hub Qwen proposer,
# whose remote modeling file depends on the Transformers 4.x
# decoder_layer.attention_type API. Keep this runner in the dedicated
# legacy range; K3/Gemma production paths use requirements.txt's
# unbounded Transformers 5.x-compatible environment.
python3 -m pip install 'transformers>=4.45,<5.0'
python3 -m pip install pytest pytest-asyncio pytest-timeout coverage

- name: Run integration suite
Expand Down
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,53 @@ latency drift over a 4-hour, 480-turn Mac M4 run; bounded memory).
> verifier for lightweight serving, or the **restored Gemma-4 26B** path
> (proposer + f_θ/S5) for the memory-bounded, recall-preserving engine below.

## Distributed Prefill KV Cache Network

Kakeya can use trusted peer Mac minis as an **immutable prefill-cache tier**.
Every node advertises model/cache compatibility through the existing P2P
`CapabilityService`; a cold inference node queries local and remote caches in
parallel, imports the longest valid token-prefix snapshot once, computes only
the missing suffix, and keeps autoregressive decode entirely local.

This is not remote attention and not coherent shared RAM:

```text
tokenize + chained prefix hashes
├── local lookup ──────────────┐
└── P2P lookup over gossip ────┤ choose longest compatible prefix
stream one immutable KV snapshot
local suffix prefill → local decode
```

Key properties:

- exact model/tokenizer/quantization/RoPE/cache-format compatibility;
- longest **contiguous** prefix reuse — arbitrary holes are never reused;
- memory-bounded LRU storage with leases and cache epochs;
- point-to-point chunked gRPC publish/fetch with SHA-256 validation;
- failure-safe fallback to local prefill;
- Thunderbolt/LAN/Tailscale endpoint priority;
- node registration, inference groups, token accounting and topology UI.

Live product dashboard: **[https://kakeya.ai](https://kakeya.ai)**.

Two-Mac measured evidence (Gemma 26B MLX 4-bit, 93-token prompt):

```text
cold local prefill 5.926 s
remote Thunderbolt hit 0.061 s
observed speedup ≈97×
```

Architecture and operations:

- [ADR 0016 — Distributed Prefill KV Cache Network](docs/adr/0016-distributed-prefill-kv-cache-network.md)
- [Two-Mac live report](docs/reports/distributed-prefill-kv-mac-thunderbolt.md)
- [Operator runbook](docs/ops/distributed-prefill-kv-network.md)

## Quickstart (5 minutes on Mac M4 / Linux x86)

> **Status — v0.4** (`v0.4-mac` / `v0.4-cuda` tags). Ships from source; PyPI +
Expand Down Expand Up @@ -102,6 +149,7 @@ patterns — see [`docs/quickstart.md`](docs/quickstart.md).
| `AppendTokens` / `Generation` coordinators | Drive prefill / incremental forward / greedy decode; route per-session (multi-tenant) or single. | `inference_engine.session.{coordinator,generator}` |
| Python / TypeScript SDKs | `kakeya.Client` / `Session` (sync gRPC); `@kakeya/runtime` (Node 20+). | [`sdks/`](sdks/) |
| HTTP shim (deprecated) | OpenAI-compatible `/v1/chat/completions`; `Deprecation` + `Sunset` headers. | `inference_engine.server.app` |
| **Distributed Prefill KV Cache** | P2P capability gossip, exact compatibility locks, chained longest-prefix lookup, chunked snapshot publish/fetch, local suffix prefill and local decode. | `inference_engine.distributed.prefill_cache*`, `inference_engine.network` |

## Runtime evidence (foundational, carried into v0.4)

Expand Down Expand Up @@ -703,7 +751,7 @@ scripts/
| v0.5 GA multi-host hardening | queued | mTLS node identity, Bonjour seed discovery, K3 DFlash hidden-state flow over the mlx.distributed ring |
| Async continuous batching | designing | Dynamic mid-flight arrival + ragged-length cohorts under the async gRPC `Generate` handlers (current batcher is fixed-cohort) |
| Deployment polish | queued | PyPI + npm publishing, GHCR Docker image, `kakeya prewarm` CLI, `kakeya chat` REPL |
| Cross-request KV reuse | designing | Sessions survive across requests on gRPC; turns intra-session drift into 0 ms inter-request drift |
| **Distributed Prefill KV reuse** | ✅ live MVP | Cross-node immutable snapshots, chained longest-prefix matching, Thunderbolt gRPC transfer and public fleet dashboard ([ADR 0016](docs/adr/0016-distributed-prefill-kv-cache-network.md)) |

## Continuous integration

Expand Down
2 changes: 2 additions & 0 deletions deploy/cloudflare-worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.wrangler/
62 changes: 62 additions & 0 deletions deploy/cloudflare-worker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# kakeya.ai Cloudflare Worker

`kakeya-inference-network` owns `kakeya.ai/*` and forwards the public product
surface to the direct origin at `agent.kakeya.ai`.

Routing:

- `/` and `/network` → `/network`
- `/v1/network/*` → same API path
- `/healthz` → `/v1/network/summary`
- unknown browser paths → dashboard

## Validate

```bash
npm install
npm audit --omit=dev
npm run check
```

## Deploy

```bash
npx wrangler login
npm run deploy
```

Expected route:

```text
kakeya.ai/* (zone kakeya.ai)
```

## Verify

```bash
curl -fsS https://kakeya.ai/ | grep "Kakeya Inference Network"
curl -fsS https://kakeya.ai/healthz
curl -fsS https://kakeya.ai/v1/network/nodes
```

Responses carry:

```text
X-Kakeya-Surface: inference-network
```

## Rollback

List versions/deployments:

```bash
npx wrangler versions list
npx wrangler deployments list
```

Roll back with Wrangler's version rollback/deployment command, or remove the
`kakeya.ai/*` route. The direct origin remains available at:

```text
https://agent.kakeya.ai/network
```
Loading
Loading