Skip to content

feat(hip): Inkling 2 Mini's per-stream state and prompt snapshots on one HIP rank - #5728

Merged
ashhart merged 3 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-state
Dec 1, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-state

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

TensorFold has Inkling 2 Mini's HIP text weights loader (#5031), serve-flag refusals (#5034), attention (#4633), loop kernels (#5012), and the shared kept_state.zig walk (#4724), but no per-stream state or prompt snapshot path on HIP. This adds HIP5b, the second slice of the HIP5 stack listed on #4274 (and Refs #4265). No forward pass, new kernels, or native registration yet.

  • zig/src/families/inkling2/hip_engine.zig mirrors CUDA's loop_engine.zig Model without the forward:
    • Per-stream slot of five device buffers: visit cache sized by loop.CacheLayout, four 32-byte rewind sites per visit (conv.hip / ops.cu RewindSite layout), conv-state backup, 16-row window history, and the last prompt row's FP32 logits (no 32-byte per-stream sampling rule buffer on HIP).
    • Shared forward scratch allocated once at Model.init, with hip_attention.zig partial slots and routed-expert activation/down rows.
    • Pre-allocation refusals by name (with log lines): missing loop config, gate rank != 64, mismatched global/sliding KV widths, context 0 or past text_config.model_max_length (Mini names max_position_embeddings only under mtp_config), and > 16 streams.
  • zig/src/families/inkling2/hip_snapshot.zig adapts loop.CacheLayout into kept_state.Visit slices and delegates kept-row byte counts and packed-order traversal directly to #4724's shared kept_state.zig walk (the same walk CUDA's loop_engine.zig uses), followed by the slot's conv region. Model.save, restore, and drop queue one device copy per piece on the HIP stream with CUDA's named refusals (NotAtMark, StateOfAnotherModel, BadLoopSnapshot) and error cleanup. Snapshots store positions, so they restore into any slot whose context holds them.
  • zig/build/hip_contract.zig adds test-inkling2-hip-state-host (also wired into test-inkling2-hip-host and test), inkling2-hip-state-build, and the explicit GPU step inkling2-hip-state-test.
  • docs/design/inkling-2-mini.md documents the HIP stream state byte budgets, kept_state.zig-backed snapshot walk, context check, and test steps.

Stack and scope

  • Issue: Refs docs: a plan for Inkling 2 Mini on CUDA and Metal in claimable slices #4274 (HIP5b), Refs Inkling 2 Mini on HIP (gfx1151): serve the looped 26.4B checkpoint natively #4265 (HIP column).
  • Dependency diagram:
    main (includes #4633 attention, #5012 loop, #5031 weights, #5034 refusals, #5369 tiny-mini, #4724 kept_state)
      └── 📍 HIP5b: feat/hip-inkling2-state (this PR: per-stream state + prompt snapshots)
    Independent open kernel PRs (separate stack, ready/in review):
      #4994 (experts, READY to land), #5499 (attn-extent, READY to land), #5192 (NaN tile)
    Follow-ups (after kernel PRs + HIP2 land):
      HIP2 (dense/logits/conv/norms) → HIP5c (forward) → HIP5d (lane adapter) → HIP5e (serve) → HIP6 (DSpark)
    
  • Stacked on: main 25c3d447d. Commits:
    • e11e08bb0 feat(hip): Inkling 2 Mini's per-stream state on one HIP rank
    • fca4a675d feat(hip): Inkling 2 Mini's prompt snapshots on one HIP rank
  • Size: +1,346/-2 in 6 files (572 lines implementation in hip_engine.zig + hip_snapshot.zig, 736 lines host + GPU tests in hip_engine_test.zig + hip_snapshot_test.zig, 24 lines build wiring, 16 lines design doc). Both commits form one cohesive state + snapshot work unit; rollback is cleanly bounded to these 6 files.
  • Out of scope: forward pass, HIP kernels, lane adapter, server registration, and DSpark.

Checks on this head

  • Head commit: fca4a675d, on main 25c3d447d.
  • Lean checker (python3 tools/zig/lean_check.py): 0 issues in all 6 touched files (88 pre-existing repo-wide across 9,180 files).
  • Formatting and whitespace: zig fmt --check build.zig zig and git diff --check origin/main..HEAD clean.
  • Host tests (-Dhip=true):
    • zig build -Dhip=true test-inkling2-hip-state-host: 21/21 passed (Mini and tiny-inkling2-mini byte budgets at 8K/32K/128K/1M, shared scratch, rewind site tables, addSlots/reset/deinit, every refusal, allocation-failure cleanup, kept_state.zig ring wrap pieces, and host byte-for-byte restore in place and across capacities).
    • zig build -Dhip=true test-inkling2-hip-host: 89/91 passed, 2 skipped (names_test.zig checkpoint tests needing local env vars).
    • zig build -Dhip=true test-inkling2-host: 69/74 passed, 5 skipped.
    • zig build -Dhip=true test-inkling2-loop-hip-host: 33/33 passed.
    • zig build -Dhip=true check-hip-kernel-contract-host: passed.
  • GPU device test on Radeon 8060S (gfx1151):
    • zig build -Dhip=true -Dhip-arch=gfx1151 inkling2-hip-state-test: 5/5 passed (seeded Mini and tiny-inkling2-mini slots saved, verified against host gather, clobbered, restored byte-for-byte in place and into another slot capacity).
  • CI: re-running on rebased head fca4a675d (previous head ffef60aae passed 5/5 checks).

Receipt

n/a: no forward, server, or inference path reaches this state yet. The host recording tests (21/21) and gfx1151 device snapshot round-trip test (5/5) are the evidence.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (n/a: no forward/engine)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a: no forward/engine)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (n/a: no arithmetic)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (n/a: no forward/engine)

@AbrahamCete
AbrahamCete force-pushed the feat/hip-inkling2-state branch from ffef60a to fca4a67 Compare November 30, 2026 21:15
@AbrahamCete
AbrahamCete marked this pull request as ready for review November 30, 2026 21:15
@ashhart
ashhart force-pushed the feat/hip-inkling2-state branch from fca4a67 to cb82cb7 Compare December 1, 2026 02:14
@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Reviewed at this head: Inkling 2 Mini's HIP stream state and snapshots are not yet used by serving. On a Strix Halo (gfx1151) the host steps passed and the device test passed 5 of 5: save, clobber and restore, in place and at another capacity, every byte equal. This head's CI passed.

  • Synthena

AbrahamCete and others added 3 commits December 1, 2026 06:08
hip_engine.zig is the HIP twin of loop_engine.zig's Model without the
forward. Each stream owns a slot of five buffers: the visit cache that
loop.CacheLayout sizes, four 32-byte rewind sites a visit (conv.hip's
and ops.cu's RewindSite layout), the conv states' backup, a 16-row
window history and the last prompt row's FP32 logits. HIP's draws keep
no per-stream sampling rule, so stream_bytes has no rule buffer.
addSlots writes each slot's site table and zeroes its conv states;
reset zeroes the current slot's. The forward's shared scratch follows
CUDA's buffer list, with hip_attention.zig's partial slots and the
routed experts' activation and down rows, allocated once at init.

Before any allocation the state refuses, by name and with a log line,
a config without a loop, gates other than rank 64, global and sliding
KV widths that differ (CacheLayout sizes every conv by the sliding
width), a context of zero or past text_config.model_max_length (Mini
names max_position_embeddings only under mtp_config, so the HIP host
reads no window), and more than 16 streams.

test-inkling2-hip-state-host, also part of test-inkling2-hip-host,
runs it over a recording runtime: each stream's allocations at Mini's
and tiny-inkling2-mini's shapes at 8K, 32K, 128K and 1M (25,087,464 B
past the cache on Mini), the scratch, the site tables, the addSlots,
reset and deinit counts, each refusal and its message, and cleanup
after a failed allocation.
hip_snapshot.zig adapts loop.CacheLayout into kept_state.Visit slices
and delegates kept-row counting and packed-order traversal to the shared
kept_state.zig walk (the same walk CUDA's loop_engine.zig uses), then
appends the slot's conv region. Model.save, restore and drop queue one
device copy a piece on the stream, with CUDA's refusals by name
(NotAtMark, StateOfAnotherModel, BadLoopSnapshot) and log lines. A
snapshot is stored by position, so it restores into any slot whose
context holds it. A save whose copy fails waits for the stream before
it frees its buffer.

Host tests: the walk's rings equal hip_attention.zig's, its bytes at
Mini's and tiny-inkling2-mini's shapes, its pieces split at the ring
wrap and tile the snapshot; save and restore issue exactly those
copies; on host memory a restored slot equals a reference built from
positions byte for byte, in place and at another capacity.

inkling2-hip-state-test (built in test, run only on its own step)
does the same on gfx1151 with tiny-inkling2-mini's and Mini's shapes:
seeded slots saved, the snapshot compared with the walk's gather,
the slot clobbered, restored and compared whole, and restored into a
slot of another capacity.
@ashhart
ashhart force-pushed the feat/hip-inkling2-state branch from cb82cb7 to fd1c780 Compare December 1, 2026 06:08
@ashhart
ashhart merged commit f17dedb into ashhart:main Dec 1, 2026
5 of 10 checks passed
@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thank you @AbrahamCete. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

AbrahamCete added a commit to AbrahamCete/TensorFold that referenced this pull request Dec 1, 2026
…tract launchers

Zig 0.17 requires each source file to belong to one module. After ashhart#5012,
ashhart#4994, ashhart#5499 and ashhart#5728, inkling2_hip, inkling2_loop_hip,
inkling2_experts_hip and the stream state targets all imported config.zig
directly, causing duplicate module ownership inside tf-hip-kernel-contract.

Group the shared Inkling 2 family files (config, plan, names, names_test,
loop, kept_state, hip_weights, config_test) into
zig/src/families/inkling2/hip_family.zig and pass one inkling2_family
module into the Inkling 2 HIP launcher and state modules.
ashhart pushed a commit to AbrahamCete/TensorFold that referenced this pull request Dec 1, 2026
…tract launchers

Zig 0.17 requires each source file to belong to one module. After ashhart#5012,
ashhart#4994, ashhart#5499 and ashhart#5728, inkling2_hip, inkling2_loop_hip,
inkling2_experts_hip and the stream state targets all imported config.zig
directly, causing duplicate module ownership inside tf-hip-kernel-contract.

Group the shared Inkling 2 family files (config, plan, names, names_test,
loop, kept_state, hip_weights, config_test) into
zig/src/families/inkling2/hip_family.zig and pass one inkling2_family
module into the Inkling 2 HIP launcher and state modules.
ashhart pushed a commit that referenced this pull request Dec 1, 2026
…tract launchers

Zig 0.17 requires each source file to belong to one module. After #5012,
#4994, #5499 and #5728, inkling2_hip, inkling2_loop_hip,
inkling2_experts_hip and the stream state targets all imported config.zig
directly, causing duplicate module ownership inside tf-hip-kernel-contract.

Group the shared Inkling 2 family files (config, plan, names, names_test,
loop, kept_state, hip_weights, config_test) into
zig/src/families/inkling2/hip_family.zig and pass one inkling2_family
module into the Inkling 2 HIP launcher and state modules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants