Skip to content

fix(metal): rename test-local fp8_nblk to avoid quant.h collision - #945

Closed
gouravkargwal wants to merge 1 commit into
JustVugg:mainfrom
gouravkargwal:fix/metal-test-fp8-nblk
Closed

fix(metal): rename test-local fp8_nblk to avoid quant.h collision#945
gouravkargwal wants to merge 1 commit into
JustVugg:mainfrom
gouravkargwal:fix/metal-test-fp8-nblk

Conversation

@gouravkargwal

Copy link
Copy Markdown
Contributor

Fixes #940

The test file defined its own static int fp8_nblk while quant.h now provides static inline int64_t fp8_nblk. Same name and parameter list with different return types breaks compilation of the Metal test (make metal-test): "functions that differ only in their return type cannot be overloaded".

Renamed the test-local helper to ref_fp8_nblk. Header API and production behavior are untouched.

Reproduced and verified on Apple M3, 16 GB: make metal-test passes in full.

@gouravkargwal

Copy link
Copy Markdown
Contributor Author

Proof — reproduced and verified on Apple M3, 16 GB

Environment:

  • MacBook (Apple M3, 16 GB), macOS
  • Apple clang 17.0.0, Homebrew libomp
  • Commit: this branch (fix/metal-test-fp8-nblk)

Before the fix — exact failure of make metal-test:

tests/../quant.h:483:23: error: functions that differ only in their return type cannot be overloaded
tests/test_backend_metal.mm:99:12: note: previous definition is here

After the fix — full run below, exits 0. Note the FP8 grouped cases (the ones exercising the renamed helper) all pass:

@gouravkargwal

Copy link
Copy Markdown
Contributor Author

clang++ -x objective-c++ -std=gnu++17 -fobjc-arc -O3 tests/test_backend_metal.mm backend_metal.mm -framework Metal -framework Foundation -o backend_metal_test
./backend_metal_test
Metal backend kernel tests:
int8 gate/up S=1 nerr=2.36e-06 ok
int4 gate/up S=1 nerr=1.98e-06 ok
int4 down S=1 nerr=1.03e-06 ok
int2 gate/up S=1 nerr=1.72e-06 ok
f32 S=1 nerr=1.77e-06 ok
int8 gate/up S=4 nerr=2.36e-06 ok
int4 gate/up S=7 (odd) nerr=1.98e-06 ok
int4 non-mult-4 dims nerr=3.78e-06 ok
Metal fmt=4 grouped-int4 tests (coli_metal_matmul vs matmul_i4_grouped semantics):
grouped gate/up I=6144(mult64) S=1 worst_rel=1.90e-08 (I=6144 gs=64 ng=96 S=1) ok
grouped down I=2048(mult64) S=1 worst_rel=2.09e-08 (I=2048 gs=64 ng=32 S=1) ok
grouped gate/up I=6144(mult64) S=4 worst_rel=1.83e-08 (I=6144 gs=64 ng=96 S=4) ok
grouped I=200 (non-mult-64) S=2 worst_rel=1.29e-08 (I=200 gs=64 ng=4 S=2) ok
grouped I=201 (odd, non-mult-64) S=3 worst_rel=2.40e-08 (I=201 gs=64 ng=4 S=3) ok
grouped I=64 (degenerate, ng=1) S=1 worst_rel=1.15e-08 (I=64 gs=64 ng=1 S=1) ok
grouped I=40 (<gs, single partial group) S=1 worst_rel=2.53e-08 (I=40 gs=64 ng=1 S=1) ok
grouped I=512(mult64) outlier-heavy S=3 worst_rel=5.89e-08 (I=512 gs=64 ng=8 S=3) ok
grouped I=201(non-mult-64) outlier-heavy S=2 worst_rel=4.91e-08 (I=201 gs=64 ng=4 S=2) ok
Metal fmt=8 native FP8-e4m3 passthrough tests:
fp8 LUT exactness (256/256 codes via GPU kernel) 0/256 mismatches ok
fp8 gate/up-shaped O=2048 I=6144 (spec example) S=1 worst_rel=3.01e-08 (I=6144 O=2048 nblkO=16 nblkI=48 S=1) ok
fp8 down-shaped O=6144 I=2048 S=1 worst_rel=3.63e-08 (I=2048 O=6144 nblkO=48 nblkI=16 S=1) ok
fp8 gate/up-shaped O=2048 I=6144 S=4 worst_rel=4.05e-08 (I=6144 O=2048 nblkO=16 nblkI=48 S=4) ok
fp8 block edges: O,I both non-mult-128 worst_rel=5.95e-08 (I=200 O=130 nblkO=2 nblkI=2 S=2) ok
fp8 block edges: O just over 128, I exact worst_rel=4.65e-08 (I=128 O=129 nblkO=2 nblkI=1 S=1) ok
fp8 block edges: O exact, I just over 128 worst_rel=6.93e-08 (I=129 O=128 nblkO=1 nblkI=2 S=1) ok
fp8 degenerate 1x1 (single sub-block) worst_rel=5.87e-08 (I=1 O=1 nblkO=1 nblkI=1 S=1) ok
fp8 non-square block grid nblkO=3 nblkI=48 (stride audit) worst_rel=3.33e-08 (I=6144 O=384 nblkO=3 nblkI=48 S=3) ok
fp8 GEMM entry explicitly gated off (coli_metal_gemm refuses) rc=0 (expect 0/CPU-fallback) ok
fp8 MB_BUILD/moe_submit entry gated off (shared-expert fmt=8 hazard) rc=0 (expect 0/CPU-fallback) ok
Metal batched moe_block tests:
moe decode nb=8 R=8 nerr=2.43e-06 ok
moe ragged nb=6 R=16 nerr=2.49e-06 ok
Metal fmt=6 (E8/IQ3) moe_block tests:
e8 decode nb=8 R=8 nerr=4.80e-07 ok
e8 ragged nb=6 R=16 nerr=5.12e-07 ok
Metal large-batch gemm test:
gemm S=64 int4 nerr=2.85e-06 ok
gemm S=64 int4-grouped worst_rel=2.42e-08 ok
Metal fused attention tests:
attn S=1 pos=0 nerr=4.04e-06 cache=1.38e-05 ok
attn S=1 pos=37 nerr=4.13e-06 cache=1.48e-05 ok
attn S=4 pos=12 (MTP) nerr=5.37e-06 cache=1.34e-05 ok
attn S=3 pos=0 nerr=5.30e-06 cache=1.31e-05 ok
Metal fused attention tests (fmt=4 grouped q_a, proves bind_gemv gs plumbing):
attn grouped-qa S=1 pos=37 nerr=5.53e-06 cache=7.87e-06 qraw=1.94e-08 ok
attn grouped-qa S=4 pos=12 (MTP) nerr=5.00e-06 cache=1.38e-05 qraw=2.02e-08 ok
Metal negative control: fmt 1/2/3 unaffected by the fmt=4 shader branch --
see the runs above (int8/int4/int2/f32/moe/gemm/attn cases): all still ok.
Metal top-8 select serial-vs-parallel tests (exact-match contract, E=256):
top8 generic S=1 ok (serial==parallel bitwise, S=1 E=256)
top8 generic S=4 ok (serial==parallel bitwise, S=4 E=256)
top8 ALL-EQUAL ties ok (serial==parallel bitwise, S=1 E=256)
top8 massed dup ties S=4 ok (serial==parallel bitwise, S=4 E=256)
top8 3-level ties rscale ok (serial==parallel bitwise, S=2 E=256)
top8 denormal logits ok (serial==parallel bitwise, S=1 E=256)
top8 topp=0.01 (Ke=1 edge) ok (serial==parallel bitwise, S=1 E=256)
top8 topp=0.6 tied weights ok (serial==parallel bitwise, S=1 E=256)
top8 topp=0.999 S=4 ok (serial==parallel bitwise, S=4 E=256)
top8 topp on ALL-EQUAL ok (serial==parallel bitwise, S=2 E=256)
Metal top-8 select expert-count-generality tests (E!=256, REAP/#428 motivated):
top8 E=168 (REAP) generic S=1 ok (serial==parallel bitwise, S=1 E=168)
top8 E=168 (REAP) massed dup ties S=4 ok (serial==parallel bitwise, S=4 E=168)
top8 E=24 (<32 lane width) generic ok (serial==parallel bitwise, S=1 E=24)
top8 E=24 (<32 lane width) ALL-EQUAL ties ok (serial==parallel bitwise, S=1 E=24)
top8 E=200 (lane straddles E boundary) ok (serial==parallel bitwise, S=4 E=200)
top8 E=257 (>256, auto-serial-fallback) ok (serial==parallel bitwise, S=1 E=257)
metal backend tests: ok
exit: 0

@JustVugg

Copy link
Copy Markdown
Owner

Closing, with appreciation rather than rejection: this exact fix — same rename, same ref_fp8_nblk name — landed on dev six days ago as c7aaaf7, addressing what became #940. You based this on the released code, which doesn't have it yet; it ships in v1.6.0, which is imminent (#943). Independent convergence on the identical solution is the best possible confirmation the fix is right.

Your #947 is the more valuable half anyway — the reason this bug ever shipped is that no CI ran metal-test, and that PR closes the hole itself. Review over there.

@JustVugg JustVugg closed this Aug 11, 2026
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.

[Bug]: make metal-test failed

2 participants