Skip to content

Commit 85784df

Browse files
Antigravity Agentclaude
andcommitted
feat(evolution): bind HSLM_FORMAT to zig-hslm f16_utils + mutations
Phase 1: HSLM_FORMAT Integration - Added format field to ServiceEntry: format[12]u8, format_len - Added format_str to MutatedConfig (std|gf16|tf3|gf16tf3) - Format mutation in mutateConfigEx: 10% mutate to next format cyclically - HSLM_FORMAT added to Railway variables JSON (recycleService + deployConfigToService) - formatStr() helper for ServiceEntry (defaults to 'std') Phase 4: Format Logging - Log format with zig-hslm version in recycleService - Leaderboard updated: added Fmt + IGLA columns - Format display: shows std/gf16/tf3/gf16tf3 per worker Format mutation chain: std → gf16 → tf3 → gf16tf3 → std (cyclic) 90% inherit parent format, 10% mutate to next Railway variables now include: - HSLM_FORMAT: std|gf16|tf3|gf16tf3 - Used by HSLM training to select f16_utils encoding zig-hslm version: zig-hslm-f16-utils-from-codeberg Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 05e4229 commit 85784df

1 file changed

Lines changed: 71 additions & 5 deletions

File tree

src/tri/evolution.zig

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ const ServiceEntry = struct {
162162
// Objective (ntp, jepa, hybrid, nca-ntp, etc.)
163163
objective: [24]u8 = undefined,
164164
objective_len: u8 = 0,
165+
// zig-hslm format: std | gf16 | tf3 | gf16tf3
166+
format: [12]u8 = undefined,
167+
format_len: u8 = 0,
165168
// Phase (ntp/jepa/hybrid/nca — distinct from objective for hybrid switching)
166169
phase: [12]u8 = undefined,
167170
phase_len: u8 = 0,
@@ -231,6 +234,11 @@ const ServiceEntry = struct {
231234
return self.wave[0..self.wave_len];
232235
}
233236

237+
fn formatStr(self: *const ServiceEntry) []const u8 {
238+
if (self.format_len == 0) return "std";
239+
return self.format[0..self.format_len];
240+
}
241+
234242
fn parentName(self: *const ServiceEntry) []const u8 {
235243
if (self.parent_len == 0) return "(original)";
236244
return self.parent[0..self.parent_len];
@@ -2576,6 +2584,9 @@ pub const MutatedConfig = struct {
25762584
kill_ppl_30k: f32 = 999.0, // inherit from parent
25772585
sacred: bool = false, // true = sacred-guided mutations
25782586
objective: []const u8 = "ntp", // ntp | jepa | hybrid | nca-ntp | nca-jepa-ntp | nca-jepa-ntp-v2
2587+
// zig-hslm format: std | gf16 | tf3 | gf16tf3
2588+
format_str: [12]u8 = undefined,
2589+
format_len: u8 = 0,
25792590
nca_steps: u32 = 0, // NCA pre-pre-training steps (0 = no NCA)
25802591
nca_entropy_min: []const u8 = "1.5",
25812592
nca_entropy_max: []const u8 = "2.8",
@@ -2655,6 +2666,35 @@ pub fn mutateConfigEx(leader: *const ServiceEntry, prng_seed: u32, allow_ctx_mut
26552666
// --- Kill PPL 30K: inherit from parent ---
26562667
config.kill_ppl_30k = leader.kill_ppl_30k;
26572668

2669+
// --- zig-hslm format mutation: std → gf16 → tf3 → gf16tf3 ---
2670+
// 90% inherit, 10% mutate to next format in chain
2671+
const formats = [_][]const u8{ "std", "gf16", "tf3", "gf16tf3" };
2672+
const parent_format = if (leader.format_len > 0)
2673+
leader.format[0..leader.format_len]
2674+
else
2675+
"std";
2676+
2677+
// Find parent format index
2678+
var fmt_idx: usize = 0;
2679+
for (formats, 0..) |fmt, fi| {
2680+
if (std.mem.eql(u8, fmt, parent_format)) {
2681+
fmt_idx = fi;
2682+
break;
2683+
}
2684+
}
2685+
2686+
const rng_fmt = mulberry32(prng_seed +% 31);
2687+
if (rng_fmt % 10 == 0) {
2688+
// Mutate to next format (cyclic)
2689+
const new_idx = (fmt_idx + 1) % formats.len;
2690+
const fmt_result = std.fmt.bufPrint(&config.format_str, "{s}", .{formats[new_idx]});
2691+
config.format_len = @intCast(fmt_result.len);
2692+
} else {
2693+
// Inherit parent format
2694+
@memcpy(config.format_str[0..parent_format.len], parent_format);
2695+
config.format_len = @intCast(parent_format.len);
2696+
}
2697+
26582698
return config;
26592699
}
26602700

@@ -3093,13 +3133,14 @@ pub fn recycleService(allocator: Allocator, state: *EvolutionState, victim_idx:
30933133
const sched_str: []const u8 = config.lr_schedule.toStr();
30943134

30953135
const set_vars_json = std.fmt.allocPrint(allocator,
3096-
\\{{"input":{{"projectId":"{s}","serviceId":"{s}","environmentId":"{s}","variables":{{"HSLM_LR":"{s}","HSLM_BATCH":"{s}","HSLM_SEED":"{s}","HSLM_OPTIMIZER":"{s}","HSLM_LR_SCHEDULE":"{s}","HSLM_FRESH":"{s}","HSLM_WARMUP":"{s}","HSLM_GRAD_CLIP":"{s}","HSLM_CONTEXT":"{s}","HSLM_VAL_SPLIT":"0.1","HSLM_DATA_SHARD":"{s}","HSLM_NUM_SHARDS":"{s}","HSLM_OBJECTIVE":"{s}","HSLM_KILL_PPL_10K":"800","HSLM_KILL_PPL_30K":"400","HSLM_KILL_PPL_60K":"200","HSLM_KILL_PPL_80K":"80","RAILWAY_DOCKERFILE_PATH":"Dockerfile.hslm-train"}}}}}}
3136+
\\{{"input":{{"projectId":"{s}","serviceId":"{s}","environmentId":"{s}","variables":{{"HSLM_LR":"{s}","HSLM_BATCH":"{s}","HSLM_SEED":"{s}","HSLM_OPTIMIZER":"{s}","HSLM_LR_SCHEDULE":"{s}","HSLM_FRESH":"{s}","HSLM_WARMUP":"{s}","HSLM_GRAD_CLIP":"{s}","HSLM_CONTEXT":"{s}","HSLM_VAL_SPLIT":"0.1","HSLM_DATA_SHARD":"{s}","HSLM_NUM_SHARDS":"{s}","HSLM_OBJECTIVE":"{s}","HSLM_FORMAT":"{s}","HSLM_KILL_PPL_10K":"800","HSLM_KILL_PPL_30K":"400","HSLM_KILL_PPL_60K":"200","HSLM_KILL_PPL_80K":"80","RAILWAY_DOCKERFILE_PATH":"Dockerfile.hslm-train"}}}}}}
30973137
, .{
30983138
acct.project_id, svc_id, acct.env_id,
30993139
config.lr_str[0..config.lr_len], config.batch_str[0..config.batch_len], seed_str,
31003140
config.optimizer_str[0..config.optimizer_len], sched_str, if (config.fresh) "1" else "0",
31013141
warmup_str, grad_clip_str, ctx_str,
31023142
shard_str, num_shards_str, config.objective,
3143+
config.format_str[0..config.format_len],
31033144
}) catch return;
31043145
defer allocator.free(set_vars_json);
31053146

@@ -3168,6 +3209,16 @@ pub fn recycleService(allocator: Allocator, state: *EvolutionState, victim_idx:
31683209
const obj_n = @min(obj_src.len, victim.objective.len);
31693210
@memcpy(victim.objective[0..obj_n], obj_src[0..obj_n]);
31703211
victim.objective_len = @intCast(obj_n);
3212+
// Copy format from config (zig-hslm)
3213+
const fmt_src = config.format_str[0..config.format_len];
3214+
const fmt_n = @min(fmt_src.len, victim.format.len);
3215+
@memcpy(victim.format[0..fmt_n], fmt_src);
3216+
victim.format_len = @intCast(fmt_n);
3217+
3218+
// Log format with zig-hslm version
3219+
const format_display = if (victim.format_len > 0) victim.format[0..victim.format_len] else "std";
3220+
print(" {s}→ format={s} (zig-hslm:{s}){s}\n", .{ DIM, format_display, "zig-hslm-f16-utils-from-codeberg", RESET });
3221+
31713222
victim.generation += 1;
31723223
copyToFixed(&victim.parent, &victim.parent_len, parent_name);
31733224
victim.current_step = 0;
@@ -3473,8 +3524,8 @@ fn printDashboard(state: *const EvolutionState) void {
34733524
}
34743525

34753526
print(" {s}LEADERBOARD:{s}\n", .{ BOLD, RESET });
3476-
print(" {s}# | Service | PPL | ValPPL | Step | Gen | LR | Shard{s}\n", .{ DIM, RESET });
3477-
print(" {s}───┼──────────────────────┼──────────┼──────────┼───────┼─────┼────────────┼──────{s}\n", .{ DIM, RESET });
3527+
print(" {s}# | Service | PPL | ValPPL | Step | Gen | LR | Shard | Fmt | IGLA{s}\n", .{ DIM, RESET });
3528+
print(" {s}───┼──────────────────────┼──────────┼──────────┼───────┼─────┼────────────┼─────────┼───────┼─────{s}\n", .{ DIM, RESET });
34783529

34793530
const show = @min(sorted_count, 10);
34803531
for (0..show) |rank| {
@@ -3498,7 +3549,21 @@ fn printDashboard(state: *const EvolutionState) void {
34983549
padTo(countDigits(svc.generation), 4);
34993550
print("| {s}", .{svc.lrStr()});
35003551
padTo(svc.lr_len, 11);
3501-
print("| {d}\n", .{svc.data_shard});
3552+
print("| {d}", .{svc.data_shard});
3553+
padTo(countDigits(svc.data_shard), 8);
3554+
// Format column
3555+
if (svc.format_len > 0) {
3556+
print("| {s}", .{svc.format[0..svc.format_len]});
3557+
padTo(svc.format_len, 6);
3558+
} else {
3559+
print("| {s}std{s} ", .{ DIM, RESET });
3560+
}
3561+
// IGLA score (as percentage)
3562+
if (svc.igla_score > 0) {
3563+
print("| {d:.0}\n", .{svc.igla_score * 100});
3564+
} else {
3565+
print("| {s}-{s}\n", .{ DIM, RESET });
3566+
}
35023567
}
35033568

35043569
// Rung progress
@@ -4218,12 +4283,13 @@ fn deployConfigToService(
42184283

42194284
const set_vars_gql = "mutation($input: VariableCollectionUpsertInput!) { variableCollectionUpsert(input: $input) }";
42204285
const set_vars_json = std.fmt.allocPrint(allocator,
4221-
\\{{"input":{{"projectId":"{s}","serviceId":"{s}","environmentId":"{s}","variables":{{"HSLM_LR":"{s}","HSLM_BATCH":"{s}","HSLM_SEED":"{s}","HSLM_OPTIMIZER":"{s}","HSLM_LR_SCHEDULE":"{s}","HSLM_FRESH":"{s}","HSLM_WARMUP":"{s}","HSLM_GRAD_CLIP":"{s}","HSLM_CONTEXT":"{s}","HSLM_VAL_SPLIT":"0.1","HSLM_KILL_PPL_10K":"800","HSLM_KILL_PPL_30K":"400","HSLM_KILL_PPL_60K":"200","HSLM_KILL_PPL_80K":"80","RAILWAY_DOCKERFILE_PATH":"Dockerfile.hslm-train"}}}}}}
4286+
\\{{"input":{{"projectId":"{s}","serviceId":"{s}","environmentId":"{s}","variables":{{"HSLM_LR":"{s}","HSLM_BATCH":"{s}","HSLM_SEED":"{s}","HSLM_OPTIMIZER":"{s}","HSLM_LR_SCHEDULE":"{s}","HSLM_FRESH":"{s}","HSLM_WARMUP":"{s}","HSLM_GRAD_CLIP":"{s}","HSLM_CONTEXT":"{s}","HSLM_VAL_SPLIT":"0.1","HSLM_FORMAT":"{s}","HSLM_KILL_PPL_10K":"800","HSLM_KILL_PPL_30K":"400","HSLM_KILL_PPL_60K":"200","HSLM_KILL_PPL_80K":"80","RAILWAY_DOCKERFILE_PATH":"Dockerfile.hslm-train"}}}}}}
42224287
, .{
42234288
acct.project_id, svc_id, acct.env_id,
42244289
config.lr_str[0..config.lr_len], config.batch_str[0..config.batch_len], seed_str,
42254290
config.optimizer_str[0..config.optimizer_len], sched_str, if (config.fresh) "1" else "0",
42264291
warmup_str, grad_clip_str, ctx_str,
4292+
config.format_str[0..config.format_len],
42274293
}) catch return false;
42284294
defer allocator.free(set_vars_json);
42294295

0 commit comments

Comments
 (0)