Skip to content

Upstream PR: H3 Metal fc1 in int8 on the tensor units - #4989

Open
plotarmordev wants to merge 7 commits into
ashhart:mainfrom
plotarmordev:feat/109-upstream-pr-h3-metal-fc1-in-int8-on-the-
Open

plotarmordev wants to merge 7 commits into
ashhart:mainfrom
plotarmordev:feat/109-upstream-pr-h3-metal-fc1-in-int8-on-the-

Conversation

@plotarmordev

@plotarmordev plotarmordev commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
  • h3 image: fc1 in int8 with weight scales per 256 values of K
  • h3 image: the products and fc1's quantizer under the kernel contract
  • h3 image: int8 product, quantizer and decoder batches tested at a 2048 picture's geometry
  • h3 image: int8 fc1 for pictures only, a clip's fc1 bf16 as on main
  • h3 recipe: fc1's int8 product on the tensor units, measured
  • h3: port fixes on upstream's tree — the bind pass waits inline; the products' contract joins gemm_source
Before (int8-vs-bf16-2048) After (int8-vs-bf16-2048)
Before After

How to check

  • Base commit (main): 94e0f2dc274f1cbd63bde7cc343e47babb87cff3
  • Head commit: f5cf48ff71febb9742948b71312becbc0deee9a8
  • Machine: a Mac on Apple Silicon · macOS (Darwin arm64) · Zig 0.17.0, Python 3

Test results:

  • zig build compile-h3-host tf-kernel-contract -Dcpu=apple_m1 at a14263c09d96 (older head): 1 passed, 0 failed, 0 skipped
  • zig-out/bin/tf-kernel-contract --only "h3 product" (base 94e0f2dc2, scratch checkout) at 94e0f2dc274f (older head): 16 passed, 2 failed, 0 skipped
  • zig-out/bin/tf-kernel-contract --only "h3 product" at a14263c09d96 (older head): 31 passed, 2 failed, 0 skipped
  • zig build test-h3-image-server at a14263c09d96 (older head): 7 passed, 0 failed, 0 skipped
  • swarm scan . refs/swarm/upstream/ashhart/TensorFold/main..HEAD at a14263c09d96 (older head): 1 passed, 0 failed, 0 skipped
  • zig build test-h3-gemm test-h3-image-server at a14263c09d96 (older head): 46 passed, 0 failed, 0 skipped
  • zig build test test-golden at a14263c09d96 (older head): 6143 passed, 4 failed, 85 skipped
  • python3 tools/zig/lean_check.py (166 findings, all inherited; the gate is lean_new) at f5cf48ff71fe: 0 passed, 1 failed, 0 skipped
  • python3 tools/zig/lean_new.py lean-base.txt lean-head.txt (merge base 94e0f2dc274f1cbd63bde7cc343e47babb87cff3): 165 problems, 165 on the base, 0 new at f5cf48ff71fe: 1 passed, 0 failed, 0 skipped
  • python3 tools/pr_check.py --base origin/main --pr 4989 at f5cf48ff71fe: 1 passed, 0 failed, 0 skipped
  • zig fmt --check zig/src/families/h3/block.zig zig/src/families/h3/h3.zig zig/tests/contract/metal_h3_gemm.zig zig/tests/h3_image_decoder_selftest.zig zig/tests/h3_image_server.zig at f5cf48ff71fe: 1 passed, 0 failed, 0 skipped
  • swarm scan . origin/feat/109-upstream-pr-h3-metal-fc1-in-int8-on-the-..HEAD at f5cf48ff71fe: 1 passed, 0 failed, 0 skipped

Every block's fc1 rows are quantized once at bind into a private int8 copy, a scale per 256 values of K; each block
quantizes its normed rows a row and runs fc1 on h3_gemm_32x64_i8, folding each 256-deep block's int32 sums at the
weights' scales. The server joins the copy to its weights' residency set. A warm 2048 picture: 11.14 and 11.16 s
against 12.12 s in bf16; the picture holds card 80's rule (cosine 0.995344, 28.240 dB, mean 4.011, max 245).

(cherry picked from commit b07236c)
The limits runner joins gemm_nax's fragments ahead of h3_gemm.metal, as source.zig does at load.
h3_gemm_32x64 and its ragged form are gated bit-equal to the MLX gemm_nax they replaced; the int8 form
against float64 at its scales; h3_quantize_rows against its formula; each with its limits record.
The quantizer dropped NaN through max: a group holding one now takes a NaN scale.

(cherry picked from commit 653f88b)
…8 picture's geometry

(cherry picked from commit b5bd38a)
(cherry picked from commit a9bedf5, the
quantizer table and 11.14 s receipts of 5284846,
as one upstream section)
…roducts' contract joins gemm_source

The fork's finish() was inlined upstream in the give-way rework, so
quantizeFc1 waits cb and checks its failure the same way. Upstream keeps
the products in kernels.gemm_source, not .source: the limits runner's own
'h3 product' join already covers them (the duplicated cherry-picked branch
is dropped), and the suite's library() joins gemm_source beside .source as
source.zig does at load.
@plotarmordev

Copy link
Copy Markdown
Contributor Author

The zig job's lean findings are fixed on the new head: the h3 fc1 comments are one line each under 120 columns, so the checker reports 0 new problems over the merge base (165 inherited, unchanged). I also added the Unreleased changelog bullet naming this PR.

@AIFlowML

Copy link
Copy Markdown
Contributor

I tried the landing order main 4c79cfe346d3c239ff7dfd7aa694df799755bafa → #4909 2b60fd231ed25c40531af0ea4761d284f20fdee0 → this PR f5cf48ff71febb9742948b71312becbc0deee9a8. Both merges were clean. On the combined tree (M5 Max, Zig 0.17.0):

zig build test-h3-gemm test-h3-image-server test-h3-read-ahead \
  test-h3-image-decoder-load -Dcpu=apple_m1 --summary all

All 54 build steps and 16 tests passed: 3 GEMM, 9 image-server, 2 read-ahead and 2 decoder-load tests. That checks the server and loader fixtures with both H3 heads present. It does not cover the 2048-pixel checkpoint rendering or timing comparison.

Igor Lessio - AIFLOW LABS

This branch has not been deployed

No deployments
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