Commit 5339434
committed
feat(v4/spec): VBSpec Stage C — adapter library + chain suggestion / insertion
Adds cppmega_v4.spec.adapters, the auto-bridge library that closes
common shape gaps the resolver surfaces (VisualBuilderSpec.md §3.3, §6 C).
Six adapter brick kinds, each with a registered BrickShapeContract and
classified as norm_or_proj in the fusion compatibility table (so they
fuse into neighbour kernels at runtime, making them effectively free):
- adapter_merge_heads (B,nh,S,d) -> (B,S,nh*d)
- adapter_split_heads (B,S,nh*d) -> (B,nh,S,d) — handles both
(B,nh,S,d) and (B,S,nh,d) consumer layouts so a second transpose
rule can finish the chain.
- adapter_transpose_bnsd (B,nh,S,d) -> (B,S,nh,d)
- adapter_linear_bridge (B,S,H_in) -> (B,S,H_out)
- adapter_rmsnorm RMSNorm with H params
- adapter_residual pure passthrough residual
Public surface (re-exported from cppmega_v4.spec):
- ADAPTER_RULES, AdapterRule (table-driven trigger/transform/description)
- AdapterSuggestion (one step in a planned chain)
- suggest_adapter_chain(producer_shape, consumer_shape, *, max_steps=4):
greedy walker that tries rules in order and reports the shortest
chain that lands on consumer_shape, or None.
- insert_adapter_chain(graph, producer, consumer, suggestions): splices
the chain into a BrickGraph on the named edge, preserving edge
order and synthesising unique node names (suffix on collision).
Tests (tests/v4/test_vbspec_stage_c.py, 31 cases):
- registration: every adapter kind has a contract AND is norm_or_proj
- per-rule trigger/transform unit cases (merge, split, transpose,
bridge); no false-positives when shapes already match
- suggest_adapter_chain: empty, single-step, two-step (split + transpose),
no-rule-path-exists, max_steps exhaustion
- insert_adapter_chain: noop, unknown-edge raises, single insertion,
multi-insertion preserves order, name-collision suffix
- system: inserted adapter fuses with linear-attn neighbour (planner
still groups all three into one region); end-to-end resolver -> chain
-> splice -> re-resolve flow
Full v4 regression: 702 passed / 5 skipped / 0 failed.1 parent 6adaa9b commit 5339434
3 files changed
Lines changed: 752 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
12 | 19 | | |
13 | 20 | | |
14 | 21 | | |
| |||
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
29 | 39 | | |
30 | 40 | | |
31 | 41 | | |
| |||
34 | 44 | | |
35 | 45 | | |
36 | 46 | | |
| 47 | + | |
37 | 48 | | |
38 | 49 | | |
39 | 50 | | |
| 51 | + | |
40 | 52 | | |
0 commit comments