Commit b92ad2b
feat(onnx): ONNX runtime serving path for predict() (vector layout)
Adds the opt-in foundation-model serving path (make loadable-onnx,
-DSQLITE_PREDICT_ONNX). predict-onnx.c is the only file that links
onnxruntime; the core `loadable` stays pure C99, zero-dependency (0 onnx
symbols, 0 onnxruntime linkage, verified).
This pass implements the 'vector' io_spec layout: a self-contained,
pre-trained model (a distilled student or any exported tabular
classifier/regressor) mapping features -> prediction, dispatched through
the existing predict() model-backend seam. The 'in_context' layout (a
teacher such as TabFM that ingests the training rows as context) and the
GPU execution providers are the next pass, validated on the gated GPU
runner; requesting cuda/tensorrt here fails loud rather than silently
dropping to CPU.
Performance shape (per RFC 0005): sessions are cached process-global by
(weights, device, precision) and reused; query rows run in batches, not
one at a time; execution-provider selection is explicit.
Registry/plumbing:
- _predict_models gains weights_uri (external teacher weights) + io_spec
(tensor mapping); the weight-source CHECK now allows an inline BLOB
(small students) XOR a URI (large teachers). Idempotent column adds.
- predict_register(model_id, config_json) records a model and pins its
weights by content hash so the receipt/replay path can detect changes.
- New error codes: MODEL_EXISTS, RUNTIME_UNAVAILABLE, IO_SPEC, INFERENCE.
- Receipts record the execution provider + precision; the CPU-fp32 path
is deterministic, so replay is bit-exact (proven by the tests).
- License gate: a non-permissive model (TabFM is non-commercial) needs
accept_license to match before it will run.
Tests (self-skip when the extension has no onnx runtime, so `make test`
ignores them): hand-built ONNX fixtures with reference outputs computed
independently in pure Python; classifier + regressor correctness, exact
replay, mutation detection, 2500-row multi-batch, non-numeric handling,
license gate, fail-loud device/precision, schema mismatches, and an RSS
leak soak. Plus an ASan/UBSan/LSan C soak (make test-asan-onnx) and a CI
onnx job on ubuntu.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: mstrathman <matthew.strathman@gmail.com>1 parent 0e4887e commit b92ad2b
15 files changed
Lines changed: 1997 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
41 | 53 | | |
42 | 54 | | |
43 | 55 | | |
| |||
58 | 70 | | |
59 | 71 | | |
60 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
61 | 81 | | |
62 | 82 | | |
63 | 83 | | |
| |||
66 | 86 | | |
67 | 87 | | |
68 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
69 | 95 | | |
70 | 96 | | |
71 | 97 | | |
| |||
78 | 104 | | |
79 | 105 | | |
80 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
81 | 122 | | |
82 | 123 | | |
83 | 124 | | |
| |||
134 | 175 | | |
135 | 176 | | |
136 | 177 | | |
137 | | - | |
| 178 | + | |
| 179 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
| |||
127 | 131 | | |
128 | 132 | | |
129 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
130 | 201 | | |
131 | 202 | | |
132 | 203 | | |
| |||
0 commit comments