interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / docs / campaigns / c1 / SPEC.md

374 lines · 23416 bytes Raw Blame History Rendered
1# Campaign C1: Branch-Native Inference Correctness
2
3```text
4campaign_id = "c1"
5spec_version = 1
6status = DRAFT (frozen on merge of feat/c1-campaign-spec)
7```
8
9## 0. Question
10
11> Does the native Agent State / scheduler / KV / transformer / GB10 architecture preserve correct inference under branching, scale, and resource pressure?
12
13C1 answers that question and nothing else. It is a correctness campaign. Performance, placement optimization, AEGIS, Cortex, MCP, tool effects, multi-model support, INT4/INT8, and distributed inference are out of scope (Section 11).
14
15Path under test:
16
17```text
18request -> aien-runtime -> aien-scheduler -> SequenceArena -> aien-kv-cache (physical KV/COW)
19 -> native transformer -> aien-inference-abi (BlackwellGb10Backend + ReferenceCpuBackend)
20 -> generated tokens
21```
22
23## 1. Evidence Model
24
25Three roles produce three levels of evidence. They are never merged.
26
27| Role | Does | Must not |
28| ---- | ---- | -------- |
29| Builder / operator | Builds the environment, runs the official harness scripts, fixes infrastructure failures | Decide PASS/FAIL, edit bundles |
30| Verifier | Runs `aien-campaign-verifier` over a frozen bundle against this spec | Modify code under test, interpret results outside the acceptance files |
31| Independent reproducer | Clones the pinned commit on another GB10 and reruns from published instructions | Receive help beyond the published instructions |
32
33Evidence levels: "passed on my machine" (builder), "artifacts satisfy the predefined acceptance criteria" (verifier), "someone else reproduced it" (reproducer). C1 targets the second level. The third is a follow-on.
34
35### 1.1 Freezing rules
36
371. This spec, `acceptance.toml`, `placement.toml`, `kv_contract.toml`, and the verifier are merged to `main` before the harness emits its first evidence bundle.
382. Any later change is a dated amendment in Section 14 that bumps `spec_version`, states its reason, and names exactly which gates and claims it supersedes. Results whose acceptance meaning did not change stay valid. Prose-only fixes supersede nothing.
393. Tolerances are set from the measured noise floor (Section 5.3) and committed before any COW equivalence run they govern.
40
41### 1.2 Pass rules
42
431. Correctness invariants are binary. Every required trial passes, or the stage fails.
442. A failing seed or script becomes a permanent regression case.
453. A gate result is bound to one `main` commit SHA. Any change to code in the transitive path under test reruns every earlier gate. Documentation-only changes do not.
464. The campaign stops at the first failed gate. Later gates do not run against a commit that failed an earlier gate.
475. Passing gates may receive annotated tags `c1/gate<N>/pass/<short-sha>` whose annotation carries the bundle manifest digest. Tags are a convenience. The evidence identity is `code commit + bundle digest + spec digest + verifier digest`.
48
49## 2. Identity Model
50
51Losing KV costs computation, not identity.
52
53```text
54LogicalBranchId durable semantic identity, constant for the life of a branch
55 |-- TokenHistory authoritative token sequence
56 |-- fork lineage parent LogicalBranchId, fork_position, fork_ordinal, PrefixSnapshotId
57 |-- sampler coordinates (LogicalBranchId; generation_step, sample_stream, draw_index)
58 `-- durable journal StepCommit / ForkCommit / cancel / eviction records
59
60ExecutionLineage a frozen software and model configuration
61 `-- ExecutionFingerprint
62
63SequenceId one runtime incarnation of a branch
64 `-- { boot_epoch: u64, slot: u32, generation: u32 } (opaque, 128 bits, no truncating conversion)
65
66Physical KV reconstructible execution state beneath all of the above
67```
68
69### 2.1 SequenceId
70
71- Opaque. Equality compares all three fields. `to_u64()` and every other truncating conversion is removed.
72- Every serialized reference (scheduler events, lineage, KV logs, receipts) carries the full 128-bit value.
73- A branch may hold many `SequenceId`s over its life (preemption, restart). Each binding `SequenceId -> LogicalBranchId` is journaled per epoch.
74
75### 2.2 LogicalBranchId
76
77- 256-bit digest of `(run identity, parent LogicalBranchId, fork_position, fork_ordinal)`. Root branches derive from the run seed.
78- Keys the sampler, `TokenHistory`, lineage, `PrefixSnapshot` leases, and every verifier identity check.
79
80### 2.3 TokenHistory
81
82Owned per branch: original input tokens, inherited prefix boundary, branch-specific input, every accepted generated token. A token is appended before it counts as committed. `rec.prompt` is not recovery state.
83
84### 2.4 PrefixSnapshot
85
86```text
87PrefixSnapshot { snapshot_id, fork_position, block_ids[], partial_block_valid_tokens, digest }
88```
89
90Records the physical block IDs at fork time. It is never resolved later through a parent's mutable block table.
91
92### 2.5 BranchCheckpoint
93
94```text
95BranchCheckpoint { logical_branch_id, parent_id, fork_position, prefix_snapshot_id,
96 prefix_lease: Held | Evicted, token_history_digest, recovery }
97```
98
99Preemption drops the private suffix and keeps the prefix lease. Readmission reuses the exact leased prefix and recomputes only the divergent suffix. If the lease was evicted, recovery is a full `TokenHistory` recompute.
100
101Lease eviction is atomic: mark every affected suspended lease invalid, journal the eviction, release those suspended references, decrement physical refcounts, free only blocks that reach zero. Active references are never removed by a snapshot eviction. The scheduler reclaims private suffixes before suspended-only prefixes.
102
103### 2.6 ExecutionFingerprint
104
105Runtime binary sha256, runtime and scheduler schema versions, GPU kernel and library sha256, model manifest sha256, tokenizer sha256, `placement.toml` sha256, `kv_contract.toml` sha256, sampler algorithm and version, campaign spec version, relevant ABI versions.
106
107## 3. Invariants
108
109Every stage of every gate checks all applicable invariants. Only performance thresholds vary by stage.
110
111| # | Invariant | Definition |
112| - | --------- | ---------- |
113| I1 | Identity | Parent/child lineage, `LogicalBranchId`, and `SequenceId` bindings survive every transition. No duplicate live `SequenceId`. No child references a nonexistent fork base. |
114| I2 | Isolation | One branch's writes cannot change another branch's state. KV bytes outside legitimately COW-mutated pages are byte-for-byte identical. No write event ever targets a block with refcount > 1 or a leased snapshot block; any writer COWs first. |
115| I3 | Equivalence | COW execution matches independent recomputation from `TokenHistory` within the frozen tolerance, at every generated step (teacher forced). |
116| I4 | Conservation | Shared/private accounting equals actual allocations (Section 7). |
117| I5 | Reclamation | Destroying or cancelling a branch returns every block it solely owned. Release is idempotent: repeated or racing release never double-decrements. |
118| I6 | Parent survival | Parent inference is identical before and after child creation and destruction, except where the parent itself advances. |
119| I7 | State continuity | Preemption, suspension, readmission, cancellation, and restart do not alter the logical or numerical identity of a surviving branch. |
120
121### 3.1 Required branch behaviors
122
123- At fork, children reference the parent's physical pages. No private copies exist until a write.
124- After branch A diverges, only the affected pages become private to A. B, C, and P keep their original bytes.
125- KV contents are checked, not only metadata: selected layers, tokens, heads, and K/V planes are hashed before fork, after fork, after divergence, and after child destruction.
126- Forking into an existing sequence ID returns an error and leaves every refcount, free-list entry, block table, and existing child state byte-for-byte unchanged.
127- Releasing an already released sequence returns an error without mutating allocator state.
128- Fork positions tested (Gates 1, 2, 4): `1`, `bs - 1`, `bs`, `bs + 1`, `k*bs - 1`, `k*bs`, `k*bs + 1`, with `k` per profile in `acceptance.toml`. Every unaligned fork runs parent-writes-first, child-writes-first, parent-then-child, and child-then-parent.
129
130## 4. Gates
131
132| Gate | Purpose | Model | Preemption |
133| ---- | ------- | ----- | ---------- |
134| 0 | Measurement qualification: prove the measurement chain detects bad paths | mocks + TinyLlama | n/a |
135| 1 | Structural correctness on real runtime components; capture known KV bugs failing, fix, rerun | TinyLlama architecture | off |
136| 1.5 | Qwen qualification: checkpoint identity, 48-layer load, single-sequence reference parity | Qwen3-Coder-30B-A3B-Instruct-FP8 | off |
137| 2 | Qwen branch equivalence at low scale (2, 8, 32 branches) | Qwen | off |
138| 3 | Scale: 100 and 500 branches, fixed 40 GiB BF16 pool, max 512 private tokens per branch, idle teardown | Qwen | off (watermark 0) |
139| 4 | Resilience: oversubscription, preemption, active cancellation, crash and restart, deterministic fault points | Qwen | on |
140| 5 | Performance and placement changes. Separate campaign. | | |
141| 6 | Whole-stack chaos and soak with AEGIS, Cortex, external capabilities. Separate campaign. | | |
142
143Stage parameters (branch counts, context lengths, trial counts, fork positions) live in `acceptance.toml`.
144
145### 4.1 Gate 0: measurement qualification
146
147Test the tester. Each case has an expected verdict, and the failing cases stay in the evidence package.
148
149| Case | Expected |
150| ---- | -------- |
151| Op required on GB10 runs on CPU | FAIL |
152| Op permitted on CPU runs on CPU | PASS |
153| Backend reports GPU, witness saw no kernel | FAIL |
154| Witness saw a GPU kernel, backend reports CPU | FAIL |
155| Kernel symbol outside the op's allowlist | FAIL |
156| GPU call fails and falls back where fallback is prohibited | FAIL |
157| Bundle file altered after `sha256sums.txt` was written | FAIL |
158| Binary altered after hashing (fingerprint mismatch) | FAIL |
159| Missing device at startup with `AIEN_REQUIRE_BLACKWELL=1` | abort |
160| KV pool dtype differs from `kv_contract.toml` | abort |
161| Event journal omits a release that the raw census reflects | FAIL |
162| Mock backend that reports GPU while running the CPU reference | FAIL |
163
164### 4.2 Gate 1: TinyLlama structural correctness
165
166Order is mandatory:
167
1681. Write the tests that trigger the known defects: duplicate child ID in `fork_sequence` (table overwrite, leaked refcounts) and `free_sequence` underflow (double free).
1692. Run them. Archive the failing bundle.
1703. Land the fix commit.
1714. Rerun. Archive the passing bundle.
172
173Evidence chain: `before-fix failing bundle -> fix commit -> after-fix passing bundle`.
174
175Gate 1 also runs the adversarial script: fork 100 branches, mutate branch 73, destroy 20 arbitrary siblings, advance the parent, mutate branch 4, destroy branch 73, then verify every survivor against independent recompute. Scripts run in deterministic mode (Section 8).
176
177### 4.3 Gate 1.5: Qwen qualification
178
179Hard boundary, in order:
180
181```text
182checkpoint present
183-> every shard, index, config, tokenizer file hashed individually
184-> manifest digest over those hashes recorded
185-> architecture and config parsed
186-> all 48 layers loaded through the runtime (not the single-layer loader)
187-> single-sequence parity with the frozen Hugging Face reference harness passes
188-> only then Qwen enters Gate 2
189```
190
191Qwen enters `main` through ordinary reviewed and preflighted `feat/` PRs, not a worktree merge.
192
193### 4.4 Gate 4: resilience scenarios (minimum set)
194
195- Oversubscription: 500 branches x 1,000 private tokens against the 40 GiB pool (about 33,548 blocks required vs 27,306 available).
196- Preempt and readmit with the prefix lease held: only the private suffix is recomputed.
197- Parent terminated -> suspended children remain -> prefix becomes suspended-only -> prefix evicted -> child readmitted -> full `TokenHistory` recompute -> I3 passes.
198- Cancellation during an active write at each named fault point.
199- Release races: cancel twice, completion vs cancel, preemption vs cancel, parent teardown vs child cancel.
200- Kill between step compute and `StepCommit` fsync; kill after fsync before token exposure.
201- Restart with identical `ExecutionFingerprint`: every surviving branch recovers, with identical seeded token IDs.
202- Restart with a deliberately mismatched fingerprint: restore refused.
203
204## 5. Numerical Acceptance
205
206### 5.1 Comparisons
207
208For every compared step and every compared logit vector:
209
210- max absolute error `|a - b|`
211- max relative error `|a - b| / max(|ref|, epsilon)`, epsilon frozen in `acceptance.toml`
212- top-1 agreement
213- KL divergence of the softmax distributions
214
215Top-1 disagreement is permitted only at steps where the reference top-2 margin is below the absolute tolerance. Every such step is listed in the report.
216
217### 5.2 Exact comparisons
218
219- KV bytes not legitimately COW-mutated: zero tolerance, byte equality.
220- Seeded generation in Gate 4 continuity checks: identical token IDs. A token mismatch fails even if logits pass. Logs must show whether the cause was sampler state or a numerical boundary crossing.
221
222### 5.3 Noise floor
223
224Before any COW equivalence run, measure logit differences with no branching for the same sequence: run twice, with different batch neighbors, and prefill vs decode. Tolerance for each metric is `k x measured floor`, with `k` in `acceptance.toml`. The measured values are committed as an amendment before Gate 1 equivalence (TinyLlama) and before Gate 2 (Qwen).
225
226### 5.4 External reference
227
228Gate 1.5 compares AIEN against the Hugging Face reference on the same checkpoint and tokens (single sequence, no branching). I3 compares AIEN against itself and proves COW does not corrupt state. Both are required. Neither substitutes for the other.
229
230## 6. Device Placement
231
232"Zero fallback" is retired as a claim. Placement is enforced per op against `placement.toml`:
233
234```text
235AIEN_ENFORCE_PLACEMENT=docs/campaigns/c1/placement.toml
236```
237
238A call whose observed execution does not match the placement contract aborts the run. `AIEN_REQUIRE_BLACKWELL` keeps its existing meaning: a GB10 device must exist at startup. `fallback_count` is diagnostic telemetry only.
239
240### 6.1 Two witnesses
241
2421. AIEN dispatch record: every op call has an `op_call_id` and records requested and reported path.
2432. External device witness: `aien-campaign-device-witness`, a CUPTI activity library loaded via `CUDA_INJECTION64_PATH`, records actual kernel launches and completions. AIEN brackets each op call with an NVTX range carrying its `op_call_id`. The verifier consumes the witness trace but does not link the witness library.
244
245For an op required on GB10: AIEN reports GPU, the witness saw a kernel matching the op's allowlist inside the op's range, the kernel completed, and no CPU fallback event occurred. For an op permitted on CPU: AIEN reports CPU, `placement.toml` permits CPU, and the witness saw no kernel inside the op's range.
246
247Kernel symbol allowlists are glob patterns bound to the frozen kernel and library digests. cuBLAS kernel names are internal and version-specific, so their patterns are frozen from the Gate 0 qualification trace by amendment.
248
249## 7. KV Contract and Conservation
250
251`KvDType::Bf16` is mandatory. The receipt records `kv_dtype`, element size, block size, bytes per block, total blocks, and configured pool bytes. A mismatch with `kv_contract.toml` aborts the run. This matters because some existing transformer constructors default to an FP32 pool.
252
253The scheduler computes block demand only through a `KvPoolGeometry` value supplied by `aien-kv-cache` (block size, bytes per block, block count, dtype, layers, KV heads, head dim). The hardcoded `16` in the scheduler admission path is removed.
254
255The verifier rebuilds state from three independent sources and requires all three to agree:
256
257```text
2581. mutation journal kv_allocations.jsonl, branch_lineage.jsonl
2592. raw final census kv_census.json (sequence tables, free set, physical refcounts)
2603. reported metrics kv_metrics.json (AIEN's own counters)
261
262replayed == census replayed == reported
263```
264
265Conservation equations:
266
267```text
268allocated + free = pool_total
269refcount(block) = live references + suspended lease references reconstructed from lineage
270no referenced block in free set
271no unreferenced block outside free set
272no duplicate live SequenceId
273no child references a nonexistent fork base
274```
275
276Leak metric hierarchy on GB10 unified memory: primary is allocator block conservation; secondary are process RSS and total unified memory pressure.
277
278## 8. Determinism
279
280- Deterministic mode: the scheduler consumes a seeded event script at step boundaries. Seeds and scripts are recorded in the bundle.
281- Named fault-injection points (`cow_copy_mid`, `fork_mid`, `release_mid`, `step_pre_commit`, `step_post_commit_pre_expose`) fire on the Nth hit. Used from Gate 4.
282- Sampler: counter-based (Philox-style). Key is `LogicalBranchId`. Counter is `(generation_step, sample_stream, draw_index)`. No mutable sampler state survives across steps.
283- Gates 1 to 3 run greedy decoding plus one frozen seeded-sampling configuration.
284- Random chaos belongs to Gate 6 only.
285
286## 9. Durability (Gate 4)
287
288A model step is committed only when its `StepCommit` has been appended to the durable branch journal and synchronously persisted. No token is exposed externally before its commit is durable.
289
290```text
291StepCommit { logical_branch_id, step_number, previous_history_length, input_token,
292 accepted_output_token, token_history_digest, sampler_coordinates,
293 fork_base_id, logits_digest (campaign mode), execution_fingerprint }
294
295ForkCommit { logical_child_id, logical_parent_id, fork_position, prefix_snapshot_id,
296 token_history_digest }
297```
298
299- Journal: append-only, sequence-numbered, checksummed. A torn final record is discarded on replay (it was never exposed).
300- One fsync covering every `StepCommit` of a scheduler step counts as synchronous. Modes that expose tokens before fsync are Gate 5 modes and never inherit the restart claim.
301- A child does not exist externally until its `ForkCommit` is durable. Cancellation and prefix eviction are journaled.
302- Boot epoch is the first record of each boot (`BootCommit`): acquire exclusive startup lock, read prior epoch, increment, append, fsync the journal, fsync its directory when the file was created or renamed, release lock, then accept requests.
303- Processed-operation idempotency is derived from the journal. The separate `/tmp` processed-ops file is retired.
304- After restart every lease is `Evicted` and recovery is full `TokenHistory` recompute.
305- Physical KV is never persisted as the source of truth.
306- Exactly-once external tool effects are out of scope (AEGIS campaign).
307
308### 9.1 Restore vs migrate
309
310Restore requires the persisted `ExecutionFingerprint` to equal the current one. Otherwise restore is refused. Migration (recompute durable history under a new fingerprint, new `ExecutionLineage`, `MigrationReceipt`) is out of scope for C1 except the refusal test.
311
312## 10. Bundle and Receipt
313
314Every run emits an immutable, content-addressed bundle stored outside Git:
315
316```text
317manifest.json campaign_id, spec_commit, acceptance_sha256, placement_sha256,
318 kv_contract_sha256, kv_profile, verifier_commit, verifier_binary_sha256,
319 code_under_test_commit, dirty_tree, model_manifest_sha256,
320 execution_fingerprint, instrumentation_enabled, seeds
321environment.json driver, CUDA, Mojo, Rust toolchain, OS
322hardware.json device name, compute capability, memory
323kv_contract.json observed geometry and dtype
324op_records.jsonl AIEN dispatch record per op_call_id
325witness.jsonl device witness trace (hashed by the witness)
326kv_allocations.jsonl KV mutation journal
327branch_lineage.jsonl fork, teardown, lease, binding events
328kv_census.json raw final allocator state
329kv_metrics.json AIEN-reported counters
330logits_reference/ recompute and HF reference logits
331logits_cow/ COW-path logits
332memory_samples.csv
333latency_samples.csv
334failures.jsonl
335sha256sums.txt over every file above
336```
337
338Only `bundle_sha256`, `manifest_sha256`, and `PASS/FAIL` are committed to the repository.
339
340Instrumentation (KV hashing, witness, per-op records) is controlled by a runtime flag recorded in the manifest. Correctness gates run instrumented. Scale runs are repeated uninstrumented with end-to-end logit comparison. No timing number from an instrumented run supports a performance statement.
341
342## 11. Scope
343
344In scope: the path in Section 0 on one frozen model configuration with BF16 KV.
345
346Cut from C1: Cortex, distillation, Harvester, MCP, tool use and external effects, cockpit UI, AEGIS policy, vLLM or other comparisons, multi-model, INT4/INT8 and exotic quantization, distributed inference, deadline scheduling (deadlines are stored but not enforced by `aien-scheduler`; nothing in C1 tests them).
347
348Parallel track, not C1: the unrestricted `bash -c` path in `aien-cli/src/tools.rs` is a release-blocking security issue handled in the AEGIS security track.
349
350## 12. Build Prerequisites
351
352| Before | Required |
353| ------ | -------- |
354| Gate 0 | Per-op dispatch records; fail-closed placement enforcement; device witness; bundle and receipt schema with `ExecutionFingerprint`; `KvPoolGeometry` and KV contract check; raw state census API; this verifier |
355| Gate 1 | 128-bit `SequenceId`; `LogicalBranchId`; `TokenHistory`; duplicate-fork rejection; idempotent release; deterministic scheduler scripts |
356| Gate 1.5 | 48-layer Qwen runtime integration; checkpoint manifest; Hugging Face reference harness |
357| Gate 3 | Per-branch teardown and cancel API sharing one idempotent release primitive |
358| Gate 4 | `BranchCheckpoint` and `PrefixSnapshot` leases; durable journal with `BootCommit`, `StepCommit`, `ForkCommit`; named fault points; counter-based sampler; fingerprint-checked restore |
359
360## 13. Claims
361
362Frozen wording. Published claims are quoted verbatim with their evidence bundle digest.
363
364- **G0**: "The measurement system detects every seeded violation in the qualification suite."
365- **G1**: "On the TinyLlama architecture, AIEN's KV/COW, SequenceArena, and scheduler satisfy all seven invariants across the defined fork, mutation, preemption-free teardown, and reclamation scripts."
366- **G1.5**: "AIEN loads the frozen Qwen3-Coder-30B-A3B-Instruct-FP8 checkpoint identified by manifest `<sha>` and matches the frozen Hugging Face reference harness within the specified numerical tolerances for the defined single-sequence qualification workload."
367- **G2/G3**: "With the frozen device-placement specification and no disallowed execution paths, COW-branched inference on the frozen Qwen3-Coder checkpoint is numerically equivalent to independent recomputation at the tested branch counts through N branches with a 32K-token parent context."
368- **G4**: "With the frozen device-placement specification and no disallowed execution paths, COW-branched inference remains numerically equivalent to independent recomputation and preserves branch state continuity under the defined oversubscription, preemption, cancellation, and restart fault scenarios."
369
370Wording rules: C1 never claims "production". "Blackwell-native" and "zero fallback" may appear only in a later frozen claim that defines and proves them.
371
372## 14. Amendments
373
374None.