Skip to content

ggml-hrx: ADD_ID and SWIGLU_OAI on HRX (gpt-oss: 193 -> 49 graph splits) - #67

Merged
bong-water-water-bong merged 2 commits into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-gptoss-ops
Oct 2, 2026
Merged

bong-water-water-bong merged 2 commits into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-gptoss-ops

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Stacked on #66; it retargets to 1bit/hrx-vulkan-patched once #66 merges. Two gpt-oss ops that ran on the CPU in every layer now run on HRX, in our own files.

ADD_ID (gpt-oss expert biases, 3 per layer)

  • New files: ops/add_id_f32.loom and dispatch_registration/common/dispatch-add-id.cpp. output[t][r] = input[t][r] + bias[ids[t][r]]; ids are read through their row stride (llama.cpp passes a view of the argsort). An out-of-range id reads expert 0, so it can't read out of bounds.
  • Hook in AMD's file: GGML_OP_ADD_ID added to the eager capability list in ggml-hrx.cpp.
  • check.case against a one-workitem-per-value reference: width 300, 4 of 8 experts through a stride-8 ids view, 3 tokens. iree-test-loom --sanitizer=access gives exact results.
  • test-backend-ops ADD_ID: 6/6 on HRX, three runs. The 30 n_experts_used < n_experts cases report "not supported": test-backend-ops asks supports_op for the standalone I32 VIEW of ids, which HRX doesn't claim on its own. Inside a model graph the view is an alias and ADD_ID runs on HRX.

SWIGLU_OAI (gpt-oss clamped SwiGLU)

  • New files: ops/swiglu_oai_f32.loom and dispatch_registration/common/dispatch-swiglu-oai.cpp. Two contiguous inputs; x = min(gate, limit), y = clamp(up, -limit, limit), x / (1 + exp(-alpha x)) * (y + 1), as ggml-cpu.
  • Hook in AMD's files: GluParams gains alpha and limit (op_params 2 and 3, zero for the other GLU kinds). They're compared in glu_params_equivalent, so programs with different values aren't shared, and written to the diagnostics JSON.
  • check.case: 2050 values (partial last workgroup and vector), inputs beyond ±limit on both sides, against a reference, --sanitizer=access.
  • test-backend-ops SWIGLU_OAI: the 4 contiguous cases (alpha 0.5 / 1.702 × limit 2 / 7) pass; the 4 view cases are not supported.

gpt-oss-20b (MXFP4, HRX0, balanced power mode, this branch's build)

graph splits pp512 tg128
#66 193 527 ± 26 24.8 ± 0.5
+ ADD_ID 97 (noisy run) (noisy run)
+ SWIGLU_OAI 49 648.6 ± 23.7 29.3 ± 0.4

Greedy text is correct ("The sky appears blue because the Earth's atmosphere scatters sunlight..."). Full suite 1061/1061.

The rest of gpt-oss's CPU work is FLASH_ATTN_EXT with attention sinks (both HRX FA matchers require 4 inputs). That's next.

🤖 Generated with Claude Code

bong-water-water-bong and others added 2 commits October 2, 2026 09:11
ops/add_id_f32.loom + dispatch_registration/common/dispatch-add-id.cpp (ours): output[t][r] = input[t][r] +
bias[ids[t][r]], ids read through its row stride (llama.cpp passes a view of the argsort), an out-of-range id
reads expert 0. GGML_OP_ADD_ID joins the eager capability list in ggml-hrx.cpp. gpt-oss-20b graph splits
193 -> 97. check.case vs a one-workitem-per-value reference (iree-test-loom --sanitizer=access: exact).
test-backend-ops ADD_ID reports the n_experts_used < n_experts cases as not supported because the standalone
I32 VIEW of ids is not claimed on its own; inside a model graph the view is an alias and ADD_ID runs on HRX.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ops/swiglu_oai_f32.loom + dispatch_registration/common/dispatch-swiglu-oai.cpp (ours): two contiguous inputs,
x = min(gate, limit), y = clamp(up, -limit, limit), x / (1 + exp(-alpha x)) * (y + 1), as ggml-cpu. GluParams
carries alpha and limit (op_params 2 and 3), compared in glu_params_equivalent and kept in the diagnostics
JSON. check.case (2050 values, inputs past +-limit) vs a reference, --sanitizer=access. test-backend-ops
SWIGLU_OAI: the 4 contiguous cases (alpha 0.5 / 1.702, limit 2 / 7) OK, the 4 view cases not supported.
gpt-oss-20b graph splits 97 -> 49, pp512 648.6, tg128 29.3 tok/s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the ggml label Oct 2, 2026
@bong-water-water-bong
bong-water-water-bong changed the base branch from 1bit/hrx-mmid-g32-v2 to 1bit/hrx-vulkan-patched October 2, 2026 12:43
@bong-water-water-bong

Copy link
Copy Markdown
Author

Review (PR-Agent duty): approve.

  • Placement: ADD_ID and SWIGLU_OAI on F32 are in our own files: ops/add_id_f32.loom and ops/swiglu_oai_f32.loom, plus dispatch-add-id and dispatch-swiglu-oai, all with the full notice. AMD files get hooks only: ADD_ID in eager_capability_declared, and GluParams alpha/limit imported, compared and written to diagnostics.
  • SWIGLU_OAI math matches ggml_compute_forward_swiglu_oai_f32: x = min(gate, limit), y = clamp(up, ±limit), x·σ(αx)·(y+1). The matcher takes only the split (two-tensor) form, which ignores swapped on the CPU too, with F32, contiguous inputs and the same shapes.
  • Checks:
    • check.cases with random differentials, sanitizer clean;
    • test-backend-ops ADD_ID 6/6 x3, SWIGLU_OAI 4/4 contiguous;
    • full suite 1061/1061.
  • gpt-oss-20b (balanced mode): graph splits 193 -> 49, pp512 527 -> 649, tg128 24.8 -> 29.3, text correct.
  • CI: the Windows failures are the known test-thread-safety 0xc0000374 flake plus a cancelled job, all on Windows builds without HRX; re-running.

Merging when the hosted jobs pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant