Skip to content

Commit 5339434

Browse files
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

File tree

cppmega_v4/spec/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010
from __future__ import annotations
1111

12+
from cppmega_v4.spec.adapters import (
13+
ADAPTER_RULES,
14+
AdapterRule,
15+
AdapterSuggestion,
16+
insert_adapter_chain,
17+
suggest_adapter_chain,
18+
)
1219
from cppmega_v4.spec.resolver import (
1320
DiagnosticSeverity,
1421
ResolvedBrickGraph,
@@ -26,6 +33,9 @@
2633
)
2734

2835
__all__ = [
36+
"ADAPTER_RULES",
37+
"AdapterRule",
38+
"AdapterSuggestion",
2939
"BrickShapeContract",
3040
"DiagnosticSeverity",
3141
"ResolveError",
@@ -34,7 +44,9 @@
3444
"ShapeDiagnostic",
3545
"ShapeExpr",
3646
"contract_for",
47+
"insert_adapter_chain",
3748
"register_contract",
3849
"registered_kinds",
3950
"resolve_shapes",
51+
"suggest_adapter_chain",
4052
]

0 commit comments

Comments
 (0)