feat: add real PyTorch model backend
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
"userStories": [
|
||||
{
|
||||
"id": "US-001",
|
||||
"title": "01 \u2014 Monorepo scaffold + single-node smoke test",
|
||||
"description": "Stand up the monorepo package layout and prove that a client HTTP request can travel end-to-end through the stack \u2014 gateway \u2192 one node serving all layers \u2192 valid response \u2014 before any real model or distributed logic is wired in. The six top-level packages should exist with minimal stubs: - `packages/node` \u2014 node client CLI (`meshnet-node`) - `packages/gateway` \u2014 HTTP gateway + route orchestration - `packages/tracker` \u2014 node registry and route selection - `packages/sdk` \u2014 `meshnet` Python SDK - `packages/contracts` \u2014 Solana smart contract wrappers - `packages/p2p` \u2014 gossip and shard swarm The smoke test uses a tiny in-process stub model (not a real LLM) so the test is fast and has no external dependencies. The node runs in the same process as the test. The gateway is a real HTTP server. The client sends a real `POST /v1/chat/completions` request and receives a valid OpenAI-format response.",
|
||||
"title": "01 — Monorepo scaffold + single-node smoke test",
|
||||
"description": "Stand up the monorepo package layout and prove that a client HTTP request can travel end-to-end through the stack — gateway → one node serving all layers → valid response — before any real model or distributed logic is wired in. The six top-level packages should exist with minimal stubs: - `packages/node` — node client CLI (`meshnet-node`) - `packages/gateway` — HTTP gateway + route orchestration - `packages/tracker` — node registry and route selection - `packages/sdk` — `meshnet` Python SDK - `packages/contracts` — Solana smart contract wrappers - `packages/p2p` — gossip and shard swarm The smoke test uses a tiny in-process stub model (not a real LLM) so the test is fast and has no external dependencies. The node runs in the same process as the test. The gateway is a real HTTP server. The client sends a real `POST /v1/chat/completions` request and receives a valid OpenAI-format response.",
|
||||
"acceptanceCriteria": [
|
||||
"`pip install -e packages/node packages/gateway packages/tracker` works from repo root",
|
||||
"`meshnet-node`, `meshnet-gateway`, and `meshnet-tracker` CLI entry points exist",
|
||||
@@ -27,14 +27,14 @@
|
||||
},
|
||||
{
|
||||
"id": "US-002",
|
||||
"title": "02 \u2014 Two-node shard pipeline",
|
||||
"description": "Extend the single-node smoke test so that inference is routed through exactly two nodes, each serving half of a stub model's layers. Activation tensors must travel from the gateway to node A, then from node A to node B, and the final output returns to the gateway. This proves the distributed shard pipeline works end-to-end before real models or a real tracker are introduced. The two nodes run in the same process as the test (no real network required). The gateway hardcodes the two-node route for now \u2014 dynamic route selection comes in issue 03. The activation tensor protocol (shape, dtype, serialisation format) must be established here, as all later issues depend on it. Use the domain vocabulary from `CONTEXT.md`: the ordered list of nodes is an **inference route**; each node's layer range is a **shard**; the tensors passed between nodes are activations (not \"data\" or \"chunks\").",
|
||||
"title": "02 — Two-node shard pipeline",
|
||||
"description": "Extend the single-node smoke test so that inference is routed through exactly two nodes, each serving half of a stub model's layers. Activation tensors must travel from the gateway to node A, then from node A to node B, and the final output returns to the gateway. This proves the distributed shard pipeline works end-to-end before real models or a real tracker are introduced. The two nodes run in the same process as the test (no real network required). The gateway hardcodes the two-node route for now — dynamic route selection comes in issue 03. The activation tensor protocol (shape, dtype, serialisation format) must be established here, as all later issues depend on it. Use the domain vocabulary from `CONTEXT.md`: the ordered list of nodes is an **inference route**; each node's layer range is a **shard**; the tensors passed between nodes are activations (not \"data\" or \"chunks\").",
|
||||
"acceptanceCriteria": [
|
||||
"The integration test spins up two stub nodes, each configured with a non-overlapping shard range",
|
||||
"A `POST /v1/chat/completions` request results in activation tensors flowing node-A \u2192 node-B (verifiable via test assertions or logs)",
|
||||
"A `POST /v1/chat/completions` request results in activation tensors flowing node-A → node-B (verifiable via test assertions or logs)",
|
||||
"The gateway assembles the final response correctly from node-B's output",
|
||||
"The test passes with no external services running",
|
||||
"The activation tensor serialisation format is documented in a short inline comment (shape, dtype, wire format) \u2014 this becomes the contract all future nodes implement",
|
||||
"The activation tensor serialisation format is documented in a short inline comment (shape, dtype, wire format) — this becomes the contract all future nodes implement",
|
||||
"Follow TDD where code is added: add/adjust an observable behavior test before implementation when practical",
|
||||
"Run the task-specific tests and ensure they pass",
|
||||
"Run `python -m pytest` from repo root and ensure it passes, or document why no test suite exists yet",
|
||||
@@ -51,8 +51,8 @@
|
||||
},
|
||||
{
|
||||
"id": "US-003",
|
||||
"title": "03 \u2014 Tracker: node registration + route selection",
|
||||
"description": "Replace the hardcoded two-node route from issue 02 with a real tracker. Nodes register themselves with the tracker on startup (endpoint, shard range, hardware profile, node score). The gateway queries the tracker for an inference route for a given model preset instead of using a static list. The tracker returns an ordered list of node endpoints whose shards collectively cover all layers. The tracker runs as a lightweight HTTP service. Node score is initially a simple placeholder (e.g. fixed value or random) \u2014 real throughput/latency scoring comes later. The tracker must correctly reject route requests when no registered nodes cover a required shard range and return an appropriate error. This issue establishes the tracker's registration and routing API contract, which issues 04 (node startup) and 05 (OpenAI gateway) both depend on.",
|
||||
"title": "03 — Tracker: node registration + route selection",
|
||||
"description": "Replace the hardcoded two-node route from issue 02 with a real tracker. Nodes register themselves with the tracker on startup (endpoint, shard range, hardware profile, node score). The gateway queries the tracker for an inference route for a given model preset instead of using a static list. The tracker returns an ordered list of node endpoints whose shards collectively cover all layers. The tracker runs as a lightweight HTTP service. Node score is initially a simple placeholder (e.g. fixed value or random) — real throughput/latency scoring comes later. The tracker must correctly reject route requests when no registered nodes cover a required shard range and return an appropriate error. This issue establishes the tracker's registration and routing API contract, which issues 04 (node startup) and 05 (OpenAI gateway) both depend on.",
|
||||
"acceptanceCriteria": [
|
||||
"A node can register with the tracker via HTTP, providing its endpoint, shard range, and a hardware profile",
|
||||
"The gateway queries the tracker with a model preset name and receives an ordered list of node endpoints forming a complete inference route",
|
||||
@@ -76,8 +76,8 @@
|
||||
},
|
||||
{
|
||||
"id": "US-004",
|
||||
"title": "04 \u2014 Node client startup flow (`meshnet-node start`)",
|
||||
"description": "Make `meshnet-node start` self-configuring from scratch on a machine with a CUDA-capable GPU (or CPU fallback). The full startup sequence must complete without any manual configuration: 1. Detect GPU model and available VRAM 2. Load an existing Solana wallet from disk, or generate and save a new one 3. Query the tracker for the optimal shard assignment given the hardware profile 4. Download the assigned shard from HuggingFace (`huggingface_hub`) 5. Register with the tracker (wallet address, endpoint, shard range, hardware profile) 6. Begin accepting inference connections The node prints a short status summary on startup: wallet address, assigned shard, model preset, and download progress. No interactive prompts \u2014 the entire flow is non-interactive. This is the primary viral growth vector. Every second of friction in this flow costs node operators. The startup sequence must work on Linux with CUDA, and degrade gracefully to CPU on machines without a GPU.",
|
||||
"title": "04 — Node client startup flow (`meshnet-node start`)",
|
||||
"description": "Make `meshnet-node start` self-configuring from scratch on a machine with a CUDA-capable GPU (or CPU fallback). The full startup sequence must complete without any manual configuration: 1. Detect GPU model and available VRAM 2. Load an existing Solana wallet from disk, or generate and save a new one 3. Query the tracker for the optimal shard assignment given the hardware profile 4. Download the assigned shard from HuggingFace (`huggingface_hub`) 5. Register with the tracker (wallet address, endpoint, shard range, hardware profile) 6. Begin accepting inference connections The node prints a short status summary on startup: wallet address, assigned shard, model preset, and download progress. No interactive prompts — the entire flow is non-interactive. This is the primary viral growth vector. Every second of friction in this flow costs node operators. The startup sequence must work on Linux with CUDA, and degrade gracefully to CPU on machines without a GPU.",
|
||||
"acceptanceCriteria": [
|
||||
"`meshnet-node start --tracker http://localhost:8080` completes startup without prompts on a machine with a CUDA GPU",
|
||||
"A Solana wallet keypair is generated and saved to `~/.config/meshnet/wallet.json` if none exists",
|
||||
@@ -102,8 +102,8 @@
|
||||
},
|
||||
{
|
||||
"id": "US-005",
|
||||
"title": "05 \u2014 OpenAI-compatible gateway",
|
||||
"description": "Expose a production-shape HTTP API from the gateway so that any client using the OpenAI Python SDK (or any OpenAI-compatible tool) works by changing only the `base_url`. The gateway translates OpenAI-format requests into inference route execution and streams responses back in OpenAI-format. Endpoints to implement: - `POST /v1/chat/completions` \u2014 streaming (`text/event-stream`) and non-streaming - `GET /v1/models` \u2014 returns the list of model presets currently routable on the network - `GET /v1/health` \u2014 liveness check The gateway selects an inference route from the tracker, executes the shard pipeline, and assembles the streamed response. If the tracker returns no route for the requested model, the gateway responds with a standard OpenAI-format error (`model_not_available`). Authentication (API key \u2192 SOL/USDC balance) is a stub in this issue \u2014 return 200 for any non-empty `Authorization` header. Real payment gating comes in issue 06.",
|
||||
"title": "05 — OpenAI-compatible gateway",
|
||||
"description": "Expose a production-shape HTTP API from the gateway so that any client using the OpenAI Python SDK (or any OpenAI-compatible tool) works by changing only the `base_url`. The gateway translates OpenAI-format requests into inference route execution and streams responses back in OpenAI-format. Endpoints to implement: - `POST /v1/chat/completions` — streaming (`text/event-stream`) and non-streaming - `GET /v1/models` — returns the list of model presets currently routable on the network - `GET /v1/health` — liveness check The gateway selects an inference route from the tracker, executes the shard pipeline, and assembles the streamed response. If the tracker returns no route for the requested model, the gateway responds with a standard OpenAI-format error (`model_not_available`). Authentication (API key → SOL/USDC balance) is a stub in this issue — return 200 for any non-empty `Authorization` header. Real payment gating comes in issue 06.",
|
||||
"acceptanceCriteria": [
|
||||
"`openai.OpenAI(base_url=\"http://localhost:8080/v1\", api_key=\"test\").chat.completions.create(model=\"stub-model\", messages=[...])` returns a valid response",
|
||||
"Streaming works: `stream=True` returns `text/event-stream` chunks in OpenAI SSE format",
|
||||
@@ -127,8 +127,8 @@
|
||||
},
|
||||
{
|
||||
"id": "US-006",
|
||||
"title": "06 \u2014 Solana stake + settlement contracts",
|
||||
"description": "Deploy and integrate the Solana smart contracts that make node staking, client payment, and token reward settlement trustless. All development and testing targets **Solana testnet** \u2014 never devnet or mainnet during development, to avoid real costs.",
|
||||
"title": "06 — Solana stake + settlement contracts",
|
||||
"description": "Deploy and integrate the Solana smart contracts that make node staking, client payment, and token reward settlement trustless. All development and testing targets **Solana testnet** — never devnet or mainnet during development, to avoid real costs.",
|
||||
"acceptanceCriteria": [
|
||||
"All contracts deploy successfully to Solana testnet",
|
||||
"A node can submit a stake transaction and have its balance reflected in the registry contract",
|
||||
@@ -136,7 +136,7 @@
|
||||
"After a completed inference session, compute attribution is recorded on-chain with correct node/layer attribution",
|
||||
"The epoch settlement transaction correctly distributes token rewards to node operators and deducts client balances",
|
||||
"The gateway refuses to route to a node whose stake balance is below the minimum threshold",
|
||||
"All contract interactions in tests run against a local Solana test validator (via `solana-test-validator`) \u2014 no live testnet required for CI",
|
||||
"All contract interactions in tests run against a local Solana test validator (via `solana-test-validator`) — no live testnet required for CI",
|
||||
"A `.env.testnet` config points to Solana testnet RPC for manual end-to-end testing",
|
||||
"python -m pytest passes from repo root",
|
||||
"Commit only this story's changes"
|
||||
@@ -151,7 +151,7 @@
|
||||
},
|
||||
{
|
||||
"id": "US-007",
|
||||
"title": "07 \u2014 Fraud detection: validator + on-chain slash",
|
||||
"title": "07 — Fraud detection: validator + on-chain slash",
|
||||
"description": "Implement the optimistic fraud detection loop. After each inference request completes, the validator process independently decides whether to re-run the request on a reference node (~5% sample rate).",
|
||||
"acceptanceCriteria": [
|
||||
"The validator process samples ~5% of completed inference requests (configurable)",
|
||||
@@ -175,7 +175,7 @@
|
||||
},
|
||||
{
|
||||
"id": "US-008",
|
||||
"title": "08 \u2014 Node probationary period + ban enforcement",
|
||||
"title": "08 — Node probationary period + ban enforcement",
|
||||
"description": "Implement the two anti-sybil mechanisms that make re-entering the network after a ban economically costly.",
|
||||
"acceptanceCriteria": [
|
||||
"A node with a new wallet receives no token rewards for its first N jobs (verified via settlement contract state)",
|
||||
@@ -184,7 +184,7 @@
|
||||
"A wallet with strike count at the threshold is marked banned in the registry contract",
|
||||
"The tracker excludes banned wallets from route selection",
|
||||
"A banned wallet that attempts to register with the tracker is rejected",
|
||||
"An integration test covers: new wallet \u2192 N jobs \u2192 earning begins; and: strike threshold reached \u2192 banned \u2192 excluded from routes",
|
||||
"An integration test covers: new wallet → N jobs → earning begins; and: strike threshold reached → banned → excluded from routes",
|
||||
"python -m pytest passes from repo root",
|
||||
"Commit only this story's changes"
|
||||
],
|
||||
@@ -198,7 +198,7 @@
|
||||
},
|
||||
{
|
||||
"id": "US-009",
|
||||
"title": "09 \u2014 P2P shard swarm",
|
||||
"title": "09 — P2P shard swarm",
|
||||
"description": "Once a node has downloaded a shard, it seeds that shard to other nodes that are assigned the same shard.",
|
||||
"acceptanceCriteria": [
|
||||
"A node that has downloaded a shard is listed as a peer for that shard in the tracker",
|
||||
@@ -220,7 +220,7 @@
|
||||
},
|
||||
{
|
||||
"id": "US-010",
|
||||
"title": "10 \u2014 `meshnet` Python SDK",
|
||||
"title": "10 — `meshnet` Python SDK",
|
||||
"description": "A Python SDK (`packages/sdk`) that wraps the OpenAI-compatible gateway and exposes network-specific controls.",
|
||||
"acceptanceCriteria": [
|
||||
"`pip install meshnet` installs the SDK",
|
||||
@@ -246,7 +246,7 @@
|
||||
},
|
||||
{
|
||||
"id": "US-011",
|
||||
"title": "11 \u2014 Binary activation wire format",
|
||||
"title": "11 — Binary activation wire format",
|
||||
"description": "Replace the base64 JSON activation payload with raw binary HTTP bodies, zstd compression, and chunked prefill (128 tokens/chunk). All nodes and the gateway must be migrated. Stub nodes continue to emit zeroed tensors, just in binary. This is a protocol prerequisite for US-012 (real model backend).",
|
||||
"acceptanceCriteria": [
|
||||
"Node /forward endpoint reads shape/dtype/session/chunk from HTTP headers; body is raw binary (optionally zstd-compressed)",
|
||||
@@ -268,7 +268,7 @@
|
||||
},
|
||||
{
|
||||
"id": "US-012",
|
||||
"title": "12 \u2014 Real PyTorch model backend",
|
||||
"title": "12 — Real PyTorch model backend",
|
||||
"description": "Replace stub node inference with actual transformers layer execution. Node loads HuggingFace SafeTensors model shard (model.model.layers[start:end]), runs real forward passes in bfloat16, handles head (embed_tokens) and tail (lm_head) responsibilities, and supports bitsandbytes NF4/INT8/bfloat16 quantization via --quantization flag. Test model: openai-community/gpt2.",
|
||||
"acceptanceCriteria": [
|
||||
"meshnet-node start --model-id openai-community/gpt2 --shard-start 0 --shard-end 6 loads the shard without error",
|
||||
@@ -283,15 +283,16 @@
|
||||
"Commit only this story's changes"
|
||||
],
|
||||
"priority": 12,
|
||||
"passes": false,
|
||||
"passes": true,
|
||||
"notes": "Source issue: .scratch/distributed-inference-network/issues/12-real-pytorch-model-backend.md",
|
||||
"dependsOn": [
|
||||
"US-011"
|
||||
]
|
||||
],
|
||||
"completionNotes": "Completed by agent"
|
||||
},
|
||||
{
|
||||
"id": "US-013",
|
||||
"title": "13 \u2014 Coverage-first tracker shard assignment",
|
||||
"title": "13 — Coverage-first tracker shard assignment",
|
||||
"description": "Upgrade tracker route selection to coverage-first, speed-weighted bin-packing. Tracker maintains a live coverage map per model, issues LOAD_SHARD/DROP_SHARD rebalance directives when coverage drops, and assigns shard ranges using declared VRAM, quantization, and benchmark throughput. A model is only routable when all layer ranges have node_count >= 1.",
|
||||
"acceptanceCriteria": [
|
||||
"Node registration accepts vram_bytes, ram_bytes, quantizations[], benchmark_tokens_per_sec",
|
||||
@@ -302,7 +303,7 @@
|
||||
"Shard assignment respects VRAM: assigned_layers <= floor((vram_bytes * 0.8) / bytes_per_layer_at_quant)",
|
||||
"Faster node receives wider shard range when both can cover the same gap",
|
||||
"Integration test: three nodes with different VRAM show widest range on largest-VRAM node with 100% coverage",
|
||||
"Integration test: kill middle-range node \u2192 tracker issues LOAD_SHARD \u2192 coverage recovers",
|
||||
"Integration test: kill middle-range node → tracker issues LOAD_SHARD → coverage recovers",
|
||||
"python -m pytest passes from repo root",
|
||||
"Commit only this story's changes"
|
||||
],
|
||||
@@ -316,11 +317,11 @@
|
||||
},
|
||||
{
|
||||
"id": "US-014",
|
||||
"title": "14 \u2014 Tracker-as-first-layer-node (inference entry point)",
|
||||
"title": "14 — Tracker-as-first-layer-node (inference entry point)",
|
||||
"description": "Merge inference orchestration into tracker nodes that serve the first-layer shard. A tracker node exposes /v1/chat/completions directly: tokenizes input, runs embed_tokens + layers[0..k], selects onward route from coverage map, forwards binary activations, receives tail output, and streams tokens back. The standalone gateway becomes a thin load-balancer routing to tracker nodes.",
|
||||
"acceptanceCriteria": [
|
||||
"Node with shard_start==0 (or --tracker-mode flag) exposes /v1/chat/completions alongside /forward",
|
||||
"Tracker-node /v1/chat/completions: tokenize \u2192 embed \u2192 own layers \u2192 route selection \u2192 forward binary \u2192 receive tail \u2192 stream SSE",
|
||||
"Tracker-node /v1/chat/completions: tokenize → embed → own layers → route selection → forward binary → receive tail → stream SSE",
|
||||
"Two tracker nodes for same model each handle requests independently",
|
||||
"Gateway proxies /v1/chat/completions to tracker nodes (round-robin), discovered via GET /v1/tracker-nodes/<model_preset>",
|
||||
"Integration test: two tracker nodes + two mid-shard nodes for GPT-2; 10 requests via gateway; both tracker nodes receive load; all responses valid",
|
||||
@@ -338,6 +339,6 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"updatedAt": "2026-06-29T00:00:00.000Z"
|
||||
"updatedAt": "2026-06-29T12:43:53.339Z"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user