Skip to content

Commit 15763a8

Browse files
committed
fix: thread data materialization schema through gui
1 parent cc9b49d commit 15763a8

9 files changed

Lines changed: 156 additions & 8 deletions

File tree

cppmega_v4/jsonrpc/schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pydantic import BaseModel, ConfigDict, Field
1616

1717

18-
SCHEMA_VERSION: str = "1.1.0"
18+
SCHEMA_VERSION: str = "1.1.1"
1919

2020
JsonRpcVersion = Literal["2.0"]
2121

@@ -369,6 +369,9 @@ class VerifyParams(BaseModel):
369369
side_channels: SideChannelSpecPayload = Field(
370370
default_factory=SideChannelSpecPayload
371371
)
372+
data_materialization: DataMaterializationSpecPayload = Field(
373+
default_factory=DataMaterializationSpecPayload
374+
)
372375
available_side_channels: list[str] = Field(default_factory=lambda: ["doc_ids", "token_ids"])
373376

374377

tests/v4/test_jsonrpc_schema.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,23 @@ def test_verify_params_round_trip():
148148
assert parsed.graph.nodes[0].id == "a"
149149
assert parsed.training is True
150150
assert parsed.side_channels.mode == "auto"
151+
assert parsed.data_materialization.packing_policy == "best_fit"
152+
assert parsed.data_materialization.max_seq_len == 4096
151153
assert parsed.side_channels.families["platform"].columns == [
152154
"platform_ids", "source_platform_ids",
153155
]
154156
serial = parsed.model_dump(mode="json")
155157
assert "graph" in serial
156158
assert serial["side_channels"]["families"]["structure"]["mode"] == "if_available"
159+
assert serial["data_materialization"]["required_token_fields"] == [
160+
"input_ids",
161+
"target_ids",
162+
"loss_mask",
163+
"doc_ids",
164+
"pack_id",
165+
"valid_token_count",
166+
"num_docs",
167+
]
157168

158169

159170
def test_verify_params_rejects_unknown_field():

vbgui/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ function buildVerifyParams(
763763
},
764764
training: true,
765765
side_channels: spec.side_channels,
766+
data_materialization: spec.data_materialization,
766767
available_side_channels: availableSideChannels,
767768
};
768769
}

vbgui/src/lib/types.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Wire-format types matching cppmega_v4.jsonrpc.schema (Pydantic side).
2-
// Keep in sync with SCHEMA_VERSION 1.1.0. When the backend bumps the
2+
// Keep in sync with SCHEMA_VERSION 1.1.1. When the backend bumps the
33
// version, regen this file (codegen lands in F-D).
44

55
export type JsonRpcVersion = "2.0";
@@ -24,7 +24,7 @@ export interface JsonRpcResponse<R = unknown> {
2424
error?: JsonRpcError;
2525
}
2626

27-
export const SCHEMA_VERSION = "1.1.0";
27+
export const SCHEMA_VERSION = "1.1.1";
2828

2929
// ---------------------------------------------------------------------------
3030
// Domain payloads
@@ -81,6 +81,16 @@ export interface SideChannelSpecPayload {
8181
inference: InferenceEnrichmentSpecPayload;
8282
}
8383

84+
export type PackingPolicy = "sequential" | "best_fit";
85+
86+
export interface DataMaterializationSpecPayload {
87+
packing_policy: PackingPolicy;
88+
max_seq_len: number;
89+
pad_to_max: boolean;
90+
include_provenance: boolean;
91+
required_token_fields: string[];
92+
}
93+
8494
export interface EdgeResolution {
8595
src: string;
8696
dst: string;

vbgui/src/state/migrations.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// by a newer build) throw — the caller is expected to surface this as
1313
// a UI error rather than silently corrupting the spec.
1414

15-
export const CURRENT_SCHEMA_VERSION = 1;
15+
export const CURRENT_SCHEMA_VERSION = 2;
1616

1717
export type SchemaVersion = number;
1818

@@ -37,9 +37,46 @@ function migrate_v0_to_v1(spec: VersionedSpec): VersionedSpec {
3737
return { ...spec, schema_version: 1 };
3838
}
3939

40+
function defaultDataMaterialization(): Record<string, unknown> {
41+
return {
42+
packing_policy: "best_fit",
43+
max_seq_len: 4096,
44+
pad_to_max: true,
45+
include_provenance: true,
46+
required_token_fields: [
47+
"input_ids",
48+
"target_ids",
49+
"loss_mask",
50+
"doc_ids",
51+
"pack_id",
52+
"valid_token_count",
53+
"num_docs",
54+
],
55+
};
56+
}
57+
58+
/** v1 → v2: add packed-row materialization defaults to saved GUI specs. */
59+
function migrate_v1_to_v2(spec: VersionedSpec): VersionedSpec {
60+
const nested = spec.spec;
61+
if (nested && typeof nested === "object" && !Array.isArray(nested)) {
62+
const specPayload = nested as Record<string, unknown>;
63+
return {
64+
...spec,
65+
schema_version: 2,
66+
spec: {
67+
...specPayload,
68+
data_materialization:
69+
specPayload.data_materialization ?? defaultDataMaterialization(),
70+
},
71+
};
72+
}
73+
return { ...spec, schema_version: 2 };
74+
}
75+
4076
const MIGRATIONS: Record<number,
4177
(s: VersionedSpec) => VersionedSpec> = {
4278
0: migrate_v0_to_v1,
79+
1: migrate_v1_to_v2,
4380
};
4481

4582
export function migrate(spec: VersionedSpec): VersionedSpec {

vbgui/src/state/spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ export interface SideChannelState {
8484
inference: InferenceEnrichmentState;
8585
}
8686

87+
export type PackingPolicy = "sequential" | "best_fit";
88+
89+
export interface DataMaterializationState {
90+
packing_policy: PackingPolicy;
91+
max_seq_len: number;
92+
pad_to_max: boolean;
93+
include_provenance: boolean;
94+
required_token_fields: string[];
95+
}
96+
8797
export type TopologyFactory =
8898
| "h100_8x" | "h200_8x" | "a100_8x" | "b100_8x"
8999
| "gb10_quarter" | "tpu_v6e_8" | "tpu_v5p_4" | "m3_ultra_solo";
@@ -115,6 +125,7 @@ export interface SpecState {
115125
optim: OptimState;
116126
rewriters: RewriterState[];
117127
side_channels: SideChannelState;
128+
data_materialization: DataMaterializationState;
118129
sharding: ShardingState;
119130
gotchas: GotchaState[];
120131
worst_rank_bytes: number;
@@ -217,6 +228,21 @@ export const INITIAL_SPEC: SpecState = {
217228
cache_enabled: true,
218229
},
219230
},
231+
data_materialization: {
232+
packing_policy: "best_fit",
233+
max_seq_len: 4096,
234+
pad_to_max: true,
235+
include_provenance: true,
236+
required_token_fields: [
237+
"input_ids",
238+
"target_ids",
239+
"loss_mask",
240+
"doc_ids",
241+
"pack_id",
242+
"valid_token_count",
243+
"num_docs",
244+
],
245+
},
220246
sharding: {
221247
topology: "h100_8x",
222248
axis_assignments: [{ axis_name: "dp", kind: "fsdp2", degree: 8 }],

vbgui/tests/App.integration.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,21 @@ describe("App integration — run pipeline", () => {
110110
const pipelineCall = calls.find((c) => c.method === "pipeline.run")!;
111111
const pipelineParams = pipelineCall.params as {
112112
pipeline: { stages: string[] };
113+
spec: {
114+
data_materialization: {
115+
packing_policy: string;
116+
max_seq_len: number;
117+
required_token_fields: string[];
118+
};
119+
};
113120
};
114121
expect(pipelineParams.pipeline.stages).toContain("parse");
115122
expect(pipelineParams.pipeline.stages).toContain("dry_forward");
116123
expect(pipelineParams.pipeline.stages).not.toContain("train");
124+
expect(pipelineParams.spec.data_materialization.packing_policy).toBe("best_fit");
125+
expect(pipelineParams.spec.data_materialization.max_seq_len).toBe(4096);
126+
expect(pipelineParams.spec.data_materialization.required_token_fields)
127+
.toContain("loss_mask");
117128

118129
await waitFor(() => {
119130
expect(screen.getByTestId("run-result-modal")).toBeTruthy();

vbgui/tests/migrations.test.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("V7-H04 spec migrations", () => {
77
it("stamps schema_version on a v0 (pre-versioning) spec", () => {
88
const v0 = { projectName: "demo", spec: {}, nodes: [], edges: [] };
99
const out = migrate(v0);
10-
expect(out.schema_version).toBe(1);
10+
expect(out.schema_version).toBe(CURRENT_SCHEMA_VERSION);
1111
expect(out.projectName).toBe("demo");
1212
});
1313

@@ -30,9 +30,40 @@ describe("V7-H04 spec migrations", () => {
3030
spec: { loss: { kind: "cross_entropy" }, optim: { kind: "adamw" } },
3131
nodes: [{ id: "a" }],
3232
};
33-
const out = migrate(v0) as typeof v0 & { schema_version: number };
34-
expect(out.schema_version).toBe(1);
35-
expect(out.spec).toEqual(v0.spec);
33+
const out = migrate(v0) as typeof v0 & {
34+
schema_version: number;
35+
spec: Record<string, unknown>;
36+
};
37+
expect(out.schema_version).toBe(CURRENT_SCHEMA_VERSION);
38+
expect(out.spec.loss).toEqual(v0.spec.loss);
39+
expect(out.spec.optim).toEqual(v0.spec.optim);
40+
expect(out.spec.data_materialization).toBeDefined();
3641
expect(out.nodes).toEqual(v0.nodes);
3742
});
43+
44+
it("adds data materialization defaults when loading v1 specs", () => {
45+
const v1 = {
46+
schema_version: 1,
47+
spec: { loss: { kind: "cross_entropy" } },
48+
};
49+
const out = migrate(v1) as typeof v1 & {
50+
spec: { data_materialization?: unknown };
51+
};
52+
expect(out.schema_version).toBe(CURRENT_SCHEMA_VERSION);
53+
expect(out.spec.data_materialization).toEqual({
54+
packing_policy: "best_fit",
55+
max_seq_len: 4096,
56+
pad_to_max: true,
57+
include_provenance: true,
58+
required_token_fields: [
59+
"input_ids",
60+
"target_ids",
61+
"loss_mask",
62+
"doc_ids",
63+
"pack_id",
64+
"valid_token_count",
65+
"num_docs",
66+
],
67+
});
68+
});
3869
});

vbgui/tests/spec.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ describe("side-channel defaults", () => {
106106
]);
107107
expect(INITIAL_SPEC.side_channels.inference.fail_policy).toBe("drop_family");
108108
});
109+
110+
it("INITIAL_SPEC exposes packed-row materialization defaults", () => {
111+
expect(INITIAL_SPEC.data_materialization).toEqual({
112+
packing_policy: "best_fit",
113+
max_seq_len: 4096,
114+
pad_to_max: true,
115+
include_provenance: true,
116+
required_token_fields: [
117+
"input_ids",
118+
"target_ids",
119+
"loss_mask",
120+
"doc_ids",
121+
"pack_id",
122+
"valid_token_count",
123+
"num_docs",
124+
],
125+
});
126+
});
109127
});
110128

111129
describe("memory helpers", () => {

0 commit comments

Comments
 (0)