Skip to content

feat(hip): Inkling 2 Mini's text weights on one HIP rank, through CUDA's loader made generic - #5031

Merged
ashhart merged 6 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-weights
Nov 28, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-weights

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

TensorFold cannot put Inkling 2 Mini's text weights on a HIP device. This adds the loader: HIP5a, the first of the five
HIP5 pull requests listed on #4274 (issuecomment-7158137239), and one of the two that need none of its questions
answered. No engine, kernel or registration.

  • loop_weights.zig's loader moves unchanged into weights.zig, generic over the device buffer: Weights(Buffer),
    Loader(Buffer), load(Buffer, ...). loop_weights.zig keeps its five public names over cuda.DeviceBuffer, so
    loop_engine.zig and cuda_native.zig do not change. Against the old file, the body differs only in indentation,
    the Buffer parameter, two declarations made pub and controllers(l: anytype).
  • hip_weights.zig runs that loader on one HIP rank through hip.DeviceBuffer: one 256-aligned arena sized from the
    checkpoint, every text tensor uploaded once from its mapped bytes, the experts as stored (NVFP4 or MXFP8, as the plan
    picks per layer) and the controllers. crossQueries returns a core layer's two message query rows at the offsets
    loop_engine.zig:378 uses, and refuses any other layer.
  • The next slices read from it: each layer's expert codes, scales, amax and denominator for feat(hip): Inkling 2's routed experts under HIP-DOT-Q4, the HIP column's serial dot baseline #4994's launcher, and the
    controllers and crossQueries for perf(hip): Inkling 2's loop kernels (cross-pass message and message gate) at hidden 2,304 and 256 under named HIP baselines #5012's.

Why one loader and not a HIP copy: the tensor walk, its checks and its refusals stay in one place, as modelopt.load
already does for the experts. CUDA's behavior is unchanged; the checks are below.

Checks on this head

  • Head commit: fa5e2ab, on main 1b12359.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 164 and 164, 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test-inkling2-hip-host -Dhip=true: 45 of 47 passed, 2 skipped (names_test.zig's two checkpoint
      tests, which need TF_INKLING2_TINY and TF_INKLING2_REAL). The new tests run the loader on a recording HIP
      runtime over Mini's release header (fixtures/mini_model_header.txt), laid out on reserved memory:
      • all 822 text tensors are uploaded once each, back to back and 256-aligned, each at the field that names it; the
        one allocation equals the checkpoint's padded bytes, and no tensor is left unused;
      • NVFP4 experts on layers 0-19 and MXFP8 on 20-23, as the plan has them;
      • crossQueries on all 24 visits that carry messages, and its refusals for other layers and a config without the
        loop;
      • a config without the loop is refused before any device allocation, and the arena refuses a span past its end;
      • a failed allocation uploads nothing, and a failed upload frees the arena once and leaks nothing on the host.
    • zig build test-inkling2-host: 45 of 49 passed, 4 skipped. zig build test-inkling2-cuda-host: 43 of 43.
    • zig build test on a clean tree of this head: 13,587 of 13,681 passed, 93 skipped, 1 failed. The failure is
      stage_hip_test "every staged call on HIP memory equals the reference, whole and in parts", which feat(hip): Inkling 2's routed experts under HIP-DOT-Q4, the HIP column's serial dot baseline #4994 reports
      failing on main on this machine as well.
    • zig build test -Dhip=true on the same tree: 1,529 of the 1,553 tests it ran passed, 23 skipped, and the same
      stage_hip_test failed.
    • zig fmt --check build.zig zig and git diff --check: clean.
    • CUDA unchanged, three one-off checks that are not part of this diff, run before the rebase onto 1b12359 (main
      has changed only Metal files of the family since):
      • Main's CUDA loader with its buffer type swapped for a recorder, against this branch's shared and HIP loaders,
        over the same header in 9 cases (the load, each refusal, a failed allocation and a failed upload): the same
        allocation of 18,889,368,576 bytes, the same 1,048 upload windows in order, the same 862 address fields and the
        same errors. A planted alignment of 128 turns 6 of the 9 red.
      • A comptime comparison with main's loop_weights.zig: the same five public names, fields, defaults, sizes,
        methods, load signature and 44 error names.
      • zig build check-native-cuda-host builds the CUDA server; a planted @compileError in loop_weights.load
        fails it, so that build analyzes the loader.
  • The new tests fail before their change: without weights.zig, the HIP host step stops with
    unable to load "weights.zig": FileNotFound. Three refusals of the shared loader have no test:
    UnusedCheckpointTensor, MissingTensor and UnexpectedTensor. Core reports each with std.log.err, and Zig's
    test runner fails any test that logs an error; the one-off differential above ran them.
  • CI: green on this head (10 checks pass, 2 skipped).
  • Not run, and why:
    • A load of the released checkpoint onto a device: nothing calls this loader yet, and the checkpoint is not on this
      machine.
    • Any GPU: the change has no device code.

Receipt

n/a: nothing calls this loader yet; no engine, server or kernel reaches it. The host tests and the CUDA checks above
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 engine)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a: no 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 engine)

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @AbrahamCete. The generic loader preserves CUDA's tensor types, traversal, upload order and cleanup after the type substitutions, and the public aliases remain intact. The HIP adapter forwards raw bytes, while the query-row helper checks core-layer bounds.

This looks safe to land as the preparatory loader slice. The recording-runtime fixtures are useful evidence; they do not yet qualify a HIP serving engine. When combining the refusal slice, retain both focused host test artifacts in the build wiring.

  • Synthena

ashhart and others added 6 commits November 28, 2026 07:18
…tral weights.zig

loop_weights.zig's loader, its tensor walk, checkpointBytes and the
controllers' naming move unchanged into weights.zig, with the CUDA
device buffer made a type parameter. loop_weights.zig keeps its public
names (Controller, Attention, Layer, Weights, load) over
weights.Weights(cuda.DeviceBuffer), so loop_engine.zig and
cuda_native.zig are untouched.

Over the release's header (fixtures/mini_model_header.txt) and one
recording buffer, the old CUDA walk and the shared one make the same
allocation, the same 822 uploads in order and the same addresses.
hip_weights.zig loads the text checkpoint through the loader CUDA
shares (weights.zig), over a HIP device buffer, into one 256-aligned
allocation. It exposes each layer's attention, conv, router, expert
(format, w13 and w2 codes, scales, amax, denominator) and controller
addresses, and crossQueries, the two cross-pass query rows a core
layer's messages read.

Host tests in test-inkling2-hip-host run the loader on the release's
header over a recording runtime: every text tensor uploaded once, 256
aligned, at the field that names it; one arena of the checkpoint's
padded bytes; each layer's expert format the plan's; and the
Inkling2LoopRequired and LoopWeightsOverflow refusals.
@ashhart
ashhart force-pushed the feat/hip-inkling2-weights branch from 47af75c to 7c9813e Compare November 28, 2026 07:19
@ashhart
ashhart merged commit a26972d into ashhart:main Nov 28, 2026
1 check failed
@ashhart

ashhart commented Nov 28, 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.

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