diff --git a/CHANGELOG.md b/CHANGELOG.md index d886df2858c..e2038d8231a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,14 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel ## Unreleased +- Checkpoints: a bf16 weight stored in DFloat11's lossless form is read under its own name and decoded on the host at load to the bf16 bytes it was coded from, where such a checkpoint was refused by the missing tensor's name; GLM-5.3-Flash on CUDA is the one loader that attaches it, a damaged group is refused by name, and a checkpoint with no coded tensor loads as before (#3807, refs #3649). Thanks to @Bizuayeu. + - Flash Next on CUDA: `TF_FLASHNEXT_SPLIT_DENSE` and `TF_FLASHNEXT_SHARD_HEAD` are checked by name when the engine loads, so a malformed value names the variable, the supplied text and the accepted forms, and an empty or blank value reads as unset; valid values and defaults are unchanged (#3749, refs #2370). Thanks to @devopsfortunato. - Tests: the Web loopback startup regression sets its stand-in past the three-second warm-up, so it passes standalone and in the full suite alike (#4086, fixes #3752). - Docs: a one-GB10 recipe serves DeepSeek-V4-Pro-Qwen3.5-9B from a locally converted MLX 4-bit checkpoint, thinking and drafts off, with its health, model-list and chat checks (#4085, fixes #3905). - - - Qwen 3.5/3.6/3.8 on CUDA: `TF_QWEN35_CHUNK_SOLO=8192` lets a foreground prompt pass take up to 8,192 rows while no other stream decodes, back to 4,096 once one does and in background warm passes; unset or 4096 is off, and tokens match it off (#3294). Thanks to @jschmied. - Docs: the Flash Next CUDA recipe pulls the checkpoint and serves it by name, and supported models gives it as a 105.5 GiB download of which 73.3 GiB goes to the GPU (#4024). Thanks to @jayleaton. @@ -38,8 +38,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - Docs: on unified memory, `MemAvailable` can settle a little above the reserve after start-up and the pool's page count can differ by a few tens between launches with the same settings, because the room is read once while the host is still settling (#4079, fixes #3940). Thanks to @Bizuayeu. - - - Web: the development stand-in reports native 1.3.0, in a checkout and in the built wheel, where it still said 1.2.10 (#4077, fixes #4074). Thanks to @AIFlowML. - CI: a landing train's pull request skips GitHub's hosted checks, which our own runners already run on its tip (a red local run still starts them by hand), and a newer push cancels an older Zig format run, so main's and contributors' checks no longer queue behind trains (#4106). @@ -48,22 +46,16 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - Qwen3.8-27B on Metal: a request cancelled during its prompt pass, a drafted round or a streamed reply keeps the prompt state it completed when the prompt cache has room, so a follow-up on the same conversation resumes there instead of re-reading the history; after a cancelled reply, slot 0 first rewinds to its saved prompt state, and in the shared lane core a cancelled pass gives up only its own cache reservation (#3643, for #3618). - - - Server: every prompt-cache lookup records why it did not resume further (for example `cold`, `evicted`, `shed`, `prompt_changed` or `reply_changed`), and `/metrics` counts them as `prompt_cache_miss_total{reason}` over a fixed list of reason names (#3706, for #3686). Thanks to @bikepresentball. - DeepSeek-V4.1 on Metal: the prompt layer's compressor, indexer key and weight, and MoE gate projections run on a new simdgroup-matrix kernel (`tf_dsv41_mv_mma`) at 16 or more rows, bit-equal to the matrix-vector kernel it replaces (#3668, refs #2984). Thanks to @gilby. - - - Qwen on CUDA: a development build for sm_110 (`-Dsm=110`, NVIDIA Thor) refuses by name, before paging or weight loading, the modes not qualified there: `--slide`, a DSpine `--drafter`, `TF_DSPINE_WINDOW`, `--kv-cache fp8`, `--prompt-precision int8`, `--rope-yarn`, `TF_QWEN_KV_PAGES`, `TF_QWEN_KV_PAGES_ALL=1`, `TF_QWEN_KV_SHARE`, `TF_QWEN_REQUEST_STARTS=1`, `TF_QWEN_KV_PAGE_TEST`, `TF_QWEN_KEEP_LATE=1`, `TF_NO_TREES` and `TF_DRAFT_NODES`; the default path and the DFlash2 drafter are still served, and other GPUs are unchanged (#3057, refs #2319). Thanks to @yguanrong. - CUDA: a Flash Next prompt pass holds 3,072 rows while other streams decode (it held 1,536), so a long prompt beside running streams takes half as many passes (#3726). Thanks to @BadAd84. - GLM-5.3-Flash on CUDA: the sampled draw takes its rule from the shared `cuda.sample.rule`, as MiniMax M3 does, instead of building its own copy with a fixed `near` value (#3705, part of #2680). Thanks to @jschmied. - - - Server: `GET /v1/models/{id}` (and `/models/{id}`) returns the entry `/v1/models` lists for the served name or an alias, the id sent as written or percent-escaped (`org%2Fname`); any other id is a 404 `model_not_found`, and API keys and key scopes treat the route as they treat `/v1/models` (#3535). - Server: the next turn's background prefill puts the reply's reasoning into its guess when the client sends reasoning back, so thinking requests resume from the real next prompt instead of redoing the pass from before the reply; clients whose history drops reasoning keep the old guess (#3264). @@ -76,8 +68,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - GLM-5.3-Flash on CUDA: GLM's kernels and qmmf's decode linears launch as programmatic dependent launches, so a decode token's kernels lose most of their launch gaps; experts, the router plan and the RoCE exchange stay plain launches, a prompt chunk's KDA chain launches plain from 64 rows, and `TF_GLM_PDL=0` launches everything plain (#3776, refs #3652). Thanks to @ultradaoto. - - - dots.mocr on CUDA: `--vision` now serves images through the image tower instead of refusing them, within the request's `--vision-image-tokens` budget; text-only replies keep their pinned hashes, and the GB10 runner gains `tf-cuda-test dots-text` (three prompts of our own, served with and without `--vision`, against pinned reply hashes) and `dots-invariants` (image prompts cut into chunks against the uncut run) (#2771, refs #1927). Thanks to @laudney. - Qwen3.8-27B on Metal before M5: decode rounds read their cached keys through the prefix kernels, as on an M5, and prompt passes size their memory the same way; `TF_QWEN27_SHARED_PREFIX=0` keeps cached keys on the tail kernel (#3677, refs #3604). Thanks to @hobbesd. @@ -90,8 +80,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - Desktop: an MCP server's startup diagnostics reach the Plugins preview as whole lines, masked as a whole and capped at 64 KiB, instead of one row per stderr write (#3759). Thanks to @AIFlowML. - - - Flash Next on HIP: the prompt chunk fallback counts the window plan's slot bytes as used before deciding whether a smaller chunk admits more streams, where it counted them as free and could keep the larger chunk (#3419). Thanks to @gilby. - DeepSeek-V4.1 on Metal: its GPU work goes through a Metal 4 command queue by default where the Mac has one (macOS 26 and later), with the same kernels in the same order and bit-identical outputs; `TF_METAL4=0` keeps Metal 3, `TF_METAL4_TIMELINE=n` logs per-stage GPU times for n rounds of each kind, and `TF_DSV41_ROUND_PROF=1` logs decode rounds' host and GPU milliseconds (#3374). diff --git a/zig/src/core/checkpoint.zig b/zig/src/core/checkpoint.zig index 9aeea75088d..0eb103d87db 100644 --- a/zig/src/core/checkpoint.zig +++ b/zig/src/core/checkpoint.zig @@ -7,6 +7,7 @@ const index_format = @import("checkpoint_index.zig"); const prefetching = @import("checkpoint_prefetch.zig"); pub const cache = @import("checkpoint_cache.zig"); +pub const coded = @import("checkpoint_coded.zig"); pub const direct = @import("checkpoint_direct.zig"); pub const Tensor = st.Tensor; pub const DType = st.DType; @@ -72,6 +73,8 @@ pub const Checkpoint = struct { scope: []const u8 = "", /// Copies `get` returns in place of the mapping's bytes, by full name (checkpoint_direct's current layer). copies: ?*const std.StringHashMapUnmanaged([]const u8) = null, + /// DFloat11 groups answered under their members' weight names (`coded.attach`); null: every name is a header's. + coded: ?*coded.Coded = null, fn scoped(self: *const Checkpoint, buf: *[320]u8, name: []const u8) ![]const u8 { if (self.scope.len == 0) return name; @@ -107,6 +110,7 @@ pub const Checkpoint = struct { } pub fn close(self: *Checkpoint) void { + if (self.coded) |c| c.deinit(self.gpa); for (self.files.items) |*f| f.close(self.io); self.files.deinit(self.gpa); self.used.deinit(self.gpa); @@ -116,7 +120,11 @@ pub const Checkpoint = struct { /// The tensor named `name`, marked as used; a missing name is an error naming it. pub fn get(self: *Checkpoint, short: []const u8) !Tensor { var buf: [320]u8 = undefined; - const name = try self.scoped(&buf, short); + return self.find(try self.scoped(&buf, short), null); + } + + /// The tensor a header names `name` (the full name), marked as used; null when no file holds it. + pub fn stored(self: *Checkpoint, name: []const u8) !?Tensor { for (self.files.items) |*f| if (f.get(name)) |t| { const key = f.names.getKey(name).?; try self.used.put(self.gpa, key, {}); @@ -126,13 +134,21 @@ pub const Checkpoint = struct { }; return out; }; + return null; + } + + /// A header's tensor, else a coded one in `shape` (its loader's shape for the name without one). + fn find(self: *Checkpoint, name: []const u8, shape: ?[]const usize) !Tensor { + if (try self.stored(name)) |t| return t; + if (self.coded) |c| if (try c.get(self, name, shape)) |t| return t; std.log.err("checkpoint has no tensor {s}", .{name}); return error.MissingTensor; } /// `get` with the dtype and shape checked. pub fn expect(self: *Checkpoint, name: []const u8, dtype: DType, shape: []const usize) !Tensor { - const t = try self.get(name); + var buf: [320]u8 = undefined; + const t = try self.find(try self.scoped(&buf, name), shape); if (!t.is(dtype, shape)) { std.log.err("{s}: {t} {any}, expected {t} {any}", .{ name, t.dtype, t.shape[0..t.rank], dtype, shape }); return error.UnexpectedTensor; @@ -145,7 +161,7 @@ pub const Checkpoint = struct { var buf: [320]u8 = undefined; const name = self.scoped(&buf, short) catch return false; for (self.files.items) |*f| if (f.get(name) != null) return true; - return false; + return if (self.coded) |c| c.names.contains(name) else false; } /// Marks every name starting with `prefix` as used: a part the loader leaves out on purpose. @@ -157,8 +173,9 @@ pub const Checkpoint = struct { }; } - /// Every file's pages out of the page cache (safetensors.File.release). + /// Every file's pages out of the page cache (safetensors.File.release), and every decoded group freed. pub fn release(self: *const Checkpoint) void { + if (self.coded) |c| c.drop(self.gpa); for (self.files.items) |*f| f.release(self.gpa); } diff --git a/zig/src/core/checkpoint_coded.zig b/zig/src/core/checkpoint_coded.zig new file mode 100644 index 00000000000..cc5fb764388 --- /dev/null +++ b/zig/src/core/checkpoint_coded.zig @@ -0,0 +1,157 @@ +//! DFloat11-coded weights under a Checkpoint's names: groups found in the headers, each decoded once until a release. + +const std = @import("std"); +const st = @import("safetensors.zig"); +const dfloat11 = @import("dfloat11.zig"); +const layout = @import("dfloat11_config.zig"); +const Checkpoint = @import("checkpoint.zig").Checkpoint; + +/// A family's shapes for the names its loader takes with `get`: the files hold each member's element count alone. +pub const Shapes = struct { + ctx: *const anyopaque, + of: *const fn (ctx: *const anyopaque, name: []const u8, buf: *[st.max_rank]usize) ?[]const usize, +}; + +const stream = ".encoded_exponent"; +const parts = [_]struct { []const u8, st.DType }{ + .{ ".luts", .u8 }, .{ stream, .u8 }, .{ ".sign_mantissa", .u8 }, + .{ ".output_positions", .u8 }, .{ ".gaps", .u8 }, .{ ".split_positions", .i64 }, +}; + +const Name = struct { group: u32, member: u32 }; +const Group = struct { + prefix: []const u8, + members: u32, + /// The whole group as little-endian BF16, from the first `get` of a member until `drop`. + decoded: ?[]align(64) u8 = null, +}; + +pub const Coded = struct { + arena: std.heap.ArenaAllocator, + bytes_per_thread: u32, + threads_per_block: u32, + shapes: ?Shapes, + names: std.StringHashMapUnmanaged(Name) = .empty, + groups: std.ArrayList(Group) = .empty, + + /// Coded `name` in `want`'s shape (the family's without one), alive until the next `release`; null: not coded. + pub fn get(c: *Coded, ck: *Checkpoint, name: []const u8, want: ?[]const usize) !?st.Tensor { + const at = c.names.get(name) orelse return null; + const g = &c.groups.items[at.group]; + var buf: [st.max_rank]usize = undefined; + const shape = want orelse (if (c.shapes) |s| s.of(s.ctx, name, &buf) else null) orelse { + refuse("{s} is DFloat11-coded, and its loader names no shape for it", .{name}); + return error.CodedShapeUnknown; + }; + if (shape.len > st.max_rank) return error.RankTooHigh; + var stored: [parts.len][]const u8 = undefined; + var part: [320]u8 = undefined; + for (parts, &stored) |p, *bytes| { + const full = std.fmt.bufPrint(&part, "{s}{s}", .{ g.prefix, p[0] }) catch return error.MissingTensor; + bytes.* = ((try ck.stored(full)) orelse return error.MissingTensor).bytes; + } + const n = stored[2].len; + const range = try dfloat11.member(stored[5], g.members, n, at.member); + var count: usize = 1; + for (shape) |d| count = std.math.mul(usize, count, d) catch return error.UnexpectedTensor; + if (count != range.end - range.begin) { + refuse("{s}: {d} coded elements, expected {any}", .{ name, range.end - range.begin, shape }); + return error.UnexpectedTensor; + } + if (g.decoded == null) { + const bytes = std.math.mul(usize, 2, n) catch return error.UnexpectedTensor; + const out = try ck.gpa.alignedAlloc(u8, .@"64", bytes); + errdefer ck.gpa.free(out); + dfloat11.decode(.{ + .luts = stored[0], + .encoded_exponent = stored[1], + .sign_mantissa = stored[2], + .output_positions = stored[3], + .gaps = stored[4], + .bytes_per_thread = c.bytes_per_thread, + .threads_per_block = c.threads_per_block, + }, out) catch |err| { + refuse("DFloat11 group {s}: {t}", .{ g.prefix, err }); + return err; + }; + g.decoded = out; + } + var t: st.Tensor = .{ .dtype = .bf16, .rank = @intCast(shape.len), .shape = @splat(1), .bytes = g.decoded.?[2 * range.begin .. 2 * range.end] }; + @memcpy(t.shape[0..shape.len], shape); + return t; + } + + /// Frees every decoded group: tensors `get` returned are gone, and the next `get` decodes again. + pub fn drop(c: *Coded, gpa: std.mem.Allocator) void { + for (c.groups.items) |*g| if (g.decoded) |bytes| { + gpa.free(bytes); + g.decoded = null; + }; + } + + pub fn deinit(c: *Coded, gpa: std.mem.Allocator) void { + c.drop(gpa); + c.arena.deinit(); + gpa.destroy(c); + } +}; + +/// Has `ck` answer the member weight names of its groups (a `.encoded_exponent` and five more tensors each). +pub fn attach(ck: *Checkpoint, config: layout.Config, shapes: ?Shapes) !void { + std.debug.assert(ck.coded == null); + const c = try ck.gpa.create(Coded); + c.* = .{ .arena = .init(ck.gpa), .bytes_per_thread = config.bytes_per_thread, .threads_per_block = config.threads_per_block, .shapes = shapes }; + errdefer { + c.arena.deinit(); + ck.gpa.destroy(c); + } + const a = c.arena.allocator(); + for (ck.files.items) |*f| for (f.names.keys()) |k| { + if (!std.mem.endsWith(u8, k, stream)) continue; + const prefix = k[0 .. k.len - stream.len]; + const pattern = (try config.group(prefix)) orelse { + refuse("DFloat11 group {s}: no pattern of dfloat11_config describes it", .{prefix}); + return error.CodedGroupUnlisted; + }; + var split: usize = 0; + for (parts) |p| { + const e = entry(ck, try std.fmt.allocPrint(a, "{s}{s}", .{ prefix, p[0] })) orelse { + refuse("DFloat11 group {s}: no {s}", .{ prefix, p[0][1..] }); + return error.CodedGroupPartial; + }; + if (e.dtype != p[1]) return error.CodedGroupPartial; + split = e.end - e.begin; + } + const members = @max(1, pattern.members.len); + if (split != 8 * (members - 1)) { + refuse("DFloat11 group {s}: {d} members listed, {d} split positions stored", .{ prefix, members, split / 8 }); + return error.CodedMembers; + } + const group: u32 = @intCast(c.groups.items.len); + try c.groups.append(a, .{ .prefix = try a.dupe(u8, prefix), .members = @intCast(members) }); + for (0..members) |j| { + const name = if (pattern.members.len == 0) + try std.fmt.allocPrint(a, "{s}.weight", .{prefix}) + else + try std.fmt.allocPrint(a, "{s}.{s}.weight", .{ prefix, pattern.members[j] }); + // a name stored plain as well, or coded by two groups, has no one answer + const slot = try c.names.getOrPut(a, name); + if (slot.found_existing or entry(ck, name) != null) { + refuse("{s} is DFloat11-coded in {s} and also stored elsewhere", .{ name, prefix }); + return error.CodedNameStored; + } + slot.value_ptr.* = .{ .group = group, .member = @intCast(j) }; + } + }; + ck.coded = c; +} + +/// A refusal's line for the log; host tests refuse on purpose, and a logged error fails their run. +fn refuse(comptime fmt: []const u8, args: anytype) void { + if (!@import("builtin").is_test) std.log.err(fmt, args); +} + +fn entry(ck: *const Checkpoint, name: []const u8) ?st.Entry { + for (ck.files.items) |*f| if (f.names.get(name)) |e| return e; + return null; +} diff --git a/zig/src/core/checkpoint_coded_test.zig b/zig/src/core/checkpoint_coded_test.zig new file mode 100644 index 00000000000..971483380b2 --- /dev/null +++ b/zig/src/core/checkpoint_coded_test.zig @@ -0,0 +1,250 @@ +//! checkpoint_coded's tests: a folder of two DFloat11 groups and a plain tensor, read through a Checkpoint. + +const std = @import("std"); +const testing = std.testing; +const Io = std.Io; +const Checkpoint = @import("checkpoint.zig").Checkpoint; +const coded = @import("checkpoint_coded.zig"); +const layout = @import("dfloat11_config.zig"); +const fixture = @import("checkpoint_fixture.zig"); +const groups = @import("dfloat11_fixtures.zig").groups; + +const layer = groups[1]; // four members of 60, 1, 150 and 29 elements, blocks of 4 threads +const head = groups[2]; // one weight of 1,500 elements, codes of two tables, blocks of 4 threads +const members = [_][]const u8{ "attn.q", "attn.k", "mlp.up", "mlp.down" }; +const ends = [_]usize{ 0, 60, 61, 211, 240 }; +const config_text = + \\{"dfloat11_config":{"version":"0.2.0","bytes_per_thread":8,"threads_per_block":[4],"pattern_dict": + \\{"lm_head":[],"model.layers.\\d+":["attn.q","attn.k","mlp.up","mlp.down"]}}} +; +const plain = [_]u8{ 0x80, 0x3f, 0x00, 0x40 }; + +/// What a family's loader would know: the two names these tests take with `get`. +fn shapeOf(_: *const anyopaque, name: []const u8, buf: *[5]usize) ?[]const usize { + const known = [_]struct { []const u8, [2]usize }{ .{ "lm_head.weight", .{ 30, 50 } }, .{ "model.layers.0.attn.q.weight", .{ 6, 10 } } }; + for (known) |k| if (std.mem.eql(u8, name, k[0])) { + buf[0..2].* = k[1]; + return buf[0..2]; + }; + return null; +} +const shapes: coded.Shapes = .{ .ctx = &plain, .of = shapeOf }; + +/// The six tensors of `g` under `prefix`, with `gaps` in place of its own when given. +fn groupEntries(a: std.mem.Allocator, out: *std.ArrayList(fixture.Entry), prefix: []const u8, g: anytype, gaps: ?[]const u8) !void { + const split = try a.alloc(u8, 8 * g.split_positions.len); + for (g.split_positions, 0..) |v, i| std.mem.writeInt(i64, split[8 * i ..][0..8], v, .little); + const stored = [_]struct { []const u8, []const u8, []const u8, []const usize }{ + .{ "luts", "U8", g.luts, &.{ g.luts.len / 256, 256 } }, + .{ "encoded_exponent", "U8", g.encoded_exponent, &.{g.encoded_exponent.len} }, + .{ "sign_mantissa", "U8", g.sign_mantissa, &.{g.sign_mantissa.len} }, + .{ "output_positions", "U8", g.output_positions, &.{g.output_positions.len} }, + .{ "gaps", "U8", gaps orelse g.gaps, &.{g.gaps.len} }, + .{ "split_positions", "I64", split, &.{g.split_positions.len} }, + }; + for (stored) |s| try out.append(a, .{ + .name = try std.fmt.allocPrint(a, "{s}.{s}", .{ prefix, s[0] }), + .dtype = s[1], + .shape = try a.dupe(usize, s[3]), + .bytes = s[2], + }); +} + +const Folder = struct { + tmp: testing.TmpDir, + arena: std.heap.ArenaAllocator, + entries: std.ArrayList(fixture.Entry) = .empty, + path: [64]u8 = undefined, + + /// The layer's group, the head's and a plain norm, not yet written. + fn init() !Folder { + var f: Folder = .{ .tmp = testing.tmpDir(.{}), .arena = .init(testing.allocator) }; + errdefer f.deinit(); + const a = f.arena.allocator(); + try groupEntries(a, &f.entries, "model.layers.0", layer, null); + try groupEntries(a, &f.entries, "lm_head", head, null); + try f.entries.append(a, .{ .name = "model.norm.weight", .dtype = "BF16", .shape = &.{2}, .bytes = &plain }); + return f; + } + + fn deinit(f: *Folder) void { + f.arena.deinit(); + f.tmp.cleanup(); + } + + /// Writes the entries (less the first one named `without`) as one file and gives the folder's path. + fn write(f: *Folder, without: ?[]const u8) ![]const u8 { + const a = f.arena.allocator(); + var kept: std.ArrayList(fixture.Entry) = .empty; + var left = without; + for (f.entries.items) |e| { + if (left != null and std.mem.eql(u8, e.name, left.?)) left = null else try kept.append(a, e); + } + try fixture.write(a, testing.io, f.tmp.dir, "model.safetensors", kept.items); + return std.fmt.bufPrint(&f.path, ".zig-cache/tmp/{s}", .{f.tmp.sub_path}); + } + + fn config(f: *Folder, text: []const u8) !layout.Config { + return (try layout.parse(f.arena.allocator(), text)).?; + } +}; + +test "a coded member answers under its own weight name with the bytes it was coded from, in the shape asked" { + var f = try Folder.init(); + defer f.deinit(); + var ck = try Checkpoint.openModel(testing.allocator, testing.io, try f.write(null)); + defer ck.close(); + // unattached, the names are no header's: missing, as before + try testing.expect(!ck.has("lm_head.weight")); + try coded.attach(&ck, try f.config(config_text), shapes); + var name: [64]u8 = undefined; + for (members, 0..) |m, j| { + const full = try std.fmt.bufPrint(&name, "model.layers.0.{s}.weight", .{m}); + try testing.expect(ck.has(full)); + const t = try ck.expect(full, .bf16, &.{ends[j + 1] - ends[j]}); + try testing.expectEqualSlices(u8, layer.want[2 * ends[j] .. 2 * ends[j + 1]], t.bytes); + try testing.expectEqual(@as(usize, 0), @intFromPtr(t.bytes.ptr) % 2); + } + // `get` has no shape of its own: the family's + const w = try ck.get("lm_head.weight"); + try testing.expect(w.is(.bf16, &.{ 30, 50 })); + try testing.expectEqualSlices(u8, head.want, w.bytes); + try testing.expectEqualSlices(u8, &plain, (try ck.get("model.norm.weight")).bytes); + try testing.expect(!ck.has("model.layers.0.attn.q") and !ck.has("model.layers.1.attn.q.weight")); + try testing.expectEqual(@as(usize, 0), ck.unused()); +} + +test "a group is decoded once: later gets share its buffer until a release, and after one it decodes again" { + var f = try Folder.init(); + defer f.deinit(); + var ck = try Checkpoint.openModel(testing.allocator, testing.io, try f.write(null)); + defer ck.close(); + try coded.attach(&ck, try f.config(config_text), shapes); + const c = ck.coded.?; + for (c.groups.items) |g| try testing.expect(g.decoded == null); + const q = try ck.get("model.layers.0.attn.q.weight"); + const again = try ck.get("model.layers.0.attn.q.weight"); + try testing.expectEqual(q.bytes.ptr, again.bytes.ptr); + // another member of the group is a slice of the same buffer + const up = try ck.expect("model.layers.0.mlp.up.weight", .bf16, &.{ 15, 10 }); + try testing.expectEqual(q.bytes.ptr + 2 * 61, up.bytes.ptr); + var held: usize = 0; + for (c.groups.items) |g| held += @intFromBool(g.decoded != null); + try testing.expectEqual(@as(usize, 1), held); // the head's group was not asked for + ck.release(); + for (c.groups.items) |g| try testing.expect(g.decoded == null); + const back = try ck.get("model.layers.0.attn.q.weight"); + try testing.expectEqualSlices(u8, layer.want[0..120], back.bytes); +} + +test "a checkpoint opened under a prefix and read under a scope finds the groups under it alone" { + var f = try Folder.init(); + defer f.deinit(); + var ck = try Checkpoint.openModelPrefix(testing.allocator, testing.io, try f.write(null), "model."); + defer ck.close(); + ck.scope = "model."; + try coded.attach(&ck, try f.config(config_text), shapes); + try testing.expectEqual(@as(usize, 1), ck.coded.?.groups.items.len); + try testing.expect(ck.has("layers.0.mlp.down.weight")); + const q = try ck.get("layers.0.attn.q.weight"); + try testing.expect(q.is(.bf16, &.{ 6, 10 })); + try testing.expectEqualSlices(u8, layer.want[0..120], q.bytes); + const down = try ck.expect("layers.0.mlp.down.weight", .bf16, &.{29}); + try testing.expectEqualSlices(u8, layer.want[2 * 211 ..], down.bytes); +} + +test "a coded name with no shape, or a shape of another count, is refused by name and nothing is decoded" { + var f = try Folder.init(); + defer f.deinit(); + var ck = try Checkpoint.openModel(testing.allocator, testing.io, try f.write(null)); + defer ck.close(); + try coded.attach(&ck, try f.config(config_text), shapes); + // the family names shapes for two names; this is neither + try testing.expectError(error.CodedShapeUnknown, ck.get("model.layers.0.mlp.up.weight")); + try testing.expectError(error.UnexpectedTensor, ck.expect("model.layers.0.mlp.up.weight", .bf16, &.{ 10, 16 })); + try testing.expectError(error.UnexpectedTensor, ck.expect("lm_head.weight", .bf16, &.{ 1 << 40, 1 << 40 })); + for (ck.coded.?.groups.items) |g| try testing.expect(g.decoded == null); +} + +test "a damaged group gives the decoder's refusal and holds nothing; the other group still reads" { + var f = try Folder.init(); + defer f.deinit(); + const a = f.arena.allocator(); + const gaps = try a.dupe(u8, layer.gaps); + gaps[0] ^= 0x08; // the first thread's gap, 0, becomes 1 + f.entries.clearRetainingCapacity(); + try groupEntries(a, &f.entries, "model.layers.0", layer, gaps); + try groupEntries(a, &f.entries, "lm_head", head, null); + var ck = try Checkpoint.openModel(testing.allocator, testing.io, try f.write(null)); + defer ck.close(); + try coded.attach(&ck, try f.config(config_text), shapes); + try testing.expectError(error.GapMismatch, ck.get("model.layers.0.attn.q.weight")); + for (ck.coded.?.groups.items) |g| try testing.expect(g.decoded == null); + try testing.expectEqualSlices(u8, head.want, (try ck.get("lm_head.weight")).bytes); +} + +test "attach refuses a group it cannot answer for: unlisted, partial, miscounted, or a name stored twice" { + const head_only = "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":[4],\"pattern_dict\":{\"lm_head\":[]}}}"; + const three = "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":[4],\"pattern_dict\":" ++ + "{\"lm_head\":[],\"model.layers.\\\\d+\":[\"attn.q\",\"attn.k\",\"mlp.up\"]}}}"; + const cases = [_]struct { config: []const u8, without: ?[]const u8, extra: ?[]const u8, want: anyerror }{ + .{ .config = head_only, .without = null, .extra = null, .want = error.CodedGroupUnlisted }, + .{ .config = config_text, .without = "model.layers.0.gaps", .extra = null, .want = error.CodedGroupPartial }, + .{ .config = config_text, .without = "lm_head.split_positions", .extra = null, .want = error.CodedGroupPartial }, + .{ .config = config_text, .without = "lm_head.gaps", .extra = "lm_head.gaps", .want = error.CodedGroupPartial }, + .{ .config = three, .without = null, .extra = null, .want = error.CodedMembers }, + .{ .config = config_text, .without = null, .extra = "model.layers.0.mlp.up.weight", .want = error.CodedNameStored }, + .{ .config = config_text, .without = null, .extra = "lm_head.weight", .want = error.CodedNameStored }, + }; + for (cases) |case| { + var f = try Folder.init(); + defer f.deinit(); + // a BF16 tensor of that name: a weight stored plain as well, or a group's own tensor of another dtype + if (case.extra) |name| try f.entries.append(f.arena.allocator(), .{ .name = name, .dtype = "BF16", .shape = &.{2}, .bytes = &plain }); + var ck = try Checkpoint.openModel(testing.allocator, testing.io, try f.write(case.without)); + defer ck.close(); + try testing.expectError(case.want, coded.attach(&ck, try f.config(case.config), null)); + // refused whole: the checkpoint answers as an unattached one + try testing.expectEqual(@as(?*coded.Coded, null), ck.coded); + try testing.expectEqualSlices(u8, &plain, (try ck.get("model.norm.weight")).bytes); + } +} + +fn roundTrip(gpa: std.mem.Allocator, io: Io, dir: []const u8) !void { + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const config = (try layout.parse(arena.allocator(), config_text)).?; + var ck = try Checkpoint.openModel(gpa, io, dir); + defer ck.close(); + try coded.attach(&ck, config, shapes); + const q = try ck.get("model.layers.0.attn.q.weight"); + try testing.expectEqualSlices(u8, layer.want[0..120], q.bytes); + ck.release(); + const w = try ck.expect("lm_head.weight", .bf16, &.{1500}); + try testing.expectEqualSlices(u8, head.want, w.bytes); +} + +test "the content digest reads a coded folder: a group's empty tensor starts where the next tensor does" { + var f = try Folder.init(); + defer f.deinit(); + // the head's group has no split positions: its last tensor is empty, at the offset the norm's bytes begin + try testing.expectEqual(@as(usize, 0), head.split_positions.len); + const Content = @import("checkpoint_identity.zig").Content; + const dir = try f.write(null); + const digest = try (try Content.startWithCache(testing.allocator, testing.io, dir, false, null)).finish(); + try testing.expectEqual(digest, try (try Content.startWithCache(testing.allocator, testing.io, dir, false, null)).finish()); +} + +test "a failed allocation while groups attach, decode, drop and close leaves nothing behind" { + var f = try Folder.init(); + defer f.deinit(); + const dir = try f.write(null); + var i: usize = 0; + while (true) : (i += 1) { + var failing = testing.FailingAllocator.init(testing.allocator, .{ .fail_index = i, .resize_fail_index = 0 }); + roundTrip(failing.allocator(), testing.io, dir) catch |err| if (!failing.has_induced_failure) return err; + try testing.expectEqual(failing.allocated_bytes, failing.freed_bytes); + if (!failing.has_induced_failure) break; + } + try testing.expect(i > 8); // the walk reached past the open into the attach and the decodes +} diff --git a/zig/src/core/dfloat11.zig b/zig/src/core/dfloat11.zig new file mode 100644 index 00000000000..390b35fc068 --- /dev/null +++ b/zig/src/core/dfloat11.zig @@ -0,0 +1,468 @@ +//! DFloat11 groups: checks their tables and decodes their Huffman-coded BF16 exponents block by block. + +const std = @import("std"); + +pub const Error = error{ + LutsShape, + LutsPointer, + LutsTree, + LutsDepth, + PositionsShape, + PositionsRange, + StreamBlocks, + GapsShape, + BlockCount, + GapMismatch, + CodeLength, + CodeDepth, + StreamEnd, + SplitPositions, + UnsupportedBytesPerThread, + UnsupportedThreadsPerBlock, + OutputSize, +}; + +/// One group's stored tensors, as the bytes of the safetensors file. +pub const Group = struct { + luts: []const u8, + encoded_exponent: []const u8, + sign_mantissa: []const u8, + output_positions: []const u8, + gaps: []const u8, + bytes_per_thread: u32 = 8, + threads_per_block: u32 = 512, +}; + +const pointer = 240; // entries from here to 255 name table 256 - entry +const max_tables = 4; // tables on a path: a code has at most 32 bits +const thread_bits: u64 = 64; // the bits of a thread's chunk, n = 8 bytes + +/// Checks the group's shapes and tables (everything that can be checked without walking the stream). +pub fn check(g: Group) Error!void { + if (g.bytes_per_thread != 8) return error.UnsupportedBytesPerThread; + if (g.threads_per_block == 0) return error.UnsupportedThreadsPerBlock; + if (g.luts.len % 256 != 0 or g.luts.len < 2 * 256) return error.LutsShape; + try checkTree(g.luts); + const p = g.output_positions; + if (p.len % 4 != 0 or p.len < 8) return error.PositionsShape; + const blocks = p.len / 4 - 1; + if (position(p, 0) != 0 or position(p, blocks) != g.sign_mantissa.len) return error.PositionsRange; + for (1..blocks + 1) |b| if (position(p, b) < position(p, b - 1)) return error.PositionsRange; + const t: u64 = g.threads_per_block; + const threads = (@as(u64, g.encoded_exponent.len) + 7) / 8; + if ((threads + t - 1) / t != blocks) return error.StreamBlocks; + if (g.gaps.len != (5 * blocks * t + 7) / 8) return error.GapsShape; +} + +/// Walks the tables from table 0: each pointer names a table below k, reached once, at most four tables deep. +fn checkTree(luts: []const u8) Error!void { + const k = luts.len / 256 - 1; + var depth: [257 - pointer]u8 = @splat(0); + var queue: [257 - pointer]usize = undefined; + depth[0] = 1; + queue[0] = 0; + var queued: usize = 1; + for (0..depth.len) |i| { + if (i == queued) break; + const t = queue[i]; + for (luts[256 * t ..][0..256]) |e| { + if (e < pointer) continue; + const c = 256 - @as(usize, e); + if (c >= k) return error.LutsPointer; + if (depth[c] != 0) return error.LutsTree; + if (depth[t] == max_tables) return error.LutsDepth; + depth[c] = depth[t] + 1; + queue[queued] = c; + queued += 1; + } + } +} + +/// Decodes the whole group into out, 2 * N bytes of little-endian BF16; out is unspecified on an error. +pub fn decode(g: Group, out: []u8) Error!void { + if (out.len != 2 * g.sign_mantissa.len) return error.OutputSize; + try check(g); + for (0..g.output_positions.len / 4 - 1) |b| try decodeBlock(g, b, out); +} + +/// Decodes the codes that begin in block b's bytes, from its first gap to where the next block's first gap points. +fn decodeBlock(g: Group, b: usize, out: []u8) Error!void { + const k = g.luts.len / 256 - 1; + const lengths = g.luts[256 * k ..][0..256]; + const s = g.encoded_exponent; + const s_bits = 8 * @as(u64, s.len); + const n = g.sign_mantissa.len; + const last = b + 2 == g.output_positions.len / 4; + const first = b * @as(u64, g.threads_per_block); + const end = (first + g.threads_per_block) * thread_bits; + const stop: usize = position(g.output_positions, b + 1); + var i: usize = position(g.output_positions, b); + if (b == 0 and gap(g.gaps, 0) != 0) return error.GapMismatch; + var pos = first * thread_bits + gap(g.gaps, first); + var thread = first; // the thread whose gap the walk has met + while (pos < end) { + if (i == stop) { + if (last) break; + return error.BlockCount; + } + const at = pos / thread_bits; + if (at != thread) { + if (pos - at * thread_bits != gap(g.gaps, at)) return error.GapMismatch; + thread = at; + } + var e = g.luts[byteAt(s, pos)]; + var d: u64 = 1; + while (e >= pointer) : (d += 1) e = g.luts[256 * (256 - @as(usize, e)) + byteAt(s, pos + 8 * d)]; + const len: u64 = lengths[e]; + if (len == 0) return error.CodeLength; + if ((len + 7) / 8 != d) return error.CodeDepth; + const sm = g.sign_mantissa[i]; + const v = @as(u16, sm & 0x80) << 8 | @as(u16, e) << 7 | (sm & 0x7f); + std.mem.writeInt(u16, out[2 * i ..][0..2], v, .little); + pos += len; + i += 1; + if (i == n and (pos > s_bits or pos + 8 <= s_bits)) return error.StreamEnd; + } + if (i != stop) return error.BlockCount; + if (!last and pos != end + gap(g.gaps, first + g.threads_per_block)) return error.GapMismatch; +} + +fn position(p: []const u8, b: usize) u32 { + return std.mem.readInt(u32, p[4 * b ..][0..4], .little); +} + +/// Thread j's 5-bit gap, packed most significant bit first. +fn gap(gaps: []const u8, j: u64) u64 { + const q: usize = @intCast(5 * j / 8); + const pair = @as(u16, gaps[q]) << 8 | @as(u16, if (q + 1 < gaps.len) gaps[q + 1] else 0); + return (pair >> @intCast(11 - 5 * j % 8)) & 31; +} + +/// The 8 stream bits from bit `bit`, most significant first; bits past the stream are zero. +fn byteAt(s: []const u8, bit: u64) u8 { + const q = bit / 8; + const hi: u16 = if (q < s.len) s[@intCast(q)] else 0; + const lo: u16 = if (q + 1 < s.len) s[@intCast(q + 1)] else 0; + return @truncate((hi << 8 | lo) >> @intCast(8 - bit % 8)); +} + +/// Member j's element range [begin, end) from split_positions' bytes (little-endian i64, members - 1 of them). +pub fn member(split_positions: []const u8, members: usize, elements: usize, j: usize) Error!struct { begin: usize, end: usize } { + if (members == 0 or j >= members) return error.SplitPositions; + if (split_positions.len % 8 != 0 or split_positions.len / 8 != members - 1) return error.SplitPositions; + var begin: usize = 0; + var end: usize = 0; + var prev: usize = 0; + for (0..members) |i| { + const split = if (i + 1 == members) elements else std.math.cast( + usize, + std.mem.readInt(i64, split_positions[8 * i ..][0..8], .little), + ) orelse return error.SplitPositions; + if (split < prev) return error.SplitPositions; + if (i == j) { + begin = prev; + end = split; + } + prev = split; + } + return .{ .begin = begin, .end = end }; +} + +const Buf = struct { + luts: [6 * 256]u8 = @splat(0), + enc: [512]u8 = @splat(0), + pos: [64]u8 = @splat(0), + gaps: [384]u8 = @splat(0), + sm: [1536]u8 = @splat(0), + luts_len: usize, + enc_len: usize, + pos_len: usize, + gaps_len: usize, + sm_len: usize, + threads_per_block: u32, + bytes_per_thread: u32 = 8, + + fn init(f: anytype) Buf { + var b: Buf = .{ + .luts_len = f.luts.len, + .enc_len = f.encoded_exponent.len, + .pos_len = f.output_positions.len, + .gaps_len = f.gaps.len, + .sm_len = f.sign_mantissa.len, + .threads_per_block = f.threads_per_block, + }; + @memcpy(b.luts[0..f.luts.len], f.luts); + @memcpy(b.enc[0..f.encoded_exponent.len], f.encoded_exponent); + @memcpy(b.pos[0..f.output_positions.len], f.output_positions); + @memcpy(b.gaps[0..f.gaps.len], f.gaps); + @memcpy(b.sm[0..f.sign_mantissa.len], f.sign_mantissa); + return b; + } + + fn group(b: *const Buf) Group { + return .{ + .luts = b.luts[0..b.luts_len], + .encoded_exponent = b.enc[0..b.enc_len], + .sign_mantissa = b.sm[0..b.sm_len], + .output_positions = b.pos[0..b.pos_len], + .gaps = b.gaps[0..b.gaps_len], + .bytes_per_thread = b.bytes_per_thread, + .threads_per_block = b.threads_per_block, + }; + } + + fn bytes(b: *Buf, which: usize) []u8 { + return switch (which) { + 0 => b.luts[0..b.luts_len], + 1 => b.enc[0..b.enc_len], + 2 => b.pos[0..b.pos_len], + else => b.gaps[0..b.gaps_len], + }; + } + + fn position(b: *const Buf, i: usize) u32 { + return std.mem.readInt(u32, b.pos[4 * i ..][0..4], .little); + } + + fn setPosition(b: *Buf, i: usize, v: u32) void { + std.mem.writeInt(u32, b.pos[4 * i ..][0..4], v, .little); + } + + fn setGap(b: *Buf, j: usize, v: u5) void { + for (0..5) |i| { + const bit = 5 * j + i; + const mask = @as(u8, 0x80) >> @intCast(bit % 8); + if ((v >> @intCast(4 - i)) & 1 == 1) b.gaps[bit / 8] |= mask else b.gaps[bit / 8] &= ~mask; + } + } + + fn decoded(b: *const Buf, out: *[2 * 1536]u8) Error![]const u8 { + try decode(b.group(), out[0 .. 2 * b.sm_len]); + return out[0 .. 2 * b.sm_len]; + } + + fn refused(b: *const Buf, want: Error) !void { + var out: [2 * 1536]u8 = undefined; + try std.testing.expectError(want, b.decoded(&out)); + } +}; + +fn splitBytes(f: anytype, buf: *[64]u8) []const u8 { + for (f.split_positions, 0..) |s, i| std.mem.writeInt(i64, buf[8 * i ..][0..8], s, .little); + return buf[0 .. 8 * f.split_positions.len]; +} + +test "every fixture group passes the checks, decodes to its bytes and splits into its members" { + var out: [2 * 1536]u8 = undefined; + for (@import("dfloat11_fixtures.zig").groups) |f| { + const b = Buf.init(f); + try check(b.group()); + try std.testing.expectEqualSlices(u8, f.want, try b.decoded(&out)); + try std.testing.expectEqual(f.tables, f.luts.len / 256 - 1); + var buf: [64]u8 = undefined; + const split = splitBytes(f, &buf); + var at: usize = 0; + for (0..f.members) |j| { + const r = try member(split, f.members, f.elements, j); + try std.testing.expectEqual(at, r.begin); + if (j + 1 < f.members) try std.testing.expectEqual(f.split_positions[j], @as(i64, @intCast(r.end))); + at = r.end; + } + try std.testing.expectEqual(f.elements, at); + } +} + +test "a stream of the wrong length is refused" { + const fx = @import("dfloat11_fixtures.zig").groups; + var b = Buf.init(fx[1]); + b.enc_len -= 33; + try b.refused(error.StreamBlocks); + b = .init(fx[1]); + b.enc_len += 32; + try b.refused(error.StreamBlocks); + b = .init(fx[1]); + b.enc_len = 0; + try b.refused(error.StreamBlocks); + b = .init(fx[0]); + b.enc_len -= 1; + try b.refused(error.StreamEnd); + b = .init(fx[0]); + b.enc_len += 1; + try b.refused(error.StreamEnd); + b = .init(fx[0]); + b.sm_len = 192; + b.setPosition(1, 192); + try b.refused(error.StreamEnd); + b.enc_len = 24; + var out: [2 * 1536]u8 = undefined; + try std.testing.expectEqualSlices(u8, fx[0].want[0 .. 2 * 192], try b.decoded(&out)); +} + +test "sign_mantissa, gaps and output_positions of the wrong shape are refused" { + const fx = @import("dfloat11_fixtures.zig").groups; + var b = Buf.init(fx[1]); + b.sm_len -= 1; + try b.refused(error.PositionsRange); + b = .init(fx[1]); + b.sm_len += 1; + try b.refused(error.PositionsRange); + b = .init(fx[1]); + b.gaps_len -= 1; + try b.refused(error.GapsShape); + b = .init(fx[1]); + b.gaps_len += 1; + try b.refused(error.GapsShape); + b = .init(fx[1]); + b.pos_len -= 1; + try b.refused(error.PositionsShape); + b = .init(fx[1]); + b.pos_len -= 4; + try b.refused(error.PositionsRange); + b = .init(fx[1]); + b.pos_len = 4; + try b.refused(error.PositionsShape); +} + +test "output positions that do not count the blocks' elements are refused" { + const fx = @import("dfloat11_fixtures.zig").groups; + var b = Buf.init(fx[1]); + b.setPosition(0, 1); + try b.refused(error.PositionsRange); + b = .init(fx[1]); + b.setPosition(5, 241); + try b.refused(error.PositionsRange); + b = .init(fx[1]); + b.setPosition(2, b.position(3) + 1); + try b.refused(error.PositionsRange); + b = .init(fx[1]); + b.setPosition(1, b.position(1) + 1); + try b.refused(error.BlockCount); +} + +test "tables that are not a tree of at most four levels are refused" { + const fx = @import("dfloat11_fixtures.zig").groups; + var b = Buf.init(fx[0]); + b.luts_len = 256; + try b.refused(error.LutsShape); + b = .init(fx[0]); + b.luts_len = 513; + try b.refused(error.LutsShape); + b = .init(fx[0]); + b.luts[7] = 256 - 1; + try b.refused(error.LutsPointer); + b = .init(fx[2]); + try std.testing.expectEqual(@as(u8, 255), b.luts[255]); + b.luts[3] = 255; + try b.refused(error.LutsTree); + b = .init(fx[0]); + b.luts_len = 6 * 256; + @memset(&b.luts, 0); + for (0..4) |t| b.luts[256 * t] = @intCast(255 - t); + try b.refused(error.LutsDepth); +} + +test "elements whose code has no length, or a length that does not fit its tables, are refused" { + const fx = @import("dfloat11_fixtures.zig").groups; + var b = Buf.init(fx[0]); + b.luts[256 + 0x78] = 9; + try b.refused(error.CodeDepth); + b = .init(fx[0]); + @memset(b.luts[128..256], 0); + b.enc[3] = 0x10; + try b.refused(error.CodeLength); +} + +test "a gap that names another offset, or an unsupported n or T, is refused" { + const fx = @import("dfloat11_fixtures.zig").groups; + var b = Buf.init(fx[1]); + b.setGap(1, 2); + try b.refused(error.GapMismatch); + b = .init(fx[0]); + b.bytes_per_thread = 4; + try b.refused(error.UnsupportedBytesPerThread); + b = .init(fx[0]); + b.threads_per_block = 0; + try b.refused(error.UnsupportedThreadsPerBlock); +} + +test "split positions out of order, past N or of the wrong count are refused" { + const f = @import("dfloat11_fixtures.zig").groups[1]; + var buf: [64]u8 = undefined; + const split = splitBytes(f, &buf); + try std.testing.expectError(error.SplitPositions, member(split, 3, f.elements, 0)); + try std.testing.expectError(error.SplitPositions, member(split[0..16], 4, f.elements, 0)); + try std.testing.expectError(error.SplitPositions, member(split, 4, 210, 0)); + std.mem.writeInt(i64, buf[0..8], 62, .little); + try std.testing.expectError(error.SplitPositions, member(split, 4, f.elements, 3)); + std.mem.writeInt(i64, buf[0..8], -1, .little); + try std.testing.expectError(error.SplitPositions, member(split, 4, f.elements, 3)); +} + +test "bits after the last element are not checked, whatever entries they reach" { + const f = @import("dfloat11_fixtures.zig").groups[0]; + var out: [2 * 1536]u8 = undefined; + for ([_]u8{ 0x79, 0x00 }) |v| { + var b = Buf.init(f); + @memset(b.luts[128..256], v); + b.luts[256 + 0x79] = 20; + b.enc[24] |= 0x1f; + try std.testing.expectEqualSlices(u8, f.want, try b.decoded(&out)); + } +} + +test "random single-byte changes are refused or decoded, never anything else" { + const fx = @import("dfloat11_fixtures.zig").groups; + var prng = std.Random.DefaultPrng.init(1117); + const r = prng.random(); + var out: [2 * 1536]u8 = undefined; + var seen = [2]usize{ 0, 0 }; + for (0..4000) |_| { + var b = Buf.init(fx[r.uintLessThan(usize, fx.len)]); + const field = b.bytes(r.uintLessThan(usize, 4)); + field[r.uintLessThan(usize, field.len)] = r.int(u8); + _ = b.decoded(&out) catch { + seen[0] += 1; + continue; + }; + seen[1] += 1; + } + try std.testing.expect(seen[0] > 0 and seen[1] > 0); +} + +test "every block's first gap must continue the stream where the block before it ended" { + const fx = @import("dfloat11_fixtures.zig").groups; + var b = Buf.init(fx[0]); + b.setGap(0, 5); + try b.refused(error.GapMismatch); + for (fx) |f| { + const blocks = f.output_positions.len / 4 - 1; + if (blocks == 1) continue; + for (0..blocks) |k| { + const j = k * f.threads_per_block; + for ([_]i64{ 1, -1 }) |step| { + const v = @as(i64, @intCast(gap(f.gaps, j))) + step; + if (v < 0 or v > 31) continue; + b = .init(f); + b.setGap(j, @intCast(v)); + try b.refused(error.GapMismatch); + } + } + } +} + +test "a table no pointer names is not walked and does not change the values" { + const f = @import("dfloat11_fixtures.zig").groups[2]; + var b = Buf.init(f); + @memcpy(b.luts[768..1024], f.luts[512..768]); + for (b.luts[512..768], 0..) |*e, i| e.* = @truncate(i * 151 + 7); + b.luts_len = 1024; + var out: [2 * 1536]u8 = undefined; + try std.testing.expectEqualSlices(u8, f.want, try b.decoded(&out)); +} + +test "an output of the wrong size is refused" { + const b = Buf.init(@import("dfloat11_fixtures.zig").groups[1]); + var out: [2 * 1536]u8 = undefined; + try std.testing.expectError(error.OutputSize, decode(b.group(), out[0 .. 2 * b.sm_len + 2])); + try std.testing.expectError(error.OutputSize, decode(b.group(), out[0 .. 2 * b.sm_len - 1])); +} diff --git a/zig/src/core/dfloat11_config.zig b/zig/src/core/dfloat11_config.zig new file mode 100644 index 00000000000..ebe8b5c7f78 --- /dev/null +++ b/zig/src/core/dfloat11_config.zig @@ -0,0 +1,205 @@ +//! config.json's dfloat11_config: the coding's two sizes, and which module names are groups of which members. + +const std = @import("std"); + +/// A module-name pattern and the members whose weights its group holds, in order (none: the module's own weight). +pub const Pattern = struct { + text: []const u8, + members: []const []const u8, +}; + +pub const Config = struct { + bytes_per_thread: u32, + threads_per_block: u32, + patterns: []const Pattern, + + /// The pattern that describes the whole of `module`; null when none does, an error when two do. + pub fn group(self: Config, module: []const u8) error{AmbiguousDfloat11Pattern}!?Pattern { + var found: ?Pattern = null; + for (self.patterns) |p| { + if (!matches(p.text, module)) continue; + if (found) |first| { + if (!@import("builtin").is_test) std.log.err("dfloat11_config: {s} matches both {s} and {s}", .{ module, first.text, p.text }); + return error.AmbiguousDfloat11Pattern; + } + found = p; + } + return found; + } +}; + +/// `text`'s dfloat11_config with its strings in `arena`; null when config.json has none. +pub fn parse(arena: std.mem.Allocator, text: []const u8) !?Config { + const root = std.json.parseFromSliceLeaky(std.json.Value, arena, text, .{}) catch |err| switch (err) { + error.OutOfMemory => return err, + else => return error.BadDfloat11Config, + }; + if (root != .object) return error.BadDfloat11Config; + const value = root.object.get("dfloat11_config") orelse return null; + if (value != .object) return error.BadDfloat11Config; + const o = value.object; + const threads = o.get("threads_per_block") orelse return error.BadDfloat11Config; + // the writers seen store the number in a list of one + if (threads != .array or threads.array.items.len != 1) return error.BadDfloat11Config; + const dict = o.get("pattern_dict") orelse return error.BadDfloat11Config; + if (dict != .object) return error.BadDfloat11Config; + const patterns = try arena.alloc(Pattern, dict.object.count()); + var it = dict.object.iterator(); + for (patterns) |*p| { + const kv = it.next().?; + if (!readable(kv.key_ptr.*)) { + if (!@import("builtin").is_test) std.log.err("dfloat11_config: pattern {s} uses more than letters, digits, _ - . \\. \\d and \\d+", .{kv.key_ptr.*}); + return error.UnsupportedDfloat11Pattern; + } + if (kv.value_ptr.* != .array) return error.BadDfloat11Config; + const members = try arena.alloc([]const u8, kv.value_ptr.array.items.len); + for (members, kv.value_ptr.array.items) |*m, v| { + if (v != .string or v.string.len == 0) return error.BadDfloat11Config; + m.* = v.string; + } + p.* = .{ .text = kv.key_ptr.*, .members = members }; + } + return .{ + .bytes_per_thread = try number(o.get("bytes_per_thread")), + .threads_per_block = try number(threads.array.items[0]), + .patterns = patterns, + }; +} + +fn number(v: ?std.json.Value) error{BadDfloat11Config}!u32 { + const x = v orelse return error.BadDfloat11Config; + if (x != .integer) return error.BadDfloat11Config; + return std.math.cast(u32, x.integer) orelse error.BadDfloat11Config; +} + +/// One step of a pattern: a byte as itself, `.` for any byte, `\.` for a dot, `\d` for a digit, `\d+` for digits. +const Atom = struct { + kind: enum { byte, any, digit }, + byte: u8 = 0, + many: bool = false, + len: usize, + + fn read(p: []const u8) ?Atom { + switch (p[0]) { + '\\' => { + if (p.len < 2) return null; + if (p[1] == '.') return .{ .kind = .byte, .byte = '.', .len = 2 }; + if (p[1] != 'd') return null; + const many = p.len > 2 and p[2] == '+'; + return .{ .kind = .digit, .many = many, .len = if (many) 3 else 2 }; + }, + '.' => return .{ .kind = .any, .len = 1 }, + 'a'...'z', 'A'...'Z', '0'...'9', '_', '-' => return .{ .kind = .byte, .byte = p[0], .len = 1 }, + else => return null, + } + } + + fn takes(a: Atom, c: u8) bool { + return switch (a.kind) { + .byte => c == a.byte, + .any => true, + .digit => std.ascii.isDigit(c), + }; + } +}; + +/// Whether every step of `pattern` is one this reader takes (the published configs use no other). +fn readable(pattern: []const u8) bool { + var p = pattern; + while (p.len > 0) p = p[(Atom.read(p) orelse return false).len..]; + return true; +} + +/// Whether `name` is the whole of what `pattern` (a readable one) describes. +fn matches(pattern: []const u8, name: []const u8) bool { + if (pattern.len == 0) return name.len == 0; + const a = Atom.read(pattern).?; + var n: usize = 0; + while (n < name.len and a.takes(name[n])) { + n += 1; + if (matches(pattern[a.len..], name[n..])) return true; + if (!a.many) break; + } + return false; +} + +const testing = std.testing; + +// four published repositories' dfloat11_config objects: keys and patterns as stored, the longer member lists cut short +const published = [_][]const u8{ + \\{"dfloat11_config":{"bytes_per_thread":8,"pattern_dict":{"lm_head":[],"model.embed_tokens":[],"model.layers.\\d+": + \\["self_attn.q_proj","self_attn.k_proj","self_attn.v_proj","self_attn.o_proj","mlp.gate_proj","mlp.up_proj", + \\"mlp.down_proj"]},"threads_per_block":[512],"version":"0.2.0"}} + , + \\{"dfloat11_config":{"bytes_per_thread":8,"pattern_dict":{"transformer_blocks.\\d+":["norm1.linear","attn.to_q"], + \\"single_transformer_blocks.\\d+":["norm.linear","proj_mlp"]},"threads_per_block":[512],"version":"0.2.0"}} + , + \\{"dfloat11_config":{"bytes_per_thread":8,"pattern_dict":{"language_model.model.layers.\\d+":["self_attn.q_proj", + \\"mlp.down_proj"]},"threads_per_block":[512],"version":"0.2.0"}} + , + \\{"dfloat11_config":{"bytes_per_thread":8,"pattern_dict":{"transformer_blocks\\.\\d+":["img_mod.1","attn.to_q"]}, + \\"threads_per_block":[512],"version":"0.5.0"}} +}; + +test "the published configs read: sizes, patterns with and without an escaped dot, members in the list's order" { + var arena: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena.deinit(); + const llama = (try parse(arena.allocator(), published[0])).?; + try testing.expectEqual(@as(u32, 8), llama.bytes_per_thread); + try testing.expectEqual(@as(u32, 512), llama.threads_per_block); + try testing.expectEqual(@as(usize, 0), (try llama.group("lm_head")).?.members.len); + try testing.expectEqual(@as(usize, 0), (try llama.group("model.embed_tokens")).?.members.len); + const layer = (try llama.group("model.layers.31")).?; + try testing.expectEqual(@as(usize, 7), layer.members.len); + try testing.expectEqualStrings("self_attn.q_proj", layer.members[0]); + try testing.expectEqualStrings("mlp.down_proj", layer.members[6]); + for ([_][]const u8{ "model.layers", "model.layers.", "model.layers.3.mlp", "model.layers.x", "xmodel.layers.3", "lm_head2", "model.layerss.3" }) |name| + try testing.expectEqual(@as(?Pattern, null), try llama.group(name)); + + // the whole name: a block of the single kind is not also a block of the other kind + const flux = (try parse(arena.allocator(), published[1])).?; + try testing.expectEqualStrings("norm.linear", (try flux.group("single_transformer_blocks.7")).?.members[0]); + try testing.expectEqualStrings("norm1.linear", (try flux.group("transformer_blocks.7")).?.members[0]); + + const gemma = (try parse(arena.allocator(), published[2])).?; + try testing.expect((try gemma.group("language_model.model.layers.0")) != null); + const edit = (try parse(arena.allocator(), published[3])).?; + try testing.expect((try edit.group("transformer_blocks.59")) != null); + // an escaped dot is a dot; a bare one is any byte, as the expression says + try testing.expectEqual(@as(?Pattern, null), try edit.group("transformer_blocks_59")); + try testing.expect((try flux.group("transformer_blocks_59")) != null); +} + +test "a config without the object is null; a pattern past the readable steps, or an odd size, is refused" { + var arena: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + try testing.expectEqual(@as(?Config, null), try parse(a, "{\"model_type\":\"x\"}")); + const head = "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":[512],\"pattern_dict\":{\""; + for ([_][]const u8{ "layers.(\\\\d+)", "a|b", "x*", "x+", "layers.\\\\w+", "^lm_head$", "layers.[0-9]", "tail\\\\" }) |pattern| { + const text = try std.fmt.allocPrint(a, "{s}{s}\":[]}}}}}}", .{ head, pattern }); + try testing.expectError(error.UnsupportedDfloat11Pattern, parse(a, text)); + } + for ([_][]const u8{ + "[]", + "{\"dfloat11_config\":7}", + "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":512,\"pattern_dict\":{}}}", + "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":[512,256],\"pattern_dict\":{}}}", + "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":[512]}}", + "{\"dfloat11_config\":{\"threads_per_block\":[512],\"pattern_dict\":{}}}", + "{\"dfloat11_config\":{\"bytes_per_thread\":-8,\"threads_per_block\":[512],\"pattern_dict\":{}}}", + "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":[512],\"pattern_dict\":{\"m\":[7]}}}", + "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":[512],\"pattern_dict\":{\"m\":\"w\"}}}", + "{\"dfloat11_config\":", + }) |text| try testing.expectError(error.BadDfloat11Config, parse(a, text)); +} + +test "a module two patterns describe is an error, not the first one's" { + var arena: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena.deinit(); + const text = "{\"dfloat11_config\":{\"bytes_per_thread\":8,\"threads_per_block\":[512],\"pattern_dict\":" ++ + "{\"model.layers.\\\\d+\":[\"a\"],\"model.layers.\\\\d\\\\d\":[\"b\"]}}}"; + const c = (try parse(arena.allocator(), text)).?; + try testing.expectEqualStrings("a", (try c.group("model.layers.3")).?.members[0]); + try testing.expectError(error.AmbiguousDfloat11Pattern, c.group("model.layers.12")); +} diff --git a/zig/src/core/dfloat11_fixtures.zig b/zig/src/core/dfloat11_fixtures.zig new file mode 100644 index 00000000000..3a30d81ceeb --- /dev/null +++ b/zig/src/core/dfloat11_fixtures.zig @@ -0,0 +1,318 @@ +//! Small DFloat11 groups for the reader's tests: each was encoded and decoded back before it was written here. +pub const Group = struct { + name: []const u8, + threads_per_block: u32, + tables: usize, + elements: usize, + members: usize, + luts: []const u8, + encoded_exponent: []const u8, + sign_mantissa: []const u8, + output_positions: []const u8, + gaps: []const u8, + split_positions: []const i64, + want: []const u8, +}; + +pub const groups = [_]Group{ + .{ + .name = "one symbol, one block of 512 threads", + .threads_per_block = 512, + .tables = 1, + .elements = 195, + .members = 1, + .luts = "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + .encoded_exponent = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + .sign_mantissa = "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" ++ + "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" ++ + "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" ++ + "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" ++ + "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01", + .output_positions = "\x00\x00\x00\x00\xc3\x00\x00\x00", + .gaps = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + .split_positions = &.{}, + .want = "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c" ++ + "\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c\x01\x3c", + }, + .{ + .name = "four members over blocks of 4 threads", + .threads_per_block = 4, + .tables = 1, + .elements = 240, + .members = 4, + .luts = "\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x77\x70\x70\x70\x70\x70\x70\x70\x70" ++ + "\x70\x70\x70\x70\x70\x70\x70\x70\x75\x75\x75\x75\x75\x75\x75\x75\x75\x75\x75\x75\x75\x75\x75\x75\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x7a\x7a\x7a\x7a\x7a\x7a\x7a\x7a" ++ + "\x7a\x7a\x7a\x7a\x7a\x7a\x7a\x7a\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x7b\x6f\x6f\x6f\x6f\x6f\x6f\x6f\x6f\x71\x71\x71\x71\x71\x71\x71\x71" ++ + "\x72\x72\x72\x72\x72\x72\x72\x72\x73\x73\x73\x73\x73\x73\x73\x73\x74\x74\x74\x74\x74\x74\x74\x74\x7c\x7c\x7c\x7c\x7c\x7c\x7c\x7c\x7d\x7d\x7d\x7d\x7d\x7d\x7d\x7d" ++ + "\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x7e\x80\x80\x80\x80\x80\x80\x80\x80\x6d\x6d\x6d\x6d\x6e\x6e\x6e\x6e\x7f\x7f\x7f\x7f\x81\x81\x81\x81\x85\x85\x85\x85\x6c\x6c\x82\x82" ++ + "\x86\x86\x8d\x8d\x94\x94\x5b\x67\x69\x6b\x83\x84\x88\x8a\x8b\x91\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08" ++ + "\x00\x08\x00\x08\x07\x06\x06\x05\x04\x05\x05\x05\x05\x04\x04\x03\x04\x04\x04\x04\x05\x05\x05\x06\x05\x06\x07\x08\x08\x06\x07\x00\x08\x00\x08\x08\x00\x07\x00\x00" ++ + "\x00\x08\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + .encoded_exponent = "\xae\x33\x11\x4e\xcb\x17\x16\xbb\xad\x11\xdc\x93\x5c\xa9\xd3\x3c\x29\xab\x94\xda\xca\x2f\xd1\x7c\x32\xa1\x6e\x38\xf2\xd9\xf3\x60\xfe\xb5\x78\xe8\x7f\x44\x45\xbf" ++ + "\x46\x20\x02\xdb\xc6\xea\x03\x1f\xd0\x6c\x5d\x5b\xf1\xb4\x65\x54\x1e\x1a\xa5\xdf\x81\xd5\x4b\x33\x82\x95\xf1\xce\xa7\x0a\xef\x33\xfb\x4f\x73\x1b\xa5\x13\x67\xf9" ++ + "\x92\xa5\x74\xc3\x47\x0b\x5d\xb1\x67\x3c\xb2\x61\x5f\x3e\xc8\x4a\x8a\x9d\xc6\x0d\x8f\x2d\x77\xc2\x32\xcc\xe5\xac\xc1\xf6\x73\x88\x80\x99\x4a\x16\x23\x89\xd9\x2e" ++ + "\x4b\x29\x4a\xe3\x93\xd4\x15\xb3\x2a\xbc\xad\x7f\xfd\xc3\xda\x20\x2b\x05\x9d\x00", + .sign_mantissa = "\x1a\x55\x7c\x87\xe6\x2d\xd7\xc9\x99\x9d\x6b\xdc\xbf\x3f\xc0\x46\x5f\xd4\x8a\x53\xd7\x81\x59\x5e\xa5\x85\x56\x3f\x7f\xe9\x4f\x6b\xee\xac\xba\xfe\x1b\xce\xc6\x0b" ++ + "\x27\xa9\xd3\x67\xa7\xe1\x49\xb4\x1f\x3c\xcb\x92\x31\xfa\xf1\x40\x77\xb7\xe8\x83\xe6\x84\xba\x96\xdd\x49\x5d\x18\x21\xe8\xb4\xb9\x04\x92\x78\x75\x8c\x59\xd4\xc7" ++ + "\xac\x02\xf1\xea\xac\xfc\x7c\x2c\x18\x87\x1f\x6e\x6b\xd6\xd8\xd6\x35\x13\xeb\x7e\x70\x99\x19\x21\xa1\x67\x2d\xc4\xa7\x57\xe4\xaf\xdf\x7d\xdc\xee\x97\x26\xdd\xce" ++ + "\xa0\x2a\x45\x39\x53\x7c\x87\x53\x76\xf2\x84\xc8\xb3\x77\x44\x20\x43\x0b\xf3\xc1\xc2\x48\x0c\x70\xb1\xe0\xb6\x44\x39\xa1\x9e\xa6\x7e\xef\x96\xba\xd9\xd3\xdb\xdd" ++ + "\x6b\x91\x10\xb8\x4d\xb7\x22\xdb\xe7\xc7\x11\x92\x91\xbb\x39\xac\x98\x17\x36\x0b\x9b\x40\xf9\xdf\x72\x8a\xbe\x2c\xf6\xaf\xdf\xea\x02\x73\xa2\xc6\x26\x40\xb9\x9d" ++ + "\x9d\xaf\xe4\x81\x06\x1a\xa8\x2a\x18\x99\xb7\x02\x41\x0c\x59\x2b\x43\x49\x54\x65\xc0\x04\x17\x13\xa7\x20\xb9\x15\x92\xa1\x34\xa6\xb7\x99\x1a\xff\x9a\xa4\x24\x9b", + .output_positions = "\x00\x00\x00\x00\x38\x00\x00\x00\x6d\x00\x00\x00\xa4\x00\x00\x00\xdd\x00\x00\x00\xf0\x00\x00\x00", + .gaps = "\x00\x42\x11\x88\xa0\x00\x00\x41\x84\x03\x20\x40\x00", + .split_positions = &.{ 60, 61, 211 }, + .want = "\x9a\x39\xd5\x3e\x7c\x3f\x87\xbd\xe6\xbd\x2d\x39\x57\xb6\x49\xbc\x99\xbd\x1d\xbe\xeb\x3b\x5c\xba\x3f\xbe\x3f\x3d\x40\xbc\x46\x39\x5f\x3b\x54\xbd\x0a\xbd\x53\x38" ++ + "\x57\xbb\x01\xc0\xd9\x40\x5e\x3c\xa5\xba\x05\xb9\x56\x3f\xbf\x3f\x7f\x3c\xe9\xba\x4f\x3c\x6b\x3d\x6e\xb8\xac\xb8\xba\xbc\x7e\xba\x1b\x3c\xce\xbb\x46\xbe\x8b\x42" ++ + "\x27\x38\xa9\xb4\xd3\xbc\x67\x3c\x27\xbb\x61\xb8\x49\x37\xb4\xbb\x9f\x3f\xbc\x46\xcb\xbc\x12\xbf\xb1\x46\x7a\xba\xf1\xbb\x40\x3d\x77\x4a\x37\xc0\x68\xbe\x83\xbd" ++ + "\xe6\xc2\x84\xbb\xba\xc5\x96\xbd\xdd\xbd\xc9\x3d\x5d\x3a\x18\x45\xa1\x3b\xe8\xbe\xb4\xbd\xb9\xbb\x84\x3b\x12\xb8\xf8\x36\x75\x43\x0c\xb7\x59\x3c\xd4\xbb\xc7\xbb" ++ + "\xac\xbc\x82\x3a\xf1\xc1\xea\xbb\xac\xbc\xfc\xbe\x7c\x3e\x2c\x3c\x98\x3c\x07\xc4\x9f\x3c\x6e\x40\xeb\x3a\x56\xb8\xd8\xb9\x56\xbb\xb5\x3b\x13\x43\xeb\xbc\xfe\x39" ++ + "\x70\x38\x19\xc1\x99\x3f\xa1\x3b\xa1\xc2\xe7\x39\x2d\x38\x44\xbf\xa7\xb8\xd7\x3d\x64\xb8\xaf\xb7\x5f\xbe\xfd\x3e\xdc\xc0\x6e\xc0\x97\xb8\xa6\x3d\x5d\xbc\x4e\xbd" ++ + "\x20\xbd\xaa\x38\xc5\x3a\x39\x42\x53\x3b\xfc\x33\x87\xba\xd3\x3b\x76\x37\x72\xbb\x04\xb9\x48\xbb\xb3\xb6\x77\x3d\xc4\x35\xa0\x37\x43\x3c\x0b\x3b\xf3\xb9\x41\xc0" ++ + "\xc2\xbc\xc8\x3b\x0c\x40\xf0\x3a\xb1\xbd\x60\xbc\xb6\xb9\xc4\x36\xb9\x3e\x21\xba\x1e\xbd\xa6\xba\x7e\x3f\xef\xbc\x16\xbb\xba\xbe\x59\xbc\x53\xbd\x5b\xbf\xdd\xad" ++ + "\x6b\x3b\x11\xb8\x10\x3c\x38\xbb\x4d\x3c\x37\xbb\x22\x41\xdb\xbb\xe7\xbe\xc7\xba\x91\x3c\x92\xba\x11\xbf\xbb\xbc\x39\x3e\x2c\xbd\x98\xbe\x17\x3b\xb6\x3c\x0b\x3c" ++ + "\x9b\xb8\xc0\x3a\xf9\xb7\x5f\xc0\x72\x3f\x8a\xbd\xbe\xba\x2c\x36\x76\xbd\xaf\xba\xdf\xbd\xea\xbd\x82\x3d\xf3\x3b\x22\xbb\x46\xbf\x26\x3b\x40\x39\x39\xb8\x9d\xbe" ++ + "\x9d\xbd\xaf\xbf\xe4\xb8\x01\xba\x06\x3b\x1a\x3e\x28\xb8\x2a\x3c\x98\x37\x99\xb7\xb7\xb7\x02\x3e\xc1\x3b\x8c\x40\xd9\x3a\x2b\x40\xc3\x3d\x49\x38\x54\x3a\x65\x3f" ++ + "\xc0\xb7\x84\x39\x17\x3d\x93\x37\x27\xba\x20\x3e\xb9\xc8\x15\x37\x92\xbb\x21\xbd\x34\x3a\xa6\xbd\xb7\xbd\x99\xbb\x1a\x3c\xff\xbc\x9a\xbb\x24\xbc\xa4\x38\x1b\xb9", + }, + .{ + .name = "codes of two tables, blocks of 4 threads", + .threads_per_block = 4, + .tables = 2, + .elements = 1500, + .members = 1, + .luts = "\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64" ++ + "\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64" ++ + "\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64\x64" ++ + "\x64\x64\x64\x64\x64\x64\x64\x64\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65" ++ + "\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x65\x66\x66\x66\x66\x66\x66\x66\x66" ++ + "\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x67\x67\x67\x67\x67\x67\x67\x67\x67\x67\x67\x67\x67\x67\x67\x67" ++ + "\x68\x68\x68\x68\x68\x68\x68\x68\x69\x69\x69\x69\x6a\x6a\x6b\xff\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d" ++ + "\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d" ++ + "\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d" ++ + "\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6d\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c" ++ + "\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c" ++ + "\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6c\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e" ++ + "\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x6e\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0a\x09\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00", + .encoded_exponent = "\x33\xe3\x21\x08\x40\x16\x60\xe6\x49\x92\x1c\xd1\xe2\x33\x64\x63\x76\x7f\x1f\x38\x16\xe9\x36\x58\x20\x5e\xa1\x23\xf1\xe3\xa0\xfd\x47\x5d\x67\x39\xcb\x54\xd1\xed" ++ + "\xbc\x8e\x4c\x31\x90\xbf\xae\x36\xdc\x33\x16\x1e\x82\xc6\x5b\x1c\xf9\x78\x6f\xa4\x37\x83\xfe\x46\x08\x3a\x9e\xb5\xd7\x45\xd3\xfd\x46\x72\x59\xcc\xa5\xf0\xbb\x7f" ++ + "\xc4\x30\x56\x4e\x94\x4d\x63\x3e\x9d\x6f\x0c\x5f\xba\x85\x76\x82\x82\x72\x70\x6d\xeb\xc1\x96\x19\x32\xb8\xd0\x95\x0a\x44\xff\x94\xf1\x5b\xd4\x4a\xb2\x06\x27\x6a" ++ + "\x60\xb6\x2a\x24\xda\x90\x11\xe5\xc6\x79\x39\x3c\xa6\xea\x64\xbc\xa8\xb9\x91\xdb\x58\x0c\x20\xb5\xbb\x0b\xd3\x5d\x6e\x5a\x50\x36\xec\x53\x9d\x98\x06\x08\x20\xda" ++ + "\x46\x35\x82\xfa\x60\x26\xe0\x4a\xb9\xa2\x46\xae\xc7\xf6\x1e\x5e\xb5\xc3\x97\x5d\xbb\x2e\x74\x89\xa3\x77\x11\x1d\xf0\x0e\xe7\x34\xe7\x61\xa0\xff\x28\x1d\xf8\xb0" ++ + "\x32\xd2\x0a\x6b\xd0\x82\x50\xfb\x42\x88\xe6\xfe\x3d\x31\x1e\x40\xfb\xb0\xa7\x00\x88\xdf\x8e\x3d\xbd\x4c\xa7\xfe\x1f\x8c\xb8\x2c\xe1\x3b\x3f\x3f\x0a\x90\x3e\xa8" ++ + "\x4a\x7c\x1a\xc7\x6a\xe7\xcd\xa1\x84\x65\xb8\xa8\x8d\xf9\x7a\xbd\xd6\x7c\xd9\x49\xde\x4c\xee\x66\xd3\x90\x07\xaa\xe4\xf1\x4c\x6f\x4c\x2e\x5c\x70\xf8\x8c\x60\xec" ++ + "\x6e\xad\x7c\xba\x82\x0b\x8f\xe9\xfe\x3e\x99\xe5\xde\xd3\xe7\x5a\xf4\x8e\x4e\x84\x2d\xae\x63\xad\x98\x80\x62\x7a\xd0\x6c\x9c\x1d\x6b\x1f\x9f\xe1\xaa\x72\x84\xf7" ++ + "\x66\x6a\x17\x76\x93\x03\x7c\x6a\x59\x9e\x47\xdb\x08\xdb\x32\xd8\xc2\xe8\x5e\xb9\x3b\x4f\x33\xf5\x29\xce\x96\x09\x15\xe8\x4c\x52\x07\x47\x5f\xe8\x5a\x7b\x44\x37" ++ + "\xf2\xc3\xfa\xd0\x30\xcf\x5b\x0a\xed\x5e\x8c\x95\xf4\x3e\x84\x8d\xdf\x76\x08", + .sign_mantissa = "\x59\x35\x4b\x44\x09\x15\x1f\x4b\x5f\x63\x50\x5b\x0e\x68\x44\x58\x52\x3e\x41\x68\x56\x35\x77\x7b\x5d\x0b\x3f\x10\x54\x67\x7d\x2c\x18\x25\x55\x3e\x03\x4a\x7d\x2d" ++ + "\x6a\x1a\x17\x65\x7a\x77\x72\x45\x63\x15\x2a\x78\x51\x12\x5b\x29\x05\x1a\x74\x53\x51\x4d\x07\x61\x1b\x23\x4e\x67\x25\x0b\x11\x27\x55\x66\x2c\x1b\x6e\x35\x10\x00" ++ + "\x21\x68\x7c\x40\x44\x06\x77\x65\x6e\x49\x17\x3d\x31\x2b\x38\x1c\x7d\x7c\x47\x25\x41\x14\x2a\x4e\x24\x79\x3c\x67\x28\x16\x5c\x0f\x1a\x2f\x5c\x42\x21\x57\x42\x3c" ++ + "\x17\x72\x13\x2a\x6b\x65\x6f\x3c\x43\x65\x6a\x12\x33\x59\x4d\x25\x50\x37\x6a\x1e\x07\x24\x26\x18\x6e\x48\x2b\x61\x24\x28\x15\x2a\x08\x16\x44\x1f\x26\x48\x37\x0d" ++ + "\x16\x21\x12\x18\x32\x28\x2f\x2d\x71\x02\x78\x35\x04\x4c\x5e\x15\x0a\x5d\x3d\x0f\x57\x30\x01\x7a\x77\x5e\x05\x53\x7d\x12\x5a\x5b\x56\x56\x71\x54\x27\x08\x01\x12" ++ + "\x0b\x27\x40\x05\x03\x1a\x2c\x62\x4a\x10\x6e\x2d\x68\x7e\x39\x24\x21\x5e\x39\x32\x06\x2b\x13\x62\x52\x34\x1e\x15\x6a\x59\x5e\x33\x35\x1c\x74\x3a\x51\x72\x58\x17" ++ + "\x5d\x68\x69\x49\x79\x1c\x02\x0d\x18\x48\x16\x1b\x23\x06\x39\x08\x5e\x6d\x7a\x59\x09\x04\x2f\x4e\x64\x42\x51\x73\x48\x55\x2e\x72\x68\x6b\x61\x66\x65\x66\x58\x7c" ++ + "\x47\x10\x6e\x12\x4f\x60\x75\x72\x41\x51\x41\x14\x17\x35\x23\x01\x12\x6b\x12\x6f\x28\x72\x51\x3f\x42\x4c\x41\x51\x68\x10\x6e\x38\x17\x24\x3c\x21\x70\x5e\x08\x51" ++ + "\x77\x3a\x3e\x5c\x41\x3e\x0e\x73\x21\x7e\x52\x64\x16\x25\x27\x16\x2f\x1b\x24\x03\x18\x37\x23\x31\x65\x14\x57\x68\x53\x63\x31\x02\x32\x79\x55\x3f\x4e\x52\x4c\x4d" ++ + "\x32\x71\x20\x22\x0e\x51\x6e\x44\x2c\x69\x18\x0e\x17\x35\x36\x16\x01\x65\x2f\x36\x51\x01\x72\x5d\x36\x21\x5b\x03\x4e\x0c\x21\x45\x63\x0a\x71\x33\x4f\x72\x6f\x26" ++ + "\x0b\x49\x0c\x5e\x6a\x29\x4c\x6f\x49\x42\x2e\x66\x08\x18\x34\x72\x55\x02\x1b\x01\x46\x7d\x72\x5c\x12\x05\x68\x0a\x51\x67\x35\x27\x31\x57\x4f\x4d\x06\x39\x0b\x49" ++ + "\x42\x0c\x1b\x33\x51\x64\x6c\x3c\x55\x63\x4e\x6a\x1f\x7f\x44\x06\x06\x76\x0d\x2d\x1e\x50\x29\x71\x33\x4d\x56\x3f\x2c\x73\x66\x6c\x09\x77\x77\x7f\x32\x41\x0f\x5b" ++ + "\x6b\x2b\x06\x0e\x5a\x15\x2c\x4a\x46\x6f\x33\x0e\x3c\x61\x1b\x3b\x32\x13\x67\x6a\x39\x7d\x29\x1f\x72\x6f\x50\x32\x22\x5e\x6c\x14\x0f\x50\x3a\x1c\x4d\x2f\x32\x1b" ++ + "\x24\x16\x08\x45\x6e\x1e\x14\x62\x0c\x0c\x7a\x18\x0a\x24\x2b\x06\x14\x08\x52\x04\x34\x01\x3c\x21\x2b\x7c\x7b\x7c\x1d\x11\x02\x34\x6a\x2d\x1c\x72\x56\x6b\x56\x0b" ++ + "\x4a\x43\x5e\x23\x57\x60\x5b\x71\x79\x3a\x34\x35\x03\x68\x40\x72\x49\x1b\x05\x77\x49\x7b\x48\x33\x25\x21\x1d\x5f\x21\x75\x72\x5f\x54\x45\x2e\x09\x12\x75\x19\x3b" ++ + "\x03\x46\x3c\x4a\x57\x11\x1c\x52\x24\x2d\x57\x0b\x27\x79\x79\x3c\x11\x67\x55\x22\x63\x15\x26\x6e\x78\x7b\x6c\x69\x71\x6f\x26\x22\x08\x00\x4b\x2a\x1a\x70\x3e\x1b" ++ + "\x25\x32\x38\x08\x03\x34\x35\x6f\x5b\x11\x2e\x36\x1f\x63\x34\x71\x36\x29\x3c\x32\x30\x49\x1e\x5e\x48\x28\x06\x2e\x7f\x37\x42\x0a\x6f\x0b\x03\x01\x20\x27\x2e\x72" ++ + "\x30\x3b\x0f\x17\x45\x1a\x52\x68\x34\x2b\x1c\x2a\x67\x4c\x6e\x2a\x67\x2b\x61\x51\x7b\x06\x02\x07\x09\x6d\x33\x3b\x70\x40\x42\x2e\x50\x27\x08\x1d\x16\x56\x18\x03" ++ + "\x11\x4b\x18\x54\x75\x38\x31\x2b\x7c\x57\x33\x36\x1d\x3a\x16\x22\x0a\x3b\x1e\x26\x3d\x5d\x0b\x36\x4d\x64\x06\x41\x4a\x6c\x07\x5f\x4a\x21\x09\x17\x56\x0b\x7f\x28" ++ + "\x51\x2b\x35\x62\x02\x1f\x21\x36\x04\x1a\x52\x09\x4d\x33\x23\x02\x45\x00\x03\x76\x09\x09\x33\x31\x18\x0a\x0e\x49\x2c\x04\x18\x67\x0a\x78\x1a\x49\x45\x5c\x13\x7d" ++ + "\x77\x66\x5b\x76\x39\x5f\x6e\x10\x37\x5e\x02\x1f\x33\x28\x55\x7d\x1b\x41\x29\x0d\x13\x5b\x57\x7f\x0c\x1a\x41\x71\x79\x20\x46\x5d\x1f\x22\x53\x20\x25\x0d\x62\x54" ++ + "\x5c\x00\x7c\x46\x2d\x23\x67\x17\x68\x3c\x66\x44\x02\x08\x70\x71\x3f\x73\x05\x55\x57\x71\x77\x6f\x11\x2c\x5b\x38\x21\x51\x2f\x22\x64\x79\x08\x50\x7a\x76\x27\x4e" ++ + "\x70\x0d\x21\x45\x23\x0f\x21\x2e\x12\x64\x30\x19\x4d\x50\x55\x77\x5f\x12\x37\x01\x77\x5f\x7d\x2e\x3f\x0d\x1a\x35\x1b\x7c\x51\x63\x67\x11\x18\x13\x1d\x6f\x33\x5e" ++ + "\x0c\x59\x11\x05\x32\x57\x1c\x62\x63\x3e\x4e\x3f\x3c\x15\x33\x4f\x33\x27\x10\x55\x43\x15\x39\x1b\x2d\x0b\x46\x52\x69\x19\x20\x39\x43\x7d\x4a\x05\x19\x6e\x02\x65" ++ + "\x59\x55\x45\x6e\x47\x6c\x30\x60\x66\x22\x22\x01\x13\x53\x3b\x60\x68\x0f\x40\x3b\x79\x08\x42\x7c\x3d\x31\x01\x4d\x5d\x2b\x70\x16\x44\x68\x0f\x58\x2c\x62\x2f\x00" ++ + "\x7c\x4a\x00\x7a\x6a\x3c\x4d\x7d\x39\x07\x33\x3e\x5c\x21\x59\x31\x73\x02\x77\x52\x2e\x3f\x15\x5b\x63\x1e\x06\x17\x05\x2f\x3f\x61\x55\x52\x34\x08\x58\x10\x62\x78" ++ + "\x48\x0e\x06\x66\x50\x78\x06\x51\x72\x42\x37\x29\x2d\x75\x77\x31\x7d\x41\x22\x50\x03\x1d\x58\x5e\x5b\x40\x1f\x1f\x69\x6b\x54\x50\x55\x4c\x35\x4f\x27\x33\x29\x50" ++ + "\x48\x57\x25\x5e\x6b\x69\x55\x0f\x3b\x36\x48\x2d\x0d\x13\x61\x39\x34\x71\x5c\x79\x63\x32\x27\x16\x5b\x30\x5e\x7c\x2d\x5e\x5f\x02\x49\x34\x13\x3a\x4e\x42\x25\x0b" ++ + "\x7a\x4b\x32\x4c\x0e\x50\x0d\x1b\x5f\x61\x36\x13\x78\x6a\x0a\x77\x3f\x57\x03\x69\x1f\x53\x0c\x46\x29\x08\x6e\x10\x31\x29\x5e\x2a\x22\x6e\x5f\x3f\x50\x31\x07\x0a" ++ + "\x17\x32\x4d\x5a\x3c\x7c\x21\x19\x6f\x68\x55\x20\x1b\x49\x4b\x49\x4c\x23\x45\x7e\x1e\x45\x19\x46\x3b\x03\x4e\x59\x25\x14\x71\x2f\x48\x65\x2a\x60\x62\x6b\x70\x47" ++ + "\x0a\x0c\x26\x3d\x73\x68\x2f\x59\x7c\x0f\x12\x19\x64\x35\x6e\x29\x0f\x71\x77\x3d\x7a\x40\x22\x64\x4d\x5e\x64\x4e\x13\x22\x19\x02\x56\x58\x36\x3f\x18\x41\x70\x72" ++ + "\x07\x18\x1d\x26\x31\x1f\x28\x00\x13\x25\x4d\x5f\x3d\x01\x43\x7f\x3d\x5b\x0b\x0a\x6c\x11\x6b\x22\x4c\x69\x13\x49\x1f\x35\x71\x39\x38\x70\x11\x06\x60\x69\x05\x28" ++ + "\x34\x66\x41\x4d\x11\x52\x00\x23\x1c\x6f\x2d\x51\x5f\x24\x55\x05\x00\x0a\x37\x65\x3d\x4f\x57\x2e\x67\x73\x22\x09\x26\x5d\x7f\x7f\x16\x54\x01\x15\x5c\x55\x34\x53" ++ + "\x53\x25\x64\x6a\x39\x36\x2a\x3c\x77\x78\x4f\x3f\x35\x5e\x1e\x34\x0c\x40\x2b\x33\x4f\x29\x2d\x20\x4a\x3f\x32\x4e\x35\x5c\x03\x7a\x22\x69\x38\x30\x16\x67\x09\x24" ++ + "\x5a\x69\x64\x3a\x3b\x79\x52\x3b\x5c\x69\x2c\x4f\x1e\x74\x0d\x41\x7b\x05\x0c\x37\x1b\x00\x6a\x3f\x54\x52\x61\x1f\x1d\x4a\x1b\x79\x4e\x3b\x34\x33\x22\x49\x60\x69" ++ + "\x1f\x27\x75\x26\x3d\x1e\x2b\x62\x62\x09\x09\x72\x03\x64\x07\x24\x08\x78\x37\x7c\x3f\x55\x10\x06\x0a\x75\x20\x14\x47\x49\x7d\x64\x2c\x05\x2c\x7e\x75\x39\x6e\x38" ++ + "\x30\x13\x5c\x2f\x46\x6d\x3d\x70\x3a\x4b\x7d\x5b\x37\x4d\x47\x4c\x17\x42\x5b\x39\x2a\x2e\x19\x5c\x41\x40\x38\x58\x75\x46\x07\x0a\x34\x43\x4f\x7f\x14\x57\x1d\x62" ++ + "\x61\x53\x3f\x35\x10\x35\x76\x4f\x53\x32\x54\x4e\x07\x4b\x5f\x0f\x59\x6c\x0c\x58", + .output_positions = "\x00\x00\x00\x00\x8c\x00\x00\x00\x03\x01\x00\x00\x7c\x01\x00\x00\x09\x02\x00\x00\x8e\x02\x00\x00\x0c\x03\x00\x00\x92\x03\x00\x00\x0a\x04\x00\x00\x85\x04\x00\x00" ++ + "\xfa\x04\x00\x00\x78\x05\x00\x00\xdc\x05\x00\x00", + .gaps = "\x00\x02\x00\x88\x00\x00\x46\x00\x04\x00\x18\x04\x00\x00\x02\x00\x02\x01\x00\x02\x18\x02\x04\x00\x41\x08\x00\x10\x14\x03", + .split_positions = &.{}, + .want = "\x59\x32\x35\x32\x4b\x33\x44\x32\x89\x34\x15\x32\x1f\x32\x4b\x33\x5f\x32\xe3\x32\x50\x32\x5b\x32\x0e\x32\xe8\x32\x44\x32\x58\x32\x52\x32\xbe\x32\x41\x32\x68\x32" ++ + "\x56\x32\xb5\x32\x77\x32\x7b\x32\x5d\x32\x0b\x32\x3f\x32\x10\x32\x54\x32\x67\x32\xfd\x32\x2c\x33\x18\x32\x25\x33\x55\x32\x3e\x32\x03\x32\x4a\x32\xfd\x33\x2d\x32" ++ + "\x6a\x33\x1a\x32\x97\x32\x65\x32\xfa\x32\x77\x32\x72\x33\x45\x32\xe3\x32\x15\x32\xaa\x32\x78\x32\x51\x32\x12\x32\xdb\x33\x29\x32\x05\x33\x9a\x32\x74\x32\x53\x32" ++ + "\x51\x34\x4d\x32\x07\x32\xe1\x32\x1b\x32\x23\x32\x4e\x33\x67\x32\x25\x33\x0b\x33\x11\x32\xa7\x32\x55\x32\x66\x32\x2c\x33\x1b\x32\x6e\x32\x35\x33\x90\x33\x00\x33" ++ + "\x21\x32\xe8\x35\x7c\x32\x40\x32\xc4\x34\x06\x32\xf7\x33\x65\x32\x6e\x32\x49\x32\x17\x32\x3d\x32\xb1\x32\x2b\x33\xb8\x33\x9c\x32\x7d\x32\xfc\x32\x47\x32\x25\x33" ++ + "\x41\x33\x14\x32\xaa\x32\x4e\x33\x24\x32\x79\x32\x3c\x32\x67\x32\xa8\x32\x16\x32\x5c\x32\x0f\x32\x1a\x32\x2f\x32\xdc\x32\x42\x34\xa1\x32\xd7\x32\x42\x32\x3c\x32" ++ + "\x17\x32\xf2\x32\x13\x32\xaa\x32\x6b\x32\x65\x32\x6f\x35\x3c\x32\x43\x32\x65\x34\x6a\x32\x12\x32\xb3\x33\xd9\x32\x4d\x32\x25\x32\x50\x32\x37\x32\x6a\x35\x9e\x32" ++ + "\x87\x32\x24\x32\x26\x32\x98\x33\xee\x32\xc8\x33\xab\x32\x61\x33\x24\x32\xa8\x33\x15\x32\xaa\x33\x08\x32\x96\x33\x44\x32\x9f\x32\x26\x33\xc8\x32\xb7\x32\x8d\x32" ++ + "\x16\x32\x21\x33\x92\x32\x18\x32\x32\x32\x28\x34\x2f\x33\x2d\x33\x71\x34\x02\x32\xf8\x32\x35\x32\x04\x32\xcc\x33\x5e\x32\x95\x32\x0a\x32\x5d\x33\x3d\x32\x0f\x32" ++ + "\x57\x32\x30\x33\x01\x32\x7a\x32\x77\x33\x5e\x32\x85\x32\x53\x32\x7d\x32\x12\x32\xda\x32\xdb\x35\xd6\x32\xd6\x33\x71\x32\x54\x32\x27\x33\x08\x33\x01\x33\x92\x33" ++ + "\x0b\x32\x27\x32\x40\x32\x05\x33\x03\x32\x1a\x33\x2c\x32\x62\x32\xca\x32\x10\x33\x6e\x32\x2d\x32\x68\x32\x7e\x34\xb9\x32\x24\x32\x21\x32\x5e\x32\x39\x32\xb2\x32" ++ + "\x06\x33\x2b\x32\x13\x32\x62\x33\x52\x32\xb4\x32\x1e\x33\x15\x33\x6a\x32\x59\x32\xde\x33\x33\x32\xb5\x34\x1c\x32\xf4\x32\x3a\x34\x51\x32\x72\x32\x58\x32\x17\x33" ++ + "\xdd\x34\xe8\x32\x69\x32\xc9\x32\x79\x32\x1c\x32\x02\x32\x0d\x33\x18\x34\x48\x32\x16\x32\x1b\x32\x23\x32\x06\x36\x39\x32\x88\x32\x5e\x32\x6d\x32\x7a\x33\x59\x32" ++ + "\x09\x32\x04\x32\x2f\x32\xce\x32\x64\x32\x42\x32\x51\x32\x73\x32\xc8\x33\xd5\x32\xae\x32\x72\x32\x68\x34\xeb\x32\x61\x33\xe6\x32\xe5\x33\xe6\x32\xd8\x33\xfc\x32" ++ + "\x47\x32\x10\x32\xee\x32\x92\x33\xcf\x32\x60\x32\xf5\x36\xf2\x32\xc1\x32\x51\x32\x41\x32\x14\x33\x17\x32\xb5\x33\x23\x32\x81\x32\x12\x32\xeb\x32\x12\x33\x6f\x32" ++ + "\xa8\x33\x72\x32\x51\x33\x3f\x32\xc2\x32\xcc\x32\x41\x32\xd1\x32\xe8\x34\x10\x32\x6e\x32\x38\x32\x97\x32\xa4\x33\x3c\x33\x21\x36\x70\x32\x5e\x32\x88\x32\x51\x32" ++ + "\x77\x32\x3a\x32\x3e\x33\x5c\x32\x41\x32\x3e\x32\x0e\x32\xf3\x32\xa1\x32\x7e\x33\x52\x32\xe4\x32\x16\x32\xa5\x33\xa7\x32\x16\x32\xaf\x32\x9b\x32\x24\x32\x03\x32" ++ + "\x98\x32\x37\x32\x23\x33\xb1\x32\x65\x33\x14\x32\x57\x32\x68\x33\x53\x32\xe3\x34\xb1\x32\x02\x32\xb2\x33\xf9\x32\x55\x33\x3f\x34\x4e\x32\x52\x32\x4c\x32\x4d\x33" ++ + "\x32\x32\x71\x32\xa0\x32\x22\x35\x8e\x33\xd1\x32\xee\x32\x44\x32\x2c\x32\x69\x32\x98\x32\x8e\x32\x97\x33\x35\x33\xb6\x32\x16\x32\x01\x32\x65\x32\x2f\x32\xb6\x32" ++ + "\xd1\x32\x01\x32\x72\x32\x5d\x32\x36\x32\xa1\x32\x5b\x32\x83\x33\x4e\x32\x8c\x32\x21\x32\xc5\x33\x63\x32\x0a\x32\x71\x32\x33\x32\x4f\x33\x72\x33\x6f\x34\xa6\x32" ++ + "\x0b\x34\x49\x32\x0c\x32\x5e\x32\x6a\x32\x29\x33\x4c\x32\xef\x32\x49\x33\x42\x32\x2e\x32\x66\x32\x08\x33\x18\x32\xb4\x32\x72\x32\x55\x33\x02\x32\x9b\x32\x81\x32" ++ + "\xc6\x33\x7d\x32\x72\x32\x5c\x33\x92\x32\x05\x32\x68\x32\x0a\x32\xd1\x32\x67\x32\xb5\x32\xa7\x32\xb1\x32\x57\x32\x4f\x32\x4d\x32\x86\x32\xb9\x32\x0b\x32\xc9\x32" ++ + "\x42\x32\x0c\x32\x9b\x32\x33\x32\x51\x36\x64\x32\xec\x32\xbc\x32\x55\x32\x63\x34\x4e\x32\x6a\x32\x9f\x32\xff\x32\x44\x33\x06\x34\x86\x32\xf6\x32\x0d\x32\x2d\x32" ++ + "\x9e\x32\x50\x32\xa9\x32\xf1\x32\xb3\x32\x4d\x33\x56\x32\xbf\x32\x2c\x32\x73\x32\x66\x32\x6c\x32\x09\x32\x77\x33\x77\x32\x7f\x32\xb2\x32\x41\x32\x8f\x33\x5b\x33" ++ + "\xeb\x32\xab\x32\x06\x32\x0e\x33\x5a\x32\x15\x32\x2c\x32\x4a\x32\xc6\x32\x6f\x33\x33\x33\x0e\x32\x3c\x32\xe1\x32\x9b\x32\xbb\x32\x32\x32\x13\x32\xe7\x32\x6a\x32" ++ + "\xb9\x32\x7d\x32\x29\x33\x1f\x33\xf2\x32\xef\x32\x50\x32\xb2\x32\x22\x32\x5e\x32\x6c\x32\x14\x32\x0f\x32\x50\x32\xba\x32\x1c\x32\x4d\x32\x2f\x34\x32\x32\x9b\x32" ++ + "\xa4\x33\x16\x32\x08\x32\x45\x33\x6e\x32\x1e\x34\x14\x32\xe2\x32\x0c\x32\x8c\x33\x7a\x32\x98\x32\x0a\x32\x24\x34\x2b\x32\x86\x32\x94\x32\x08\x32\x52\x33\x84\x33" ++ + "\xb4\x32\x81\x32\x3c\x32\x21\x33\x2b\x32\xfc\x32\x7b\x32\xfc\x32\x1d\x34\x11\x32\x82\x32\xb4\x32\xea\x32\x2d\x32\x1c\x32\xf2\x32\xd6\x33\x6b\x32\x56\x33\x0b\x32" ++ + "\xca\x32\x43\x32\x5e\x32\xa3\x33\x57\x33\x60\x33\xdb\x32\x71\x33\x79\x32\x3a\x32\x34\x32\x35\x32\x03\x32\x68\x32\x40\x33\x72\x32\x49\x32\x1b\x32\x85\x32\x77\x32" ++ + "\x49\x32\x7b\x32\x48\x32\xb3\x32\x25\x33\xa1\x32\x1d\x33\xdf\x33\x21\x33\x75\x32\x72\x32\x5f\x32\xd4\x32\x45\x34\xae\x32\x09\x32\x12\x33\xf5\x32\x99\x33\xbb\x32" ++ + "\x03\x33\xc6\x33\x3c\x32\xca\x32\x57\x33\x91\x32\x1c\x32\xd2\x32\xa4\x32\x2d\x32\x57\x32\x0b\x32\x27\x32\x79\x32\x79\x33\x3c\x33\x91\x33\x67\x33\x55\x32\x22\x32" ++ + "\xe3\x32\x95\x32\x26\x32\xee\x33\x78\x32\xfb\x33\x6c\x33\x69\x32\x71\x33\x6f\x32\x26\x32\x22\x32\x08\x32\x00\x32\x4b\x32\x2a\x32\x1a\x33\x70\x32\x3e\x32\x1b\x32" ++ + "\x25\x32\xb2\x32\x38\x32\x08\x32\x03\x32\x34\x32\xb5\x32\x6f\x32\x5b\x32\x11\x32\x2e\x32\x36\x33\x1f\x33\xe3\x32\x34\x32\xf1\x32\x36\x32\x29\x32\x3c\x33\x32\x32" ++ + "\x30\x32\x49\x33\x9e\x32\x5e\x33\x48\x32\x28\x32\x06\x32\x2e\x32\xff\x32\xb7\x34\xc2\x32\x0a\x32\x6f\x33\x0b\x32\x03\x32\x01\x32\x20\x32\x27\x32\x2e\x32\xf2\x32" ++ + "\x30\x32\x3b\x33\x8f\x33\x17\x32\x45\x32\x1a\x32\x52\x32\x68\x32\xb4\x32\x2b\x32\x9c\x32\xaa\x32\xe7\x32\xcc\x33\x6e\x32\x2a\x33\xe7\x32\x2b\x32\x61\x32\xd1\x32" ++ + "\x7b\x32\x86\x32\x02\x32\x07\x32\x09\x33\xed\x32\xb3\x32\xbb\x33\x70\x33\x40\x32\x42\x32\xae\x35\x50\x33\x27\x32\x08\x32\x1d\x32\x16\x34\x56\x32\x98\x32\x03\x34" ++ + "\x91\x32\x4b\x33\x98\x32\xd4\x33\x75\x32\x38\x32\x31\x32\xab\x33\x7c\x32\xd7\x32\xb3\x33\xb6\x32\x9d\x33\x3a\x33\x96\x33\x22\x33\x0a\x32\xbb\x32\x9e\x33\x26\x32" ++ + "\xbd\x33\xdd\x32\x0b\x32\xb6\x32\x4d\x32\x64\x32\x86\x32\x41\x32\x4a\x33\xec\x32\x07\x32\x5f\x32\x4a\x33\xa1\x33\x89\x33\x17\x32\x56\x32\x8b\x32\x7f\x32\x28\x32" ++ + "\xd1\x32\x2b\x32\x35\x32\xe2\x33\x82\x34\x1f\x32\x21\x32\x36\x32\x04\x32\x1a\x32\x52\x32\x09\x32\xcd\x33\xb3\x33\x23\x32\x82\x33\x45\x32\x00\x33\x83\x32\x76\x32" ++ + "\x89\x33\x09\x32\xb3\x33\x31\x33\x18\x32\x0a\x32\x0e\x32\x49\x33\xac\x32\x04\x32\x18\x32\x67\x32\x0a\x32\xf8\x36\x1a\x32\xc9\x32\xc5\x32\x5c\x32\x13\x32\x7d\x32" ++ + "\x77\x32\x66\x32\xdb\x33\x76\x35\x39\x32\x5f\x32\xee\x32\x10\x33\x37\x32\x5e\x32\x02\x32\x1f\x32\x33\x32\x28\x33\x55\x32\xfd\x32\x1b\x33\xc1\x32\x29\x32\x8d\x32" ++ + "\x13\x32\x5b\x32\x57\x32\x7f\x32\x8c\x32\x9a\x32\x41\x32\x71\x33\xf9\x32\x20\x34\xc6\x32\x5d\x32\x1f\x32\x22\x32\xd3\x32\x20\x32\x25\x32\x0d\x32\x62\x32\xd4\x32" ++ + "\x5c\x32\x80\x32\xfc\x32\x46\x32\x2d\x32\x23\x32\xe7\x34\x17\x33\xe8\x32\x3c\x32\x66\x32\x44\x32\x82\x32\x88\x32\x70\x32\x71\x32\xbf\x32\x73\x32\x05\x32\xd5\x33" ++ + "\x57\x32\x71\x33\xf7\x35\x6f\x32\x11\x32\x2c\x34\xdb\x32\x38\x32\x21\x33\x51\x32\x2f\x32\xa2\x32\x64\x32\x79\x32\x08\x34\x50\x32\xfa\x32\x76\x32\x27\x32\x4e\x32" ++ + "\x70\x32\x0d\x32\xa1\x34\xc5\x33\x23\x33\x0f\x32\x21\x32\x2e\x32\x92\x32\xe4\x32\x30\x32\x99\x33\x4d\x32\x50\x32\x55\x32\x77\x32\x5f\x32\x12\x32\x37\x32\x81\x32" ++ + "\x77\x32\x5f\x32\xfd\x32\x2e\x32\x3f\x32\x0d\x33\x1a\x35\x35\x32\x1b\x32\xfc\x33\x51\x32\x63\x32\x67\x34\x11\x33\x18\x34\x93\x32\x9d\x32\x6f\x32\x33\x33\x5e\x32" ++ + "\x8c\x32\xd9\x32\x11\x32\x05\x37\x32\x32\x57\x32\x1c\x32\x62\x32\x63\x35\x3e\x32\x4e\x32\x3f\x33\x3c\x32\x95\x32\xb3\x33\x4f\x32\x33\x32\x27\x32\x10\x32\xd5\x32" ++ + "\x43\x33\x15\x32\xb9\x33\x1b\x32\x2d\x32\x0b\x32\xc6\x32\x52\x32\xe9\x33\x19\x33\x20\x32\x39\x35\x43\x32\x7d\x35\x4a\x32\x05\x32\x19\x32\xee\x32\x82\x32\xe5\x32" ++ + "\x59\x32\xd5\x32\x45\x32\x6e\x32\x47\x32\x6c\x32\x30\x32\xe0\x34\xe6\x32\xa2\x32\xa2\x32\x01\x32\x13\x32\x53\x32\xbb\x32\x60\x32\xe8\x32\x8f\x32\x40\x32\xbb\x34" ++ + "\x79\x32\x08\x32\x42\x32\x7c\x32\x3d\x33\xb1\x32\x01\x33\x4d\x32\x5d\x32\xab\x33\x70\x33\x96\x32\xc4\x32\xe8\x33\x0f\x32\xd8\x34\x2c\x32\x62\x33\x2f\x33\x80\x32" ++ + "\x7c\x32\x4a\x32\x00\x32\x7a\x33\x6a\x32\x3c\x32\x4d\x32\xfd\x32\x39\x32\x07\x32\x33\x33\x3e\x32\xdc\x32\x21\x33\xd9\x33\x31\x32\x73\x32\x82\x32\xf7\x32\xd2\x32" ++ + "\x2e\x32\x3f\x32\x95\x32\x5b\x32\x63\x32\x1e\x33\x06\x35\x17\x32\x85\x32\x2f\x34\xbf\x32\xe1\x32\x55\x34\xd2\x33\xb4\x32\x08\x33\x58\x32\x90\x34\x62\x32\x78\x33" ++ + "\x48\x33\x0e\x32\x86\x32\xe6\x32\x50\x32\xf8\x32\x06\x32\xd1\x33\x72\x34\x42\x32\xb7\x32\x29\x32\x2d\x33\x75\x32\xf7\x33\xb1\x33\x7d\x32\x41\x33\x22\x32\x50\x33" ++ + "\x03\x33\x9d\x32\x58\x32\xde\x33\x5b\x32\xc0\x32\x1f\x32\x1f\x32\x69\x32\x6b\x32\x54\x32\x50\x32\x55\x32\x4c\x32\x35\x34\xcf\x32\xa7\x32\xb3\x32\xa9\x33\x50\x32" ++ + "\xc8\x32\x57\x32\x25\x34\x5e\x32\x6b\x32\xe9\x32\xd5\x32\x0f\x32\x3b\x33\x36\x32\x48\x32\x2d\x33\x0d\x34\x93\x32\x61\x32\x39\x33\x34\x32\x71\x32\x5c\x32\xf9\x32" ++ + "\xe3\x33\x32\x32\xa7\x32\x96\x33\x5b\x32\x30\x32\xde\x33\x7c\x32\x2d\x32\x5e\x32\xdf\x34\x02\x32\x49\x32\xb4\x32\x13\x32\x3a\x32\x4e\x33\x42\x32\x25\x32\x0b\x33" ++ + "\x7a\x32\x4b\x32\x32\x32\x4c\x32\x8e\x33\x50\x33\x0d\x32\x1b\x32\x5f\x33\xe1\x33\xb6\x32\x93\x32\x78\x33\xea\x32\x8a\x34\x77\x32\xbf\x32\xd7\x33\x83\x32\xe9\x32" ++ + "\x1f\x32\x53\x32\x0c\x32\x46\x32\xa9\x32\x08\x32\x6e\x32\x10\x32\x31\x32\xa9\x32\xde\x33\x2a\x32\x22\x32\xee\x35\xdf\x32\x3f\x32\xd0\x36\x31\x32\x07\x32\x8a\x34" ++ + "\x97\x32\x32\x32\x4d\x33\x5a\x32\x3c\x34\x7c\x32\xa1\x32\x99\x33\x6f\x34\x68\x33\xd5\x32\x20\x32\x9b\x34\x49\x32\xcb\x33\xc9\x32\x4c\x33\xa3\x32\x45\x34\xfe\x32" ++ + "\x1e\x32\xc5\x32\x19\x32\x46\x32\xbb\x33\x03\x32\xce\x32\x59\x32\xa5\x33\x94\x32\x71\x32\x2f\x32\x48\x32\xe5\x32\x2a\x32\x60\x32\x62\x32\xeb\x32\x70\x33\x47\x33" ++ + "\x8a\x32\x8c\x33\x26\x32\x3d\x33\x73\x32\x68\x32\xaf\x33\xd9\x32\x7c\x33\x0f\x33\x12\x32\x19\x33\x64\x32\x35\x32\xee\x32\x29\x32\x0f\x32\x71\x32\x77\x32\x3d\x32" ++ + "\x7a\x32\x40\x32\x22\x33\x64\x32\x4d\x32\xde\x32\x64\x32\x4e\x34\x93\x32\x22\x33\x99\x32\x02\x32\x56\x32\x58\x32\x36\x32\x3f\x33\x18\x33\x41\x32\xf0\x32\x72\x32" ++ + "\x87\x33\x18\x32\x1d\x32\x26\x32\x31\x32\x9f\x33\xa8\x32\x00\x33\x93\x32\x25\x33\x4d\x32\x5f\x32\x3d\x35\x01\x32\xc3\x36\x7f\x32\x3d\x32\x5b\x32\x0b\x33\x8a\x32" ++ + "\xec\x32\x91\x32\x6b\x32\xa2\x33\x4c\x32\xe9\x32\x93\x32\x49\x32\x1f\x32\x35\x32\xf1\x32\x39\x32\x38\x34\xf0\x33\x11\x33\x06\x32\x60\x33\x69\x32\x05\x33\xa8\x32" ++ + "\xb4\x32\x66\x32\x41\x32\x4d\x32\x91\x32\xd2\x33\x80\x33\x23\x33\x9c\x32\x6f\x32\xad\x32\x51\x32\x5f\x33\x24\x32\x55\x32\x05\x32\x00\x32\x0a\x32\x37\x33\xe5\x34" ++ + "\x3d\x32\x4f\x32\x57\x33\xae\x32\xe7\x32\x73\x32\xa2\x32\x09\x33\x26\x32\x5d\x33\x7f\x32\x7f\x34\x16\x32\xd4\x32\x01\x32\x15\x32\xdc\x34\x55\x33\x34\x33\x53\x32" ++ + "\x53\x32\x25\x32\xe4\x32\x6a\x32\x39\x32\x36\x33\x2a\x33\x3c\x33\x77\x32\x78\x33\x4f\x32\xbf\x32\x35\x33\x5e\x33\x1e\x32\x34\x32\x0c\x33\x40\x32\x2b\x32\x33\x32" ++ + "\xcf\x32\xa9\x33\xad\x32\x20\x32\x4a\x32\x3f\x32\xb2\x32\x4e\x34\xb5\x32\xdc\x33\x03\x32\xfa\x32\x22\x32\xe9\x33\x38\x33\xb0\x32\x16\x32\x67\x34\x09\x32\x24\x33" ++ + "\x5a\x32\x69\x35\xe4\x32\xba\x32\x3b\x32\xf9\x32\xd2\x32\x3b\x32\xdc\x33\x69\x32\xac\x33\xcf\x32\x1e\x32\xf4\x32\x0d\x33\x41\x32\x7b\x32\x05\x32\x0c\x32\xb7\x32" ++ + "\x1b\x32\x80\x32\x6a\x32\x3f\x32\xd4\x32\xd2\x32\x61\x34\x9f\x32\x1d\x32\x4a\x32\x1b\x32\xf9\x32\x4e\x32\x3b\x33\x34\x32\x33\x32\xa2\x32\xc9\x32\x60\x32\xe9\x32" ++ + "\x1f\x32\x27\x32\x75\x32\x26\x32\x3d\x32\x9e\x33\xab\x32\x62\x32\x62\x32\x89\x33\x89\x32\xf2\x36\x83\x32\x64\x32\x07\x32\x24\x32\x88\x32\x78\x33\xb7\x32\x7c\x32" ++ + "\x3f\x34\x55\x33\x90\x32\x06\x32\x0a\x32\xf5\x32\x20\x32\x14\x32\x47\x32\x49\x33\xfd\x35\x64\x32\xac\x32\x05\x33\x2c\x32\x7e\x32\x75\x32\xb9\x35\xee\x32\x38\x33" ++ + "\xb0\x32\x13\x32\x5c\x32\x2f\x32\x46\x32\x6d\x32\x3d\x33\x70\x32\x3a\x32\x4b\x32\x7d\x33\x5b\x32\x37\x34\xcd\x32\x47\x33\x4c\x33\x17\x32\x42\x32\x5b\x32\xb9\x32" ++ + "\xaa\x32\xae\x33\x19\x33\xdc\x32\xc1\x32\x40\x34\xb8\x32\x58\x32\x75\x32\x46\x33\x07\x32\x8a\x32\x34\x32\xc3\x32\xcf\x32\xff\x34\x94\x32\x57\x32\x1d\x32\x62\x32" ++ + "\xe1\x34\xd3\x32\x3f\x32\x35\x32\x10\x32\xb5\x32\x76\x32\xcf\x32\x53\x32\x32\x32\x54\x33\xce\x33\x87\x34\xcb\x33\x5f\x33\x0f\x32\x59\x32\x6c\x32\x0c\x32\xd8\x32", + }, + .{ + .name = "a stream that ends exactly on a block of 2 threads", + .threads_per_block = 2, + .tables = 1, + .elements = 384, + .members = 1, + .luts = "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78" ++ + "\x78\x78\x78\x78\x78\x78\x78\x78\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79" ++ + "\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79" ++ + "\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79" ++ + "\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x79\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + .encoded_exponent = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55" ++ + "\x55\x55\x55\x55\x55\x55\x55\x55", + .sign_mantissa = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ++ + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + .output_positions = "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x01\x00\x00\x80\x01\x00\x00", + .gaps = "\x00\x00\x00\x00", + .split_positions = &.{}, + .want = "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c\x00\x3c\x80\x3c" ++ + "\x00\x3c\x80\x3c\x00\x3c\x80\x3c", + }, +}; diff --git a/zig/src/core/root.zig b/zig/src/core/root.zig index caac0deebd9..c929aadb43c 100644 --- a/zig/src/core/root.zig +++ b/zig/src/core/root.zig @@ -14,7 +14,9 @@ pub const digest_cache = @import("digest_cache.zig"); pub const checkpoint_identity = @import("checkpoint_identity.zig"); pub const checkpoint_read_ahead = @import("checkpoint_read_ahead.zig"); pub const checkpoint = @import("checkpoint.zig"); +pub const dfloat11_config = @import("dfloat11_config.zig"); pub const checkpoint_fixture = @import("checkpoint_fixture.zig"); +pub const dfloat11_fixtures = @import("dfloat11_fixtures.zig"); pub const exl3_load = @import("exl3_load.zig"); pub const direct_io = @import("direct_io.zig"); pub const direct_gather = @import("direct_gather.zig"); @@ -117,6 +119,9 @@ test { _ = checkpoint; _ = @import("checkpoint_prefetch.zig"); _ = @import("checkpoint_direct.zig"); + _ = @import("dfloat11.zig"); + _ = dfloat11_config; + _ = @import("checkpoint_coded_test.zig"); _ = checkpoint_identity; _ = direct_io; _ = direct_gather; diff --git a/zig/src/families/glm/cuda_dfloat11.zig b/zig/src/families/glm/cuda_dfloat11.zig new file mode 100644 index 00000000000..0aeae1e30bb --- /dev/null +++ b/zig/src/families/glm/cuda_dfloat11.zig @@ -0,0 +1,125 @@ +//! DFloat11-coded bf16 weights for the CUDA loader: config.json's coding on its checkpoints, the shapes the files omit. + +const std = @import("std"); +const core = @import("core"); +const cfg = @import("config.zig"); + +const prefix = "model.language_model."; +const layers = prefix ++ "layers."; + +/// The stored shape of a language-model bf16 matrix the loader takes coded, by its full name; null for any other. +pub fn shapeOf(c: *const cfg.Config, name: []const u8) ?[2]usize { + if (std.mem.eql(u8, name, "lm_head.weight") or std.mem.eql(u8, name, prefix ++ "embed_tokens.weight")) return .{ c.vocab, c.hidden }; + if (!std.mem.startsWith(u8, name, layers)) return null; + const rest = name[layers.len..]; + const dot = std.mem.indexOfScalar(u8, rest, '.') orelse return null; + const i = std.fmt.parseInt(u32, rest[0..dot], 10) catch return null; + if (i > c.layers) return null; + const tail = rest[dot + 1 ..]; + if (c.kind(i) == .mla) { + if (std.mem.eql(u8, tail, "self_attn.kv_b_proj.weight")) return .{ c.mla_heads * (c.nope + c.v_dim), c.kv_lora }; + return null; + } + inline for (.{ "q", "k", "v" }) |x| if (std.mem.eql(u8, tail, "self_attn." ++ x ++ "_proj.weight")) return .{ c.kdaWidth(), c.hidden }; + if (std.mem.eql(u8, tail, "self_attn.o_proj.weight")) return .{ c.hidden, c.kdaWidth() }; + return null; +} + +fn shape(ctx: *const anyopaque, name: []const u8, buf: *[core.safetensors.max_rank]usize) ?[]const usize { + const c: *const cfg.Config = @ptrCast(@alignCast(ctx)); + buf[0..2].* = shapeOf(c, name) orelse return null; + return buf[0..2]; +} + +/// config.json's dfloat11_config, when it has one, attached to `cks`; `c` must outlive them. +pub fn attach(gpa: std.mem.Allocator, io: std.Io, dir: []const u8, c: *const cfg.Config, cks: []const *core.Checkpoint) !void { + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const scratch = arena.allocator(); + const path = try std.fs.path.join(scratch, &.{ dir, "config.json" }); + const text = try std.Io.Dir.cwd().readFileAlloc(io, path, scratch, .limited(1 << 24)); + const coding = (try core.dfloat11_config.parse(scratch, text)) orelse return; + for (cks) |ck| try core.checkpoint.coded.attach(ck, coding, .{ .ctx = c, .of = shape }); +} + +const testing = std.testing; + +test { + _ = @import("cuda_dfloat11_test.zig"); +} + +test "the coded names' shapes are the published bf16 checkpoint's header shapes, rows first" { + const c: cfg.Config = .{}; + // the published bf16 headers' shapes at the default sizes: layer 5 is KDA, 3 and the MTP layer (45) are MLA + try testing.expect(c.kind(5) == .kda and c.kind(3) == .mla and c.kind(45) == .mla); + const stored = [_]struct { []const u8, [2]usize }{ + .{ "lm_head.weight", .{ 154880, 4096 } }, + .{ "model.language_model.embed_tokens.weight", .{ 154880, 4096 } }, + .{ "model.language_model.layers.5.self_attn.q_proj.weight", .{ 8192, 4096 } }, + .{ "model.language_model.layers.5.self_attn.k_proj.weight", .{ 8192, 4096 } }, + .{ "model.language_model.layers.5.self_attn.v_proj.weight", .{ 8192, 4096 } }, + .{ "model.language_model.layers.5.self_attn.o_proj.weight", .{ 4096, 8192 } }, + .{ "model.language_model.layers.3.self_attn.kv_b_proj.weight", .{ 32768, 512 } }, + .{ "model.language_model.layers.45.self_attn.kv_b_proj.weight", .{ 32768, 512 } }, + }; + for (stored) |s| try testing.expectEqual(@as(?[2]usize, s[1]), shapeOf(&c, s[0])); + // names the loader is not given coded: no shape, so a coded one is refused by name + for ([_][]const u8{ + "model.language_model.layers.3.self_attn.o_proj.weight", + "model.language_model.layers.5.self_attn.kv_b_proj.weight", + "model.language_model.layers.5.self_attn.q_proj", + "model.language_model.layers.46.self_attn.q_proj.weight", + "model.language_model.layers.x.self_attn.q_proj.weight", + "model.language_model.norm.weight", + "model.visual.blocks.0.attn.qkv.weight", + }) |name| try testing.expectEqual(@as(?[2]usize, null), shapeOf(&c, name)); +} + +test "a config with the coding attaches it to every checkpoint given; one without leaves them as they were" { + const io = testing.io; + const gpa = testing.allocator; + const group = core.dfloat11_fixtures.groups[2]; // 1,500 elements, blocks of 4 threads + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + const parts = [_]struct { []const u8, []const u8, []const u8, []const usize }{ + .{ "luts", "U8", group.luts, &.{ group.luts.len / 256, 256 } }, + .{ "encoded_exponent", "U8", group.encoded_exponent, &.{group.encoded_exponent.len} }, + .{ "sign_mantissa", "U8", group.sign_mantissa, &.{group.sign_mantissa.len} }, + .{ "output_positions", "U8", group.output_positions, &.{group.output_positions.len} }, + .{ "gaps", "U8", group.gaps, &.{group.gaps.len} }, + .{ "split_positions", "I64", "", &.{0} }, + }; + var entries: [parts.len]core.checkpoint_fixture.Entry = undefined; + for (parts, &entries) |p, *e| e.* = .{ + .name = try std.fmt.allocPrint(a, "model.language_model.layers.5.self_attn.q_proj.{s}", .{p[0]}), + .dtype = p[1], + .shape = p[3], + .bytes = p[2], + }; + try core.checkpoint_fixture.write(a, io, tmp.dir, "model.safetensors", &entries); + var buf: [64]u8 = undefined; + const dir = try std.fmt.bufPrint(&buf, ".zig-cache/tmp/{s}", .{tmp.sub_path}); + // a model whose q_proj has the fixture's 1,500 elements: 12 heads of 5 dims, 25 wide + const c: cfg.Config = .{ .kda_heads = 12, .kda_dim = 5, .hidden = 25 }; + + try tmp.dir.writeFile(io, .{ .sub_path = "config.json", .data = "{\"model_type\":\"glm\"}" }); + { + var ck = try core.Checkpoint.openModelPrefix(gpa, io, dir, prefix); + defer ck.close(); + try attach(gpa, io, dir, &c, &.{&ck}); + try testing.expectEqual(@as(?*core.checkpoint.coded.Coded, null), ck.coded); + } + try tmp.dir.writeFile(io, .{ .sub_path = "config.json", .data = + \\{"dfloat11_config":{"version":"0.2.0","bytes_per_thread":8,"threads_per_block":[4],"pattern_dict": + \\{"model\\.language_model\\.layers\\.\\d+\\.self_attn\\.q_proj":[]}}} + }); + var ck = try core.Checkpoint.openModelPrefix(gpa, io, dir, prefix); + defer ck.close(); + try attach(gpa, io, dir, &c, &.{&ck}); + const q = try ck.get(prefix ++ "layers.5.self_attn.q_proj.weight"); + try testing.expect(q.is(.bf16, &.{ 60, 25 })); + try testing.expectEqualSlices(u8, group.want, q.bytes); +} diff --git a/zig/src/families/glm/cuda_dfloat11_test.zig b/zig/src/families/glm/cuda_dfloat11_test.zig new file mode 100644 index 00000000000..7b0f22969b1 --- /dev/null +++ b/zig/src/families/glm/cuda_dfloat11_test.zig @@ -0,0 +1,120 @@ +//! The loader's cuts over DFloat11-coded weights: the bytes a plain checkpoint gives, through the same formats code. + +const std = @import("std"); +const core = @import("core"); +const cuda = @import("cuda"); +const cfg = @import("config.zig"); +const formats = @import("cuda_formats.zig"); +const coded = @import("cuda_dfloat11.zig"); + +const testing = std.testing; +const Tensor = core.checkpoint.Tensor; +const prefix = "model.language_model."; +const group = core.dfloat11_fixtures.groups[2]; // 1,500 elements, blocks of 4 threads +const names = [_]struct { []const u8, [2]usize }{ + .{ "lm_head", .{ 60, 25 } }, + .{ prefix ++ "layers.5.self_attn.o_proj", .{ 25, 60 } }, + .{ prefix ++ "layers.5.self_attn.q_proj", .{ 60, 25 } }, +}; +const coding = + \\{"dfloat11_config":{"version":"0.2.0","bytes_per_thread":8,"threads_per_block":[4],"pattern_dict":{"lm_head":[], + \\"model\\.language_model\\.layers\\.5\\.self_attn\\.o_proj":[],"model\\.language_model\\.layers\\.5\\.self_attn\\.q_proj":[]}}} +; + +/// What formats.cut asks of the loader, with the uploads kept as bytes: a same-dtype cut is a copy of rows or columns. +const Cuts = struct { + gpa: std.mem.Allocator, + ck: *core.Checkpoint, + host: std.ArrayList(u8) = .empty, + out: std.ArrayList(u8) = .empty, + /// formats.cut's FP8 branches name the lane; a bf16 cut never reads it. + tools: struct { lane: *const cuda.qmmf.Lane } = undefined, + + pub fn formatOne(_: *Cuts, ck: *core.Checkpoint, module: []const u8, wants: []const formats.Format) !formats.Format { + var buf: [224]u8 = undefined; + const w = try ck.get(try std.fmt.bufPrint(&buf, "{s}.weight", .{module})); + const f = try formats.of(.{ .mixed = null }, .{ .weight = formats.metaOf(&w) }); + for (wants) |want| if (f == want) return f; + return error.UnreadableFormat; + } + + pub fn rows(L: *Cuts, t: Tensor, lo: usize, hi: usize, total: usize, to: core.checkpoint.DType) !void { + if (t.dtype != to or t.numel() % total != 0) return error.UnexpectedTensor; + const per = 2 * t.numel() / total; + try L.host.appendSlice(L.gpa, t.bytes[lo * per .. hi * per]); + } + + pub fn cols(L: *Cuts, t: Tensor, lo: usize, hi: usize, to: core.checkpoint.DType) !void { + if (t.dtype != to or t.rank != 2) return error.UnexpectedTensor; + for (0..t.dim(0)) |r| try L.host.appendSlice(L.gpa, t.bytes[2 * (r * t.dim(1) + lo) .. 2 * (r * t.dim(1) + hi)]); + } + + pub fn whole(L: *Cuts, t: Tensor, to: core.checkpoint.DType) !void { + if (t.dtype != to) return error.UnexpectedTensor; + try L.host.appendSlice(L.gpa, t.bytes); + } + + pub fn put(L: *Cuts, comptime _: []const u8, _: anytype) !u64 { + try L.out.appendSlice(L.gpa, L.host.items); + L.host.clearRetainingCapacity(); + return 1; + } +}; + +/// The head's rows 10 to 40, o_proj's columns 5 to 35 and q_proj whole, cut as the loader cuts them from `dir`. +fn cuts(gpa: std.mem.Allocator, dir: []const u8, c: *const cfg.Config) ![]u8 { + const io = testing.io; + var ck = try core.Checkpoint.openModelPrefix(gpa, io, dir, prefix); + defer ck.close(); + var head = try core.Checkpoint.openModelPrefix(gpa, io, dir, "lm_head."); + defer head.close(); + try coded.attach(gpa, io, dir, c, &.{ &ck, &head }); + var L: Cuts = .{ .gpa = gpa, .ck = &ck }; + defer L.host.deinit(gpa); + errdefer L.out.deinit(gpa); + _ = try formats.cut(&L, &head, &.{"lm_head"}, &.{.{ .rel = "lm_head", .rows = .{ 10, 40 } }}, &.{ .bf16, .mxfp8 }, "head", .{}); + _ = try formats.cutProj(&L, prefix, 5, &.{.{ .rel = "self_attn.o_proj", .cols = .{ 5, 35 } }}, &.{ .bf16, .mxfp8 }, "layers.{d}.kda.o"); + ck.release(); // the loader's, between layers: what was decoded goes, and the next cut decodes again + _ = try formats.cutProj(&L, prefix, 5, &.{.{ .rel = "self_attn.q_proj" }}, &.{.bf16}, "layers.{d}.kda.q"); + return L.out.toOwnedSlice(gpa); +} + +test "the loader's cuts of coded weights (head rows, o_proj columns, a whole q_proj) are the plain checkpoint's bytes" { + const io = testing.io; + const gpa = testing.allocator; + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + // a model whose three matrices have the fixture's 1,500 elements: 12 heads of 5 dims, 25 wide, 60 tokens + const c: cfg.Config = .{ .kda_heads = 12, .kda_dim = 5, .hidden = 25, .vocab = 60 }; + var got: [2][]u8 = undefined; + for (&got, 0..) |*out, as_groups| { + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var entries: std.ArrayList(core.checkpoint_fixture.Entry) = .empty; + for (names) |n| { + if (as_groups == 0) { + try entries.append(a, .{ .name = try std.fmt.allocPrint(a, "{s}.weight", .{n[0]}), .dtype = "BF16", .shape = try a.dupe(usize, &n[1]), .bytes = group.want }); + continue; + } + const parts = [_]struct { []const u8, []const u8, []const u8, []const usize }{ + .{ "luts", "U8", group.luts, &.{ group.luts.len / 256, 256 } }, + .{ "encoded_exponent", "U8", group.encoded_exponent, &.{group.encoded_exponent.len} }, + .{ "sign_mantissa", "U8", group.sign_mantissa, &.{group.sign_mantissa.len} }, + .{ "output_positions", "U8", group.output_positions, &.{group.output_positions.len} }, + .{ "gaps", "U8", group.gaps, &.{group.gaps.len} }, + .{ "split_positions", "I64", "", &.{0} }, + }; + for (parts) |p| try entries.append(a, .{ .name = try std.fmt.allocPrint(a, "{s}.{s}", .{ n[0], p[0] }), .dtype = p[1], .shape = try a.dupe(usize, p[3]), .bytes = p[2] }); + } + try core.checkpoint_fixture.write(a, io, tmp.dir, "model.safetensors", entries.items); + try tmp.dir.writeFile(io, .{ .sub_path = "config.json", .data = if (as_groups == 0) "{\"model_type\":\"glm\"}" else coding }); + var buf: [64]u8 = undefined; + out.* = try cuts(gpa, try std.fmt.bufPrint(&buf, ".zig-cache/tmp/{s}", .{tmp.sub_path}), &c); + } + defer for (got) |g| gpa.free(g); + try testing.expectEqual(@as(usize, 2 * (30 * 25 + 25 * 30 + 1500)), got[0].len); + try testing.expectEqualSlices(u8, group.want[2 * 10 * 25 .. 2 * 40 * 25], got[0][0 .. 2 * 30 * 25]); + try testing.expectEqualSlices(u8, group.want[2 * 5 .. 2 * 35], got[0][2 * 30 * 25 ..][0 .. 2 * 30]); // o_proj's first row + try testing.expectEqualSlices(u8, got[0], got[1]); +} diff --git a/zig/src/families/glm/cuda_weights.zig b/zig/src/families/glm/cuda_weights.zig index ac9f7aea111..696a4238146 100644 --- a/zig/src/families/glm/cuda_weights.zig +++ b/zig/src/families/glm/cuda_weights.zig @@ -541,6 +541,7 @@ pub fn load(gpa: std.mem.Allocator, io: std.Io, d: *const cuda.Driver, stream: c defer core.checkpoint.cache.close(&ck); var head_ck = try core.Checkpoint.openModelPrefix(gpa, io, dir, "lm_head."); defer core.checkpoint.cache.close(&head_ck); + try @import("cuda_dfloat11.zig").attach(gpa, io, dir, &c, &.{ &ck, &head_ck }); var L: Loader = .{ .gpa = gpa, .d = d, .stream = stream, .pack_dense = tools.pack_dense, .tools = tools, .w = &w, .ck = &ck }; defer L.host.deinit(gpa); defer L.staging.deinit(); @@ -576,6 +577,7 @@ test { _ = @import("cuda_proj.zig"); _ = @import("cuda_fp8pb.zig"); _ = @import("cuda_mxfp8.zig"); + _ = @import("cuda_dfloat11.zig"); _ = @import("cuda_load_ahead.zig"); _ = @import("cuda_load_pack.zig"); }