Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/docs/speculation/CONTRACT.md # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / docs / speculation / CONTRACT.md` 192 lines · 11359 bytes Raw Blame History Rendered 1 # Speculation component contract v1 2 3 All quantities are unsigned 64-bit integers. Time is microseconds. Probabilities 4 are unconditional accepted-prefix survival in millionths, monotonically 5 nonincreasing with depth. There is no floating-point input or nonfinite value; 6 out-of-range encodings are rejected. Converting an external clock/probability 7 representation is the caller's responsibility, with its precision disclosed. 8 9 ## Identity and calibration 10 11 `sid[0..31]` contains eight SHA-256 identities, four little-endian words each: 12 weights; tokenizer; numerical/sampling recipe; CUDA++ backend/library build; 13 Omega/AIENOS executable build; drafter; candidate generator; experiment and 14 measurement contract. `sid[32..63]` contains the independently expected values. 15 Each digest must be nonzero. These are equality checks, not a hash implementation 16 or authenticated discovery. The existing owner must provide real identities. 17 18 `sprofile` contains version (1), nonzero epoch, inclusive context lower bound, 19 exclusive context ceiling, evidence class (1 synthetic, 2 declared device), and 20 shape kind (1 chain). The context ceiling is at most 131072. An epoch change 21 invalidates learned state. Tree verification is explicitly unsupported. 22 23 `srows` has seven rows of eleven words. Candidate draft lengths are 24 0, 1, 2, 4, 8, 16, 31. A row contains: 25 26 | Offset | Meaning | 27 | --- | --- | 28 | 0 | Supported: 0 or 1. Unsupported rows have no measured cost claim | 29 | 1 | Draft length | 30 | 2 | Verification rows, including anchor: draft length + 1 | 31 | 3..8 | Draft, verify, commit/rollback, host, policy, preparation microseconds | 32 | 9 | Peak memory bytes required by this shape | 33 | 10 | Calibration sample count, 5 through 1,000,000 | 34 35 Ordinary row zero must be supported with zero draft time. Every enabled row 36 requires positive verify time and memory; individual phase costs are at most 37 1,000,000,000 us. Zero in other phases means measured zero, never unknown. 38 The collector requires an explicit complete phase mask. Total row cost includes 39 all six phases; cross products are bounded below the unsigned 64-bit limit. 40 41 `sprior[31]` is the frozen development estimate. `sbegin(0)` validates and starts 42 a cold request. `sbegin(1)` retains learned costs/survival only for the same 43 identity and epoch, resets request counts and probe scheduling, and requires an 44 already initialized instance. No hidden shared learning is allowed: one instance 45 per caller-controlled session. The warm flag must be recorded in trial data. 46 47 ## Selection and observation 48 49 Set `scontrol[0]` to require declared device evidence (1), or permit synthetic 50 diagnostics (0). `scontrol[1]` is sampling mode; zero means greedy and any other 51 value explicitly selects ordinary decoding. 52 53 `sselect(context, remaining, memory, epoch, mode, fixed)` takes six values. Mode 54 0 is ordinary, 1 is fixed, 2 is adaptive; `fixed` is a draft length. At most 55 256 output tokens are admitted per request. Candidate rows must fit remaining 56 output, context and memory. Unsupported fixed lengths are refused rather than 57 silently changed. Ties retain the smaller length, including ordinary. 58 59 The decision's five words are draft length, verification rows, expected output 60 millionths, predicted whole-round us, and reason. Reasons: 0 predicted gain, 61 1 explicit mode, 2 unsupported sampling, 3 ordinary fallback, 4 recovery probe. 62 For a chain of length k, expected output is 1 plus the first k survival values. 63 This requires the existing verifier's anchor/correction/bonus convention. 64 Predicted ordinary-normalized gain is derivable from these values and row zero; 65 it is not an observed speedup. 66 67 `sobserve(accepted, emitted, elapsed, eos, complete)` accepts only a completed 68 round. Accepted is at most k. Normally emitted is accepted+1; EOS may truncate 69 it. The full elapsed cost must be positive and at most 6,000,000,000 us. This 70 cost, including adaptation overhead, replaces the last observed cost for that 71 shape. Prefix survival uses a 7/8 previous + 1/8 observed update, clamped 72 monotonically. Only completed past rounds teach the policy. Frozen development 73 costs guide probes; no future fixture result is inspected. 74 75 The observed cost deliberately uses the latest single sample, without smoothing. 76 It responds promptly to a cost step but is sensitive to timing noise; this is a 77 policy choice to evaluate on development trials, not an established advantage. 78 Recovery probes are eligible when ordinary wins and at least eight total rounds 79 have completed since the previous probe (or request start). Eight bounds probing 80 to at most one in eight completed rounds while permitting recovery within a 81 256-token request. This is an initial engineering choice, not a tuned optimum. 82 Any tuning must use development data and a new frozen experiment identity. 83 84 `sstate[6]` counts emitted tokens, `[7]` consumed tokens, `[8]` an emitted but 85 unconsumed correction/bonus. `sresume()` acknowledges that the actual state owner 86 consumed that token. Selection is refused until that acknowledgement. Context 87 and remaining-budget checks follow this boundary. EOS/output exhaustion ends 88 the request. `scancel()` ends the request without learning or accepting output. 89 It does not roll back device memory. The caller must use the existing complete 90 KV, recurrent, convolution and drafter-state owner. These counters cannot prove 91 that physical state was committed correctly. 92 93 ## Observation collector 94 95 `cstart()` freezes identities, epoch and evidence class and clears collection. 96 Only supported-shape descriptors are needed; costs may initially be unknown. 97 Each `cadd()` consumes `cobs[16]`: row index, zero-based ordinal within row, 98 complete flag, outcome (0 success), six phase durations, full wall duration, 99 peak memory, verification rows, epoch, evidence class, phase-known mask (63). 100 Only nonoverlapping phase times may be supplied. Wall duration must cover their 101 sum and be at most 1,000,000,000 us. Residual wall time is attributed to host 102 overhead. Duplicate/out-of-order/incomplete/stale observations are refused. 103 104 At most 32 observations per shape are retained verbatim in `craw`, row-major, 105 with 32 records of 16 words per shape. `ccount` is the count per row; `csum` 106 keeps six phase totals plus wall total; `crange` keeps min/max wall and peak 107 memory. `cseal()` needs at least five samples for every enabled row and no 108 active round. It publishes conservatively rounded-up mean phases and peak 109 memory, then invalidates prior request state. Keep the raw samples and ranges; 110 a mean alone is insufficient evidence of a hardware cost step. 111 112 ## Paired report 113 114 Each group is one fixture at one initial context (1024 or 32768 tokens) and one 115 controller cold/warm mode. `pconfig` holds context, warm flag, fixture ID, 116 minimum usable output length and require-device flag. `parmids` contains the 117 32 expected identity words for each arm: base, ordinary, fixed, adaptive. 118 Every digest must be nonzero, including differing baseline build identities. 119 An unused component binds the digest of an explicitly named absent identity. 120 Weights/tokenizer/numerical recipe/protocol must match across all arms. The base 121 may have a different backend/executable; ordinary/fixed/adaptive share those. 122 Fixed/adaptive additionally share drafter and candidate generator. `pstart(n)` 123 freezes these identities and config, for 5 through 32 paired repetitions. 124 125 `pobs` has 56 words: 126 127 | Offset | Meaning | 128 | --- | --- | 129 | 0..2 | Pair, arm (0..3), fixture ID | 130 | 3..6 | Prompt-token SHA-256 | 131 | 7..10 | Committed-output-token SHA-256 | 132 | 11 | Actual generated count, 1..256 | 133 | 12..14 | Request start, first committed token, request end us | 134 | 15 | Peak memory bytes | 135 | 16 | Stop reason: 1 natural EOS, 2 maximum 256 reached | 136 | 17..19 | Correctness checked (1), complete (1), contamination (0) | 137 | 20..23 | Profile epoch, cold/warm flag, trial ordinal, initial context | 138 | 24..55 | Actual arm identity words | 139 140 Order rotates the four arms by pair index; exact ordinals are required. Every 141 attempt, including invalid ones, is retained in `praw` (at most 256). Invalid 142 attempts poison the group; an accepted-looking retry cannot erase them. Retain 143 the original group and explain any new campaign separately. Prompt identity is 144 fixed across pairs. Within each pair all arms must have identical greedy token 145 digest, length and stop reason. Divergence blocks performance interpretation. 146 The runtime must supply first-divergence logits/state separately; digests cannot 147 explain a numerical error. 148 149 `preport(0|1|2)` compares adaptive with base/ordinary/fixed. `summary` contains: 150 pair count, comparator, median paired speed ratio in millionths, lower/upper 151 95% interval for the population median ratio, adaptive median/p95 full request 152 time, adaptive median/p95 TTFT, adaptive peak memory, verdict, evidence class. 153 Output counts agree within pairs, so the time ratio equals the committed-token 154 throughput ratio. Ratios are rounded down to millionths. Percentiles use nearest 155 rank; an even-count median averages its two central values. 156 Time and TTFT quantiles are each sorted independently. They are not the time or 157 TTFT of the pair at the median speed ratio; the speed ratio remains paired. 158 159 The interval uses [exact binomial order statistics](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/mediancl.htm): choose the largest k whose 160 lower-tail probability is at most 1/40, then use sorted ratios k and n-k+1. 161 It assumes independent paired repetitions. Five pairs cannot give a finite 162 distribution-free 95% interval, so they produce an inconclusive result with 163 unbounded upper endpoint. More repeats improve resolution; noise is retained. 164 The wire representation of that endpoint is ``18446744073709551615``, a sentinel 165 for no finite bound, not a measured ratio. Its lower endpoint and verdict are 0. 166 Verdicts: 0 inconclusive, 1 improvement (entire interval above 1), 2 no detectable 167 improvement (both bounds exactly 1 at the stated resolution), 3 regression 168 (entire interval below 1). A too-short EOS output makes the result inconclusive. 169 Synthetic evidence remains synthetic regardless of its numerical verdict. 170 171 ## Native diagnostic stream 172 173 `replay.om` reads one bounded binary message from stdin and emits a binary 174 decision, sealed table or three reports. It performs no model execution and no 175 hardware verification. Maximum input is 65536 bytes; words are little-endian u64. 176 177 Common input: magic `827867987` (`SCX1`), version 1, operation, reserved 0; then 178 64 identity, 6 profile, 77 row and 31 prior words. The first operation-specific 179 word is index 182. 180 181 - Operation 1: two `scontrol` words followed by the six selection arguments. 182 - Operation 2: sample count followed by that many 16-word cost observations. 183 - Operation 3: five `pconfig` words, pair count, attempt count, 128 `parmids` 184 words, then that many 56-word trial observations. 185 186 Output header: magic, version, operation, evidence class, payload word count. 187 Operation 1 returns five decision words. Operation 2 returns 77 row words, 188 7 counts and 21 range words. Operation 3 returns three 12-word summaries in 189 base/ordinary/fixed order. No partial successful response is emitted after an 190 admission error. Keep the original input alongside the output as the raw record. 191 Statuses: 0 success, 65 malformed/range, 69 identity/version/correctness, 192 74 I/O, 75 incomplete/order/state, 77 unsupported/capacity.