Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- HIP: Inkling 2 Mini's per-stream state and prompt snapshots on one HIP rank, saved and restored byte for byte (not yet used by serving). Thanks @AbrahamCete.

- Inkling 2 Mini on Metal: plain decode can pick its tokens on the GPU with TF_INK2_GPU_TOKENS=1 (default off); tokens are unchanged and decode is 2.5-5% faster from 510 to 16K tokens on an M5 Ultra (#5655).

- Inkling 2 CUDA: prompt snapshots persist through the kept-image disk store, with identity checks and safe fallback on bad images.
Expand Down
16 changes: 16 additions & 0 deletions docs/design/inkling-2-mini.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ Each slice is one pull request with its own tests. "Needs" names what must land

H1 to H3, M1 and M2 can start now. C1 waits on Small's stack; C3 and M3 run the bf16-activation arithmetic and have no other dependency.

### HIP stream state

#4265 plans the HIP column, one pull request a slice. Its stream state (`families/inkling2/hip_engine.zig`) mirrors the CUDA engine's model without the forward.

- **A stream** holds the visit cache that `loop.CacheLayout` sizes, four 32-byte rewind sites a visit, a backup of the conv states, a 16-row window history and the last prompt row's FP32 logits.
- Past the cache, that is 25,087,464 bytes on Mini and 3,138,792 on the tiny checkpoint. HIP's draws keep no per-stream sampling rule, so there is no 32-byte rule buffer as on CUDA.
- A Mini stream is 800,673,256 bytes at an 8,192-token context, 1,605,979,624 at 32,768, 4,827,205,096 at 131,072 and 34,891,976,168 at 1,048,576.
- **The forward's scratch** is allocated once and shared by every stream. On Mini it is 848,778,624 bytes up to a 32,768-token context and 2,356,761,984 at 1,048,576.
- **A prompt snapshot** (`hip_snapshot.zig`) walks the state through `kept_state.zig`, as CUDA's engine does.
- It copies each visit's kept K and V rows head by head, split where the ring wraps, then every conv state. On Mini that is 171,442,176 bytes plus 32,768 a position once the window is full.
- It restores into any slot whose context holds its position.
- **The context.** Mini's config names `max_position_embeddings` only under `mtp_config`, so the HIP host reads no window. The state therefore refuses a context past `text_config.model_max_length` itself.
- **The checks.**
- `zig build -Dhip=true test-inkling2-hip-state-host` checks the sizes, the refusals and the copy lists without a device.
- `zig build -Dhip=true inkling2-hip-state-test` saves, clobbers and restores seeded slots on the GPU, in place and at another capacity, and compares every byte.

## DSpark

DSpark support is part of the plan on both backends, not an extra: H4, C5 and M6 carry it, and C7 and M8 fill the family's DSpark cell in the optimization ledger.
Expand Down
24 changes: 22 additions & 2 deletions zig/build/hip_contract.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ pub fn steps(b: *std.Build, o: Options) void {
.link_libc = true,
.imports = &.{ .{ .name = "hip", .module = o.host }, .{ .name = "core", .module = o.host.import_table.get("core").? } },
}) }));
const ink_step = b.step("test-inkling2-hip-host", "Inkling 2's HIP attention plan, contract layouts, serve-flag refusals and text weights without a device");
for ([_]*std.Build.Step{ &ink_plan.step, &ink_layout.step, &ink_refusals.step, &ink_weights.step }) |st| {
const ink_state = b.addRunArtifact(b.addTest(.{ .root_module = state(b, b.graph.host, .Debug, o.host, "zig/src/families/inkling2/hip_engine.zig"), .filters = &.{ "inkling2 hip state:", "hip snapshot walk:" } }));
b.step("test-inkling2-hip-state-host", "Inkling 2 Mini's HIP stream state: sizes, slots, refusals and snapshot copies over a recording runtime").dependOn(&ink_state.step);
const ink_step = b.step("test-inkling2-hip-host", "Inkling 2's HIP attention plan, contract layouts, serve-flag refusals, text weights and stream state without a device");
for ([_]*std.Build.Step{ &ink_plan.step, &ink_layout.step, &ink_refusals.step, &ink_weights.step, &ink_state.step }) |st| {
ink_step.dependOn(st);
o.test_step.dependOn(st);
}
Expand Down Expand Up @@ -90,6 +92,13 @@ pub fn steps(b: *std.Build, o: Options) void {
experts_step.dependOn(st);
o.test_step.dependOn(st);
}
// the device check compiles in `test`; only its own step runs it, on the GPU
const ink_device = b.addTest(.{ .root_module = state(b, o.target, .ReleaseSafe, o.host, "zig/src/families/inkling2/hip_snapshot_test.zig"), .filters = &.{"inkling2 hip snapshots on gfx1151:"} });
o.test_step.dependOn(&ink_device.step);
b.step("inkling2-hip-state-build", "Compile the Inkling 2 Mini HIP snapshot check without running it").dependOn(&ink_device.step);
const ink_device_run = b.addRunArtifact(ink_device);
ink_device_run.has_side_effects = true;
b.step("inkling2-hip-state-test", "Inkling 2 Mini HIP stream snapshots saved, clobbered and restored byte for byte on the GPU").dependOn(&ink_device_run.step);
const source = b.path("zig/kernels/hip/contract_controls.hip");
const own = hip.compile(b, o.hipcc, o.arch, source, "contract_controls.hsaco");
const exe = runner(b, o.target, o.optimize, o.gpu, o.lighton_gpu, controls(b, o.arch, own));
Expand Down Expand Up @@ -131,6 +140,17 @@ fn inkling2(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.built
return b.createModule(.{ .root_source_file = root, .target = target, .optimize = optimize, .imports = &.{.{ .name = "hip", .module = hip_mod }} });
}

/// Inkling 2 Mini's HIP stream state rooted at `root`, over the HIP backend `hip_mod` (its runtime only, no kernels).
fn state(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, hip_mod: *std.Build.Module, root: []const u8) *std.Build.Module {
return b.createModule(.{
.root_source_file = b.path(root),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{ .{ .name = "hip", .module = hip_mod }, .{ .name = "core", .module = hip_mod.import_table.get("core").? } },
});
}

/// Inkling 2 Mini's HIP refusals through the host's hook, over the host build's `engine_api` and `hip_serve`.
fn refusals(b: *std.Build, family_mod: *std.Build.Module) *std.Build.Module {
const api = family_mod.import_table.get("engine_api").?;
Expand Down
Loading
Loading