Skip to content

ROCm (Strix Halo) support for Qwen3.8-27B, with fast GGUF prompts on by default - #144

Closed
ThinkOffApp wants to merge 34 commits into
ashhart:mainfrom
ThinkOffApp:strix-rocm-gguf
Closed

ThinkOffApp wants to merge 34 commits into
ashhart:mainfrom
ThinkOffApp:strix-rocm-gguf

Conversation

@ThinkOffApp

@ThinkOffApp ThinkOffApp commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

0.6.2 validation complete for the tested Strix cases: Head 4e96ba5, based on upstream 56e2e3e. Default and TENSORFOLD_GGUF_FAST=0 each match drafted vs serial 16/16 (8 greedy, 8 seeded). All four reply files match the corresponding earlier 0.6.1-based run 16/16 each; default vs exact differs in 6/16. These raw reply comparisons were independently checked by codexmb. The current-head measurements below are single runs; no new performance optimization is claimed. Known test failures remain disclosed below.

ROCm (Strix Halo, gfx1151) for the Qwen3.8-27B CUDA path, GGUF on Gufo's kernels: rebased on 0.6.2

This PR is rebased onto upstream 0.6.2 (56e2e3e), with 31 commits; current head 4e96ba5. The two conflicts in gdn.cu and dflash2.py were resolved, preserving the ROCm portability changes and GGUF support. The new GDN kernel passes 44/44 tests on the Strix in the exported run. The earlier 0.6.1-based head 1c11bd6 is preserved as strix-rocm-gguf-v061-backup; the 0.5.0 version is preserved as strix-rocm-gguf-v050-backup.

What is new since the 0.5.0 version of this PR

  • Fast GGUF prompts on ROCm, on by default (TENSORFOLD_GGUF_FAST=0 turns them off).
    • Prompts quantize to Q8_1 and run Gufo's W8A8 WMMA GEMM (the route Gufo's own prefill uses).
    • One row runs on Gufo's decode GEMV.
    • Draft verify stays on the exact kernel (TENSORFOLD_GGUF_FAST_VERIFY, default exact). We tried WMMA and bf16
      for verify: they changed drafted replies and were not faster.
    • With the setting unset, ROCm uses the fast route. NVIDIA is excluded by the HIP gate. TENSORFOLD_GGUF_FAST=0 selects the exact route.
    • Fast prompt math differs from exact prompt math: 6 of 16 tested replies differ between the routes. Drafted versus serial replies match within each route in these tests; this is a finite comparison, not a general quality guarantee.
    • tests/test_gguf_fast_default.py covers the default and override; scripts/gguf_fast_prefill_check.py checks both directions on real weights and restores the environment in a finally block.
  • Q8_0 W8A8 over-read. Gufo's Q8_0 kernel reads activations in whole 128-token blocks with no bounds check.
    • The activation buffer has 8 tiles of slack; 6 is the minimum sufficient, derived in
      tests/test_gguf_q8_bounds.py, which reads the kernel constants from source.
    • scripts/gguf_bounds_check.py puts buffers against unmapped pages (HIP VMM). The negative controls fault: exact
      size, and 5 tiles. The 700-case 8-tile sweep is clean on gfx1151.
  • Fixes found in review:
    • pyproject ships tensorfold.cuda.gguf sources plus the vendored Gufo tree (the wheel used to hold only
      __init__.py).
    • gguf_detect.gguf_file: engine admission no longer imports gguf_load. That import broke 12
      test_cuda_capacity stand-in tests; it already did so in this PR on 0.5.0.
    • b16.cu builds on hipcc. The PTX prompt kernel is built off-ROCm only, ROCm prompt rows use the row kernel, and
      gdn.cu's portability macros are applied.
    • DFlash2 handles an unquantized (Plain) target head. Before, setup would crash on it.
    • A GGUF on a non-ROCm build gets a clear error before Gufo's HIP-only build.
  • Test fixes: the packaging test skips torch's run-time hipify copies inside the source tree. test_qmm::test_every_nibble_decodes_exactly now has the same PTX-only skip as the other tests that call the CUDA-only extension.

Deliberately not gated to ROCm

  • GGUF detection and loading. Off ROCm it is refused with a clear message.
  • The qmm_fast MLX-layout row helpers. The standard tiled CUDA route does not reach them.
  • DFlash2 Plain-head support. It is correct on any backend.
  • The top_by_value_then_id tie-break, the one deliberate CUDA-visible behaviour change, as discussed with
    @jkuepker.

Measured (single runs; receipts available)

Strix Halo (gfx1151), Qwen3.8-27B. Answering speed is tok/s for short / code / story / long doc. GGUF rows below use the 2 Oct 0.6.2 rerun on head 4e96ba5; the MLX row is the earlier 0.6.1 run. These are single runs. The long-document answering measurement follows a warm-up and benefits from prompt caching; prompt reading is measured separately on the 8,651-token prompt.

Setup Prompt reading (8,651-token prompt) Answering, drafts on Answering, drafts off Drafted vs serial
GGUF UD-Q4_K_XL, fast (default) 193.0 tok/s (191.3 with drafts) 25.4 / 35.2 / 17.6 / 27.6 10.5 16/16 identical
GGUF UD-Q4_K_XL, exact (TENSORFOLD_GGUF_FAST=0) 77.4 tok/s (75.3 with drafts) 25.4 / 37.7 / 17.4 / 27.6 10.4 16/16 identical
MLX 4-bit 140 tok/s 11.5-28.7 8.9 10/16 identical (open bug below)
  • Chunk-invariance of the fast prompt route: 20 weights over 8 quant types, slices of 1-1000 rows and permuted
    rows. Bit-identical at pad 0 and pad 96.
  • Earlier NVIDIA regression (DGX Spark, GB10, CUDA 13): the 29-commit rebase as a wheel against plain 0.6.1, same harness. The subsequent fast-default switch remains HIP-gated.
    • Replies identical, 16/16 serial and 16/16 drafted.
    • Per-kind speed similar in single runs (no repeated-run spread).
    • Not rechecked on this branch: TP2, NVFP4, EXL3 and GLM.
  • CPU suite (macOS): the same 23 failures as plain v0.6.1, no new ones.
  • 0.6.2 rerun (2 Oct, Strix, 11:08–12:03 UTC; head 4e96ba5):
    • Default and FAST=0 each match drafted/serial 16/16; all four arms match the earlier 0.6.1-based replies 16/16 each. Default vs exact differs in 6/16.
    • Exported test logs record 72 CPU-side passes and 1 skip; 22 GPU test files contain passes, one is entirely skipped, and two fail (test_build, test_logprobs, disclosed below). Switch check reports 14/14 weights wired both ways; test_gdn passes 44/44.
    • The close receipt records the model server active with HTTP health 200 and the room agent active at 12:03 UTC.
    • Receipts: fast-default-rerun/v062/SHAS.txt, summary.txt, per-file logs, four v062-*.json reply files, conflict/range diffs and window-receipt.txt. Raw reply comparisons were independently checked by codexmb.
  • Earlier 0.6.1-based fast-default rerun (2 Oct, Strix, 09:06–10:01 UTC):
    • Default and TENSORFOLD_GGUF_FAST=0 each produce identical drafted/serial replies in 16/16 cases (8 greedy, 8 seeded).
    • All four reply files match the corresponding earlier opt-in/exact files, 16/16 each. Default versus exact differs in 6/16 cases, confirming the switch changes the path.
    • Real-weight switch check: 14/14 GGUF weights wired both ways.
    • The full rerun used tree 3197181 (the initial fast-default change on 954bb9f), not final head 1c11bd6. The final head changes only check-script environment cleanup and the PTX-only test mark. The GPU switch check and end-to-end runs were not repeated after those two changes.
    • Of 25 GPU test files in that rerun, 21 contained passing tests, one was entirely skipped (test_qwen27_server_errors), and three failed (test_qmm, test_build, test_logprobs). The final-head follow-up reports test_qmm: 6 passed, 15 skipped, 0 failed; GGUF/packaging/capacity tests: 62 passed. test_build and test_logprobs remain outside this port's supported scope.
    • The window-close receipt reports the M5 model server active with HTTP health 200 and the room agent active.
    • Receipts available: fast-default-rerun/README.txt, fd-run.sh, summary.txt, per-file pytest/serve logs, and all four fd-*.json reply files. Raw reply comparisons were independently checked by codexmb.

Known open issue (not fixed here)

The MLX checkpoint on AMD: drafted replies can differ from serial.

  • Cause: decode picks gemv (no drafts) or gemm16 (drafts) for the whole run, and the two round differently.
  • TF_ROCM_DECODE_KERNEL=gemm16 restores equality (8/8 + 8/8), but halves serial decode (9.0 -> 4.5 tok/s).
  • A proper fix needs gemv to produce gemm16's bits, or the reverse. Your preferred direction?

Not covered

  • Flash Next (qwen4_exp) on ROCm: test_build reaches the unported Flash Next gdn_io.cu build.
  • test_logprobs: a bare-PyTorch reproduction on torch 2.9.1+rocm7.13 (gfx1151), seed 1234, shows integer topk(k=20) returning index == row width (out of range) at 13 checked int64 widths between 21 and 47 (45 matched). The test's vocabulary width 31 is affected, and its following gather faults. Widths 1025 and 131073 matched CPU in this check; this does not establish general large-vocabulary safety. Our static import search found tensorfold.cuda.logprobs.capture imported only by qwen4_exp decode/multi; that is not a proven call graph. Not fixed here. Receipts: rocm-topk-repro.py, rocm-topk-repro.out, test_logprobs-isolated.out. These failures are disclosed, not counted as passing tests.
  • A drafted server on a GGUF with a float head (we have no such checkpoint).
  • Repeated-run speed statistics.
  • Sanitizer-level memory safety beyond the tested shapes.
  • Full JSON-schema conformance in tools/gguf_validate.py: its check covers parsing and required keys only. That script also needs a nonzero exit for failed boolean checks; its exit code alone is not a validation gate.

Packaging note

On ROCm, torch's JIT build writes hipified copies inside the package tree. A read-only install would fail on first
use; this is torch behaviour, not this PR.

Tested and written by petrus's agents (claudemb; reviewed by codexmb).

@ashhart

ashhart commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Thanks for the ROCm port. 0.6.0 goes out tonight and has moved a lot underneath it, so we'll do the rebase ourselves in 0.6.1, keeping your commits, together with @jkuepker's ROCm work (#100) and bf16 as the prompt default. Strix Halo support for the 27B, including exact GGUF projections, comes with that.

@jkuepker

jkuepker commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Since 0.6.1 will carry #144 and #100 together, here are three things we found comparing them, for the merge:

  1. topk ties: keep ROCm (Strix Halo) support for Qwen3.8-27B, with fast GGUF prompts on by default #144's top_by_value_then_id. It covers the sampler, the drafter and the two-rank split. feat: Qwen3.8-27B on AMD GPUs (ROCm), measured on a Radeon AI PRO R9700 #100 fixed only the drafter's 16 candidates (3cd3dc0) and never touched sampling.py, so seeded sampled requests on the R9700 can likely hit the drafted-vs-serial mismatch ROCm (Strix Halo) support for Qwen3.8-27B, with fast GGUF prompts on by default #144 found on gfx1151. We haven't reproduced it there, but the merged tree should take ROCm (Strix Halo) support for Qwen3.8-27B, with fast GGUF prompts on by default #144's fix and drop ours.

  2. feat: Qwen3.8-27B on AMD GPUs (ROCm), measured on a Radeon AI PRO R9700 #100's matrix-core kernels are gfx12-only, so pick kernels by architecture. qmm_rocm.cu and attention_rocm.cu use __builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12, and feat: Qwen3.8-27B on AMD GPUs (ROCm), measured on a Radeon AI PRO R9700 #100 makes them the default on every HIP device. A small test file using that builtin compiles for gfx1201 and fails for gfx1151 (hipcc, ROCm 7.14):

    error: '__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12' needs target feature wmma-128b-insts,wavefrontsize32
    

    So on Strix Halo, feat: Qwen3.8-27B on AMD GPUs (ROCm), measured on a Radeon AI PRO R9700 #100's defaults would fail to build unless TF_ROCM_LANE, TF_ROCM_ATTN_KERNEL and TF_ROCM_TREE_KERNEL are all triton. Suggested rule: feat: Qwen3.8-27B on AMD GPUs (ROCm), measured on a Radeon AI PRO R9700 #100's WMMA kernels on gfx12, ROCm (Strix Halo) support for Qwen3.8-27B, with fast GGUF prompts on by default #144's qgemv and Triton attention on everything else.

  3. FP8 is gfx12-only too. feat: Qwen3.8-27B on AMD GPUs (ROCm), measured on a Radeon AI PRO R9700 #100's FP8 prompt path (prefill_matmul8) fits 0.6.0's --prefill-fp8 as the opt-in, with bf16 as the default, as ROCm (Strix Halo) support for Qwen3.8-27B, with fast GGUF prompts on by default #144 already does. RDNA3.5 has no FP8 matrix instructions, so --prefill-fp8 and feat: Qwen3.8-27B on AMD GPUs (ROCm), measured on a Radeon AI PRO R9700 #100's --kv-dtype fp8 should be refused below gfx12.

Most of the rest is the same fix done twice under different names: the GDN lane masks and bf16 rounding, the guard around the PTX-only qmm_v3, and keeping the stored weight layout on ROCm. Either version works. GGUF (#144) and the RAM tier, FP8 KV caches and WMMA attention (#100/#106) don't overlap.

We're happy to run the merged tree on the R9700 the day it's up; @ThinkOffApp could cover gfx1151.

@ThinkOffApp

ThinkOffApp commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @jkuepker, agreed on all three. On gfx12 (checked via gcnArchName), use WMMA and allow FP8 (prefill and --kv-dtype fp8). On every other GPU, default to qgemv and Triton attention, and refuse the FP8 flags with a clear error. Please keep top_by_value_then_id for the sampler, drafter and split. We'll run the merged 0.6.1 tree on gfx1151 (Strix Halo) the day it's up: tests, drafted == serial including seeded sampling, and GGUF speed.

@ThinkOffApp
ThinkOffApp marked this pull request as ready for review October 2, 2026 08:54
@ThinkOffApp ThinkOffApp changed the title ROCm (Strix Halo) support for the Qwen3.8-27B CUDA path, and exact GGUF projections on Gufo's kernels ROCm (Strix Halo) support for Qwen3.8-27B, with fast GGUF prompts on by default Oct 2, 2026
millaguie added a commit to millaguie/TensorFold that referenced this pull request Oct 2, 2026
…serves FP8 prompts

The merged fast_prefill refused FP8 prompts on every ROCm GPU (ashhart#144 has no FP8 prompt kernel), which also refused
gfx12's, measured at 2,360 tok/s against bf16's 1,599 on an R9700.

Claude-Session: https://claude.ai/code/session_0177FjqB2W7svyUf7deveRJg
millaguie added a commit to millaguie/TensorFold that referenced this pull request Oct 2, 2026
…serves FP8 prompts

The merged fast_prefill refused FP8 prompts on every ROCm GPU (ashhart#144 has no FP8 prompt kernel), which also refused
gfx12's: jkuepker measured his 2,360 tok/s prefill on an R9700 with it.

Claude-Session: https://claude.ai/code/session_0177FjqB2W7svyUf7deveRJg
@jkuepker

jkuepker commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

We stacked #100 on this PR's head (4e96ba5), following the rule agreed above: https://github.com/jkuepker/TensorFold/tree/rocm-144 (15 commits on top; this PR's commits are unchanged).

On the R9700 (gfx1201, torch 2.11 + ROCm 7.14) the branch passes the 27B and ROCm kernel tests in tests/cuda (354 passed). The EXL3 and NVFP4 test modules build NVIDIA-only extensions, so they now skip on ROCm. Served with DFlash2, drafted replies equal "draft": false replies at bf16 and with --prefill-fp8, and the window is 169,624 tokens on 32 GB. Prompts fill at 1,740 / 1,550 / 1,391 tok/s at bf16 and 2,245 / 1,976 / 1,714 with FP8 (marginal, at 4k / 16k / 30k tokens).

One thing for you: on this PR's own head, tests/cuda/test_qwen27_server_errors.py aborts the process on gfx1201 (exit 139, inside tree_forward via draft_decode), also when it runs alone. On rocm-144, gfx12 takes the WMMA path and the test passes. Could you run rocm-144 on gfx1151 (tests, drafted == serial, GGUF) when you have a moment? That side is untested here.

@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Thanks @jkuepker doing the run you suggested now.

@ThinkOffApp

ThinkOffApp commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

@jkuepker Thanks for stacking #100 on our head. Here are the gfx1151 results run on our Strix Halo and compared file by file on the same box.

On gfx1151 the 27B path is unchanged. Every output of our frozen 192-output bit gate is bit-identical. Replies match our head 8/8, both serial and drafted, greedy and seeded, and drafted equals serial in both modes. Speed on the Qwen3.8-27B GGUF with default settings is within 2% on the same harness earlier today. An 8,651-token prompt reads at 197.2 tok/s serial and 192.4 drafted (193.0 and 191.3 before). Decode is 10.6 tok/s serial (10.5 before), and 25.8, 35.6, 17.9 and 27.9 tok/s drafted for short, code, story and long-document prompts (25.4, 35.2, 17.6 and 27.6 before). test_qwen27_server_errors, the test that aborts on your gfx1201 passes on gfx1151.

The only differences are tests that #100 added for gfx12, which run on gfx1151 instead of skipping. Everything else fails the same way on both branches, so none of it comes from #100. The logs, receipts and scripts are on our Strix, and we're happy to share any of them.

@ashhart

ashhart commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Thank you, @ThinkOffApp. We want this in. It lands as an experimental ROCm backend for Strix Halo, under your name, once it passes the same gates as our CUDA and Metal engines. We have no Strix Halo here, so the receipts have to come from yours:

  1. drafted replies identical to one-token decoding of the same prompts;
  2. a resumed conversation identical to the fresh run it replays;
  3. concurrent requests identical to each one run alone.

One change: GGUF fast prompts stay off by default unless their output matches the native path bit for bit. If they match, post that run too and they can default on. Paste the commands, versions and outputs here, and we will port it with your commits first.

@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Thank you, @ashhart. All three gates pass on our Strix Halo (gfx1151) for the Qwen3.8-27B GGUF and the MLX 4-bit, both with DFlash2, on 4e96ba5 plus one new commit that makes GGUF fast prompts opt-in. Each reply was compared by its token_sha and its full text.

Drafted vs one-token decoding ("draft": false): 14/14 identical per model, greedy and seeded. A resumed three-turn conversation vs the same final turn on a freshly started server: 2/2. Eight requests at once on a fresh --parallel 8 server vs each run alone: 8/8, with nothing cached and the requests decoding together.

GGUF fast prompts do not match the native path bit for bit (18 of 28 replies identical), so the new commit turns them off by default; TENSORFOLD_GGUF_FAST=1 turns them on.

Versions: TensorFold 0.6.2 at 4e96ba5, torch 2.9.1+rocm7.13.0, Triton 3.5.1. Server: python -m tensorfold serve --backend cuda --drafter --context 16384 --no-thinking (plus --parallel 8 for the concurrency run). The client script and its output are below.

@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Script and output referred to above. The run was on 4e96ba5 + 9ef7977 (now pushed to this PR).

gates.py and the comparison output
"""Ash's three #144 gates against a running TensorFold server: python gates.py PORT OUT.json MODE...

MODE g1: each prompt drafted and with "draft": false (one token a round), greedy and seeded.
MODE g2a: a 3-turn conversation on this server (turns 2 and 3 resume from the prompt cache).
MODE g2b: only the 3rd turn's full request (from G2A_JSON), sent to a freshly started server (nothing cached).
MODE g3: each prompt alone, then all of them at once.
MODE g3a / g3c: only the alone half / only the all-at-once half (run g3c on a fresh server so nothing is cached).
Every reply is recorded with the server's token_sha (hash of the reply's token ids) and its cached_tokens.
"""
import concurrent.futures as cf
import json
import sys
import urllib.request

port, out_path, modes = sys.argv[1], sys.argv[2], sys.argv[3:]
URL = f"http://127.0.0.1:{port}/v1/chat/completions"


def find(d, key):
    if isinstance(d, dict):
        if key in d:
            return d[key]
        for v in d.values():
            r = find(v, key)
            if r is not None:
                return r
    return None


def ask(messages, n=96, **kw):
    body = {"model": "m", "messages": messages, "max_tokens": n, "temperature": 0}
    body.update(kw)
    r = urllib.request.Request(URL, json.dumps(body).encode(), {"Content-Type": "application/json"})
    d = json.load(urllib.request.urlopen(r, timeout=3600))
    return {"sha": find(d, "token_sha"), "cached": find(d, "cached_tokens"), "drafts": find(d, "drafts"),
            "tokens": d["usage"]["completion_tokens"], "prompt_tokens": d["usage"]["prompt_tokens"],
            "text": d["choices"][0]["message"]["content"]}


facts = ["Rivers carve valleys over millions of years as water erodes rock and carries sediment downstream. ",
         "Early computers used vacuum tubes that failed often and filled entire rooms with heat and noise. "]
P = {"short": "In three sentences, explain why the sky is blue.",
     "code": "Write a Python LRU cache class with get and put.",
     "story": "Write a short story about a lighthouse keeper.",
     "math": "Explain step by step how to compute 17 times 23.",
     "list": "List ten tips for learning a new language.",
     "long3k": "Summarize these notes:\n\n" + "".join(f"({i}) " + facts[0] for i in range(150)),
     "long5k": "What patterns do you see?\n\n" + "".join(f"({i}) " + facts[1] for i in range(260))}
SEEDED = {"temperature": 0.8, "top_p": 0.95, "seed": 4242}
TURNS = ["I am planning a three-day trip to Helsinki in October. Suggest a rough plan.",
         "Make day two more about design and architecture.",
         "Now turn the whole plan into a short packing list."]

out = {}
for mode in modes:
    if mode == "g1":
        for k, p in P.items():
            m = [{"role": "user", "content": p}]
            for s, kw in (("greedy", {}), ("seeded", SEEDED)):
                out[f"g1/{k}/{s}/drafted"] = ask(m, **kw)
                out[f"g1/{k}/{s}/oneToken"] = ask(m, draft=False, **kw)
    elif mode == "g2a":
        for s, kw in (("greedy", {}), ("seeded", SEEDED)):
            msgs = []
            for i, t in enumerate(TURNS):
                msgs.append({"role": "user", "content": t})
                r = ask(msgs, n=160, **kw)
                out[f"g2a/{s}/turn{i + 1}"] = r
                msgs.append({"role": "assistant", "content": r["text"]})
            out[f"g2a/{s}/messages"] = msgs
    elif mode == "g2b":
        prev = json.load(open(__import__("os").environ["G2A_JSON"]))
        for s, kw in (("greedy", {}), ("seeded", SEEDED)):
            out[f"g2b/{s}/turn3"] = ask(prev[f"g2a/{s}/messages"][:-1], n=160, **kw)
    elif mode in ("g3", "g3a", "g3c"):
        cases = [(k, s, kw) for k in ("short", "code", "story", "long3k") for s, kw in (("greedy", {}), ("seeded", SEEDED))]
        for k, s, kw in cases if mode != "g3c" else []:
            out[f"g3/{k}/{s}/alone"] = ask([{"role": "user", "content": P[k]}], **kw)
        if mode != "g3a":
            with cf.ThreadPoolExecutor(len(cases)) as ex:
                futs = {(k, s): ex.submit(ask, [{"role": "user", "content": P[k]}], **kw) for k, s, kw in cases}
                for (k, s), f in futs.items():
                    out[f"g3/{k}/{s}/concurrent"] = f.result()
    json.dump(out, open(out_path, "w"), indent=1)
print(out_path, "done", len(out))
gguf gate 1, drafted vs one-token (draft:false): 14/14 identical
gguf gate 1: drafts actually on in 14/14 drafted replies; tokens 2434
gguf gate 2, resumed turn 3 vs fresh server: 2/2 identical
gguf gate 2 greedy: cached tokens resumed turn2=29 turn3=212 (prompt 398), fresh turn3=0
gguf gate 2 seeded: cached tokens resumed turn2=29 turn3=212 (prompt 398), fresh turn3=0
mlx gate 1, drafted vs one-token (draft:false): 14/14 identical
mlx gate 1: drafts actually on in 14/14 drafted replies; tokens 2346
mlx gate 2, resumed turn 3 vs fresh server: 2/2 identical
mlx gate 2 greedy: cached tokens resumed turn2=29 turn3=212 (prompt 398), fresh turn3=0
mlx gate 2 seeded: cached tokens resumed turn2=29 turn3=212 (prompt 397), fresh turn3=0
gguf TENSORFOLD_GGUF_FAST=1 vs default (exact): 18/28 replies token-identical
gguf FAST=1 gate 1, drafted vs one-token: 14/14 identical
gguf gate 3 (--parallel 8, fresh server for the concurrent half): 8/8 identical  | cached on concurrent: [0]
mlx gate 3 (--parallel 8, fresh server for the concurrent half): 8/8 identical  | cached on concurrent: [0]
text-identical too: gguf g1 14/14, g2 2/2, g3 8/8; mlx g1 14/14, g2 2/2, g3 8/8

claude and others added 12 commits October 3, 2026 23:12
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 084785a1500ff5248f1cbcbdfa2e274a6cebc752)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 4ac9bf4505941dfd9ee609d6a24aa72b990b5c21)
…N kernels

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit daa29356b4e769d390d93ad5344e94e97c0063ee)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit dda994c7d9ea3b7171ed8c08166bca014a4fe7b1)
… rows

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 73fb90acc9163f0a743e8e1c3cc9969eb1f9b547)
…l a run

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 20a000fad0083e7fecffe8db9e116be10ae0e6ae)
…n-negative halves)

On AMD matrix cores a masked key's +0 weight times a negative v gives -0, and those zero products did not sum
alike, so a row's bits depended on whether its chunk loaded the keys past it (test_prefill_attention_rows_do_not_
depend_on_chunking[24-4-256], chunk size 1). Found by @codexmb's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 8ebd8a46bee9b1783883c9f955b0a301f582ac30)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 29203e90942327124ca81b4c337a9b8b823e51b8)
…sert the ROCm layout and skip sm_90-only kernels

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 92433e949750d73167011721893318bc0148d65c)
…ed, MIT) and a Qwen3.5 GGUF loader

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit a4f52128c440c0f1637034cee5821760048211c7)
…dding rows, fp64 CPU reference check

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit d49a3f931130f309e98b132569944fd39c67b151)
…; check every row count and fail on gaps

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 55d97de834f98ae601786b1974ea3b51c46bb17e)
ThinkOffApp and others added 8 commits October 3, 2026 23:12
…st, mismatch bisection

The 39264ef guard sweep on Strix had zero faults but 335 MISMATCH lines. The weight
upload, slack fill and y readback went through hipMemcpy/hipMemset on HIP's null
stream, outside torch's ordering. Every fill, copy and compare of guarded memory
is now a torch op on a __cuda_array_interface__ view of the mapping, with a sync
after each step. The guarded weight must equal the original byte for byte before
any kernel runs (WEIGHT-COPY-BAD, exit 3). Each case also runs the ctypes call on
ordinary torch buffers (CTYPES-MISMATCH separates harness from placement). y is
prefilled with a NaN marker to count unwritten outputs. On a guarded mismatch the
case reruns with one guarded buffer at a time (q8 / y / w) and prints which one
changes the output, the differing count, the first (tok, col) and max |diff|.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ails closed, run log + identity

From Codex's review of 99cbbeb (guard run 2 PASS on gfx1151):
- The child prints CASE-START right before the guarded launch and CASE-DONE after
  its sync. A child death counts as FAULT only after CASE-START with no CASE-DONE
  and a GPU memory-fault signature ("Memory access fault by GPU" with return code -6
  or 134, or hipErrorIllegalAddress / "illegal memory access"). Any other death
  (build, VMM setup, assert) is INCONCLUSIVE. A negative control that is not a clean
  FAULT stops the run as INCONCLUSIVE.
- The 6-tile positive control's result now feeds the verdict. Before this it was
  printed and then dropped.
- Every child's command, return code, stdout and stderr goes to a per-run log
  (logs/bounds/guard-<time>.log, --log). The header records the tree rev, dirty
  flag, torch/HIP versions, device and gcnArchName, the libtfgguf path, the Gufo
  revision and kSlackTiles.
- The final line is PASS / FAIL / INCONCLUSIVE, exiting 0 / 1 / 2.

Classification checked on CPU with stubbed children: fault, illegal-address,
build failure, a death after CASE-DONE, the fault text with exit 1, clean, mismatch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the span rows

A GGUF that keeps output.weight (or a tied token_embd) in F16/BF16/F32 loads it as Plain; the drafter's head setup
special-cased NVFP4, Gguf and Exl3 and otherwise read head.scales/head.biases, which Plain lacks. The sub-head now
takes the span rows (b16 computes each output column alone, so each logit keeps the target's bits). One GPU only,
as for the other non-MLX heads. Review: codexmb.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p sources

On a ROCm box the JIT build writes hipified copies inside the source tree, with a cuda folder of the path renamed
hip (cuda/kernels/gdn.cu -> hip/kernels/gdn.cpp, qwen3_5/cuda/b16.cu -> qwen3_5/hip/b16.hip). The test read them
as unshipped sources and failed on the Strix tree only. A file is skipped only when its cuda-path twin exists, so
the vendored Gufo hip/ tree still counts (and removing its package-data line still fails the test: 20 missing).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s build

GGUF detection and loading are a format extension with no HIP gate of their own; on NVIDIA a GGUF directory would
reach the Gufo build and fail in hipcc terms. Engine admission now says GGUF runs on AMD (ROCm) and names the
NVIDIA checkpoints. Test: refusal on HIP=False, no refusal on HIP=True; it fails with the check removed. Review: codexmb.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o turn them off

Prompt reading on Strix (27B UD-Q4_K_XL, 8,651-token prompt) goes from 78 to 193 tok/s; answering speed is the same
and drafted replies still match serial ones (16/16). Prompt rows no longer share decode's bits, so wording can differ
from the exact route, as prompt and answer kernels already differ on NVIDIA. NVIDIA is untouched (HIP gate).
gguf_fast_prefill_check now checks the switch both ways: unset gives the fast bits, 0 the exact ones.
Test: tests/test_gguf_fast_default.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ROCm)

It came in with ashhart#134 after this PR's ROCm skips; it calls qmm.matmul, which raises on HIP by design. On the Strix it
was the only failing GPU-side test file (2 failed), on 0.6.0 and on 0.6.1 alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Gufo's WMMA W8A8 prompt GEMM and decode GEMV give different bits from the
exact kernel, so by default every row count now stays on the exact kernel and
prompts match the native path bit for bit. TENSORFOLD_GGUF_FAST=1 turns the
fast routes back on (ROCm only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ge programs

527a6a8's grouped fold keeps serial bits only if every program rounds the
shared fp32 fold the same way. On gfx1151 the compiler contracted it into FMAs
differently per kernel, so test_rows_crossing_a_group_edge_match_serial_bits
(4 cases) and test_folded_groups_and_scalar_merge_are_bit_equal failed.
With enable_fp_fusion=False on HIP, tests/cuda/test_attention.py passes 50/50.
NVIDIA launches are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Rebased onto 0.6.5 (609ca41); the head is now 5203508, and the three gates were re-run on exactly that tree on our Strix Halo (gfx1151), GGUF and MLX 27B, same method as the earlier run.

Drafted vs one-token decoding: 14/14 per model. Resumed conversation vs a fresh server: 2/2. Eight concurrent requests on a fresh --parallel 8 server vs each alone: 8/8. Every reply matched on both token_sha and full text.

One fix came with the rebase: 0.6.5's grouped tree-attention fold (527a6a8) lost serial bits on gfx1151 for rows crossing a group edge (5 tests in test_attention.py), because AMD's compiler fused the shared fp32 fold into FMAs differently in each program. Commit 5203508 sets enable_fp_fusion=False on those three launches on ROCm only; test_attention.py now passes 50/50, and your new test_a_long_prompt_tree_window_equals_serial_on_every_path passes without needing an sm_90 skip. NVIDIA launches are unchanged.

On GGUF fast prompts: we have not re-measured the fast-vs-exact comparison on this base, so the 18 of 28 result from 4e96ba5 is the last real number we have and the commit still leaves them off by default. We will post the re-run on 5203508 rather than carry that figure forward as if it were fresh.

Versions for this run: TensorFold 0.6.5 at 5203508. The server invocation and the client script are unchanged from the earlier comments, so gates.py there is what produced these.

@millaguie

Copy link
Copy Markdown
Contributor

Thanks for #144. I tried its current head (5203508) on a Radeon AI PRO R9700 (gfx1201, RDNA4, 32 GB), in case the result helps.

On that card, the first decode request never finishes. The GPU stays at 100 % busy but under 90 W, as if a kernel were spinning, and no reply arrives. It happened with the default flags (I stopped it after 10 minutes) and with --parallel 3 (37 minutes). Killing the server frees the card without a reset.

  • Checkpoint: Vontra/Qwen3.8-27B-MLX-4bit with z-lab/Qwen3.8-27B-DFlash2
  • PyTorch 2.12.0+rocm7.14, kernel 7.1.13
  • Command: python3 -m tensorfold serve <mlx-dir> --drafter <dflash2-dir> --port 8100, then one chat request with max_tokens 256

An earlier version of your commits, which I carry in a fork on top of 0.6.2, does not hang on the same card. So it may come from a later commit, or from how that commit meets gfx1201, not from Strix Halo. I can bisect it on the R9700 if that's useful. I wrote up the gfx1201 side in #412.

@ThinkOffApp

ThinkOffApp commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for running it and for the careful report. #144 was developed and gated on gfx1151 (Strix Halo) only; we have no gfx12 card, so we cannot reproduce this here, and we have not seen the hang on gfx1151.

It may be related to what @jkuepker reported above on 2 Oct: on this PR's own head, gfx1201 aborts inside tree_forward via draft_decode, and the rule we agreed there is that gfx12 takes #100's WMMA kernels while this PR's path covers the other AMD GPUs. His rocm-144 branch does that and passes on the R9700.

Two things that would narrow it quickly, if you have a moment:

  1. The same request with "draft": false, or the server started with --no-drafts. If that completes, the hang is in the drafter / tree path.
  2. Which commit your working fork is based on. Of this PR's 33 commits, the tree attention change at the head (5203508) and the b16 lane-mask change (dc849e3) are the two I would try first.

A bisect on the R9700 would be very welcome, yes. We will take any fix that keeps gfx1151 bit-identical, and we can run the gfx1151 side of anything you find.

@millaguie

Copy link
Copy Markdown
Contributor

Thanks, that explains it. I ran your two checks on the R9700 with the current head (5203508) and the same MLX 4-bit checkpoint:

  • drafter loaded, request with "draft": false: the first token fails in top_by_value_then_id (shape '[1, 28]' is invalid for input of size 0), so no candidate passes the filter and the logits are not finite.
  • server started with --no-drafts: same error, same place.

So on gfx1201 it is not the drafter. The target forward in this PR's own path gives non finite logits, and with drafts that probably keeps the verify loop spinning.

About the base: my fork has this PR up to 4e96ba5 (423d52b in your rebased branch, it includes dc849e3) with #100 on top, the same as @jkuepker's rocm-144. On gfx12 it takes #100's WMMA kernels and never runs this path, that is why it doesn't hang. It's not a commit in between, so I don't think a bisect adds anything. Sorry for the noise, I missed the gfx12 rule you agreed above.

@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Thanks, that settles it, and it was not noise: it shows a real gap in this PR. On gfx12 without #100, this path produces non-finite logits and the server spins instead of failing. We will add a check so that on gfx12 this path stops at startup with a message pointing to #100's WMMA kernels, and gfx1151 stays bit-identical. We will post here when it is pushed.

On gfx1201 (RDNA4) this path's forward gives non-finite logits; with drafts the verify loop
then never returns (reported on ashhart#144 with an R9700). gfx12 runs on ashhart#100's WMMA kernels, so
this path now stops at startup there with a message that says so. Nothing changes on gfx1151.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ThinkOffApp

ThinkOffApp commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Pushed in 88417d3: on gfx12 this path now stops at startup with a message pointing to #100's WMMA kernels, instead of hanging. It refuses every format on gfx12, MLX and GGUF alike. #144 on its own is only tested on gfx1151, and the tree path that aborted on gfx1201 is shared by all formats. We have no GGUF result on gfx12 either way. Nothing changes on gfx1151: the head before and after this commit both match our 28-case answer key (token hash, text and token count), with identical tokens in all 28. Thanks again for running the checks.

@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @ThinkOffApp. This is a long, careful port, honest down to the 6 of 16 replies where the fast GGUF route differs from the exact one. The Python engine is frozen (#286) and new work goes into the Zig engine, so this won't land as written.

On the Zig engine it waits for a ROCm backend, the Qwen3.8-27B family and a GGUF reader. Your Zig HIP plan in #426 is where that backend starts. When ROCm comes, your HIP fixes carry over with your credit: 64-bit lane masks, HIP's bf16 rounding, and no FMA contraction in tree attention.

Two rules come with it. We write our kernels in our own code rather than vendor Gufo's, and a speed feature can't change the reply, so the Q8_1 prompt route stays out. On gemv versus gemm16, we take the row-exact direction, where a window's rows reproduce the one-row bits.

@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Thanks Ash, that makes sense, and thank you for keeping the HIP fixes with credit.

We will continue the ROCm work on the Zig engine under #426. The kernels will be our own code, with nothing from Gufo, and the Q8_1 prompt route stays out, since a speed feature must not change the reply. On gemv versus gemm16 we take the row-exact direction, so a window's rows reproduce the one-row bits.

#144 stays as the reference for gfx1151: the 28-case answer key and the 6-of-16 difference on the fast GGUF route. In #426, matching that answer key bit for bit is the acceptance gate for the ROCm backend.

millaguie added a commit to millaguie/TensorFold that referenced this pull request Oct 10, 2026
…serves FP8 prompts

The merged fast_prefill refused FP8 prompts on every ROCm GPU (ashhart#144 has no FP8 prompt kernel), which also refused
gfx12's: jkuepker measured his 2,360 tok/s prefill on an R9700 with it.
@yijunyu

yijunyu commented Oct 11, 2026

Copy link
Copy Markdown

Tested the PR's GGUF Q8_0 and K-quant prefill on a Radeon 8060S (gfx1151, ROCm 10 / torch 2.11.0+rocm10.0.0). Two findings:

  1. Build: vendor/.../prefill_quant_wave64.hip and the WaveSize == 64 branch of WmmaQuant in prefill_quant_gemm.hpp call __builtin_amdgcn_wmma_i32_16x16x16_iu8_w64, which needs wmma-256b-insts,wavefrontsize64. gfx1151 does not have that feature, so libtfgguf.so does not compile for gfx1151 as written. (Compiling with a trap guard on that branch shows the wave64 route is reached at runtime, not just compiled.)

  2. Runtime: TryLaunchQuantPrefillWave64 is taken for batch >= 96 and m, k >= 1024 for Q4_K, Q5_K, Q6_K and Q8_0. On gfx1151 that launch raises HSA_STATUS_ERROR_EXCEPTION (WKQuantA8BlockedWmmaGEMMKernel<128,128,2,...,64>).

Local workaround that makes it run (not a proposed fix, just what I tested): return false at the top of TryLaunchQuantPrefillWave64. Then Q4_K/Q6_K use the existing wave32 LaunchKQuantWmmaGEMM and Q8_0 uses W8A8BlockedWmmaGEMMKernel.

Results with that change, on real tensors from Qwen3.8-27B-UD-Q4_K_XL.gguf and Qwen3.8-27B-Q8_0.gguf (CPU dequant reference):

  • linear (fp path): rel err 1e-7 to 6e-7 for Q4_K, Q6_K and Q8_0.
  • prefill_linear (Q8_1 activations): rel err 3e-3 to 8e-3.
  • The PR's tests/test_gguf_*.py (12 tests) pass.

Not covered: Q5_K and Q3_K tensors. The PR's TryLaunchQuantPrefillWave64 is the route that needs a gfx1151-capable kernel, so a real fix would need either a wave32 WMMA variant or a gfx1151-specific guard.

@yijunyu

yijunyu commented Oct 11, 2026

Copy link
Copy Markdown

Correction to my earlier comment: the workaround there (returning false from TryLaunchQuantPrefillWave64 for every GPU) was broader than needed. It would also have turned off the wave64 route on GPUs that have wave64 WMMA. The version below only skips that route on gfx1151.

Patch (applies to 88417d3): prefill_quant_wave64.hip checks hipDeviceProp_t::gcnArchName at run time and returns false when it contains gfx1151. The guard is a runtime check because __gfx1151__ is defined only in the device pass, and the launch code runs on the host. WmmaQuant's wave64 branch gets a __builtin_trap() under __gfx1151__, so the wave64 intrinsic is not compiled for gfx1151. Nothing changes for other targets.

Tested on Radeon 8060S (gfx1151, ROCm 10, torch 2.11.0+rocm10.0.0), against CPU dequant references, using real tensors from Qwen3.8-27B-UD-Q4_K_XL.gguf and Qwen3.8-27B-Q8_0.gguf:

  • linear (fp path): rel error 1e-7 to 7e-7 for Q4_K, Q5_K, Q6_K, IQ4_XS and Q8_0, at 1 to 256 rows.
  • prefill_linear (Q8_1 activations): rel error 3e-3 to 8e-3.
  • The PR's tests/test_gguf_*.py (12 tests) pass.

Not tested: Q3_K tensors (3 in the Q4_K_XL file), and any wave64-WMMA GPU (none here). The guard's effect on those targets is unverified.

@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Thanks @yijunyu, for the report and for narrowing the guard. Skipping the wave64 route only when gcnArchName says gfx1151 is the right shape: GPUs that have wave64 WMMA keep it, and the trap under __gfx1151__ keeps the intrinsic out of that device pass.

This PR was closed on 6 Oct when the AMD work moved to the native Zig engine (#463, in 1.0.5; the model slices are planned in #490/#491), so it won't merge here. The branch still exists (ThinkOffApp:strix-rocm-gguf at 88417d3, the commit your patch applies to) but not aware if anyone would be continuing development on the old platform.

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.

6 participants