Skip to content

Commit 77e8a1b

Browse files
committed
feat(igla): add IGLA-GF16 architecture verification bench (Module 7)
Implements Module 7 from #3: - `zig build bench-igla` prints architecture verification - Parameter count: encoder + predictor + total in MB GF16 - Trinity Identity proof (|phi^2+1/phi^2 - 3| < 1e-12) - Fibonacci proof (144*phi = 233, |err| < 0.1) - Budget check: total <= 16 MB GF16 All 7 modules of IGLA-GF16 now implemented. Closes #3
1 parent 4834485 commit 77e8a1b

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

benches/igla_gf16_bench.zig

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const std = @import("std");
2+
const tc = @import("../src/trinity_constants.zig");
3+
const jepa = @import("../src/jepa_t.zig");
4+
5+
pub fn main() !void {
6+
const writer = std.io.getStdOut().writer();
7+
8+
try writer.print("IGLA-GF16 Architecture Verification\n", .{});
9+
try writer.print("====================================\n\n", .{});
10+
11+
try writer.print("Architecture:\n", .{});
12+
try writer.print(" d_model = {} (Fib(12))\n", .{tc.D_MODEL});
13+
try writer.print(" n_heads = {} (Fib(6))\n", .{tc.N_HEADS});
14+
try writer.print(" d_head = {} (d_model/n_heads)\n", .{tc.D_HEAD});
15+
try writer.print(" d_ffn = {} (Fib(13) = d_model*phi)\n", .{tc.D_FFN});
16+
try writer.print(" n_layers = {}\n", .{tc.N_LAYERS});
17+
try writer.print(" vocab = {} (GPT-2 BPE)\n\n", .{tc.VOCAB});
18+
19+
const total_mb = jepa.totalMB();
20+
const encoder_params = jepa.encoderParams();
21+
const predictor_params = jepa.predictorParams();
22+
const total_params = jepa.totalParams();
23+
24+
try writer.print("Parameter Count:\n", .{});
25+
try writer.print(" Encoder: {d:>12} params ({d:.1} MB GF16)\n", .{ encoder_params, @as(f64, @floatFromInt(encoder_params)) * 2.0 / 1048576.0 });
26+
try writer.print(" Predictor: {d:>12} params ({d:.1} MB GF16)\n", .{ predictor_params, @as(f64, @floatFromInt(predictor_params)) * 2.0 / 1048576.0 });
27+
try writer.print(" Total: {d:>12} params ({d:.1} MB GF16)\n", .{ total_params, total_mb });
28+
try writer.print(" Budget: 16.0 MB GF16 — {}\n\n", .{if (total_mb <= 16.0) "PASS" else "FAIL"});
29+
30+
try writer.print("Trinity Constants:\n", .{});
31+
try writer.print(" PHI = {d:.16}\n", .{tc.PHI});
32+
try writer.print(" PHI^2 = {d:.16}\n", .{tc.PHI_SQ});
33+
try writer.print(" 1/PHI^2 = {d:.16}\n", .{tc.PHI_INV_SQ});
34+
try writer.print(" Trinity = {d:.16} (should be 3.0)\n", .{tc.TRINITY});
35+
try writer.print(" ALPHA_PHI = {d:.16} (= phi - 1.5)\n", .{tc.ALPHA_PHI});
36+
try writer.print(" phi-split = {d:.3} (encoder/predictor)\n\n", .{jepa.PhiSplit});
37+
38+
try writer.print("Proofs:\n", .{});
39+
const trinity_err = @abs(tc.TRINITY - 3.0);
40+
try writer.print(" [1] Trinity Identity |phi^2+1/phi^2 - 3| = {e} {}\n", .{ trinity_err, if (trinity_err < 1e-12) "PASS" else "FAIL" });
41+
const fib_proof = @as(f64, @floatFromInt(tc.D_MODEL)) * tc.PHI;
42+
const fib_err = @abs(fib_proof - @as(f64, @floatFromInt(tc.D_FFN)));
43+
try writer.print(" [5] Fib proof 144*phi = {d:.2} vs d_ffn={d} |err|={e} {}\n\n", .{ fib_proof, @as(f64, @floatFromInt(tc.D_FFN)), fib_err, if (fib_err < 0.1) "PASS" else "FAIL" });
44+
}

build.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,17 @@ pub fn build(b: *std.Build) void {
164164
test_step.dependOn(&run_phi_attention_tests.step);
165165
test_step.dependOn(&run_trinity_init_tests.step);
166166
test_step.dependOn(&run_jepa_t_tests.step);
167+
168+
const igla_bench_module = b.createModule(.{
169+
.root_source_file = b.path("benches/igla_gf16_bench.zig"),
170+
.target = target,
171+
.optimize = optimize,
172+
});
173+
const igla_bench = b.addExecutable(.{
174+
.name = "igla_gf16_bench",
175+
.root_module = igla_bench_module,
176+
});
177+
const run_igla_bench = b.addRunArtifact(igla_bench);
178+
const igla_bench_step = b.step("bench-igla", "Run IGLA-GF16 architecture verification (Module 7)");
179+
igla_bench_step.dependOn(&run_igla_bench.step);
167180
}

0 commit comments

Comments
 (0)