Repository navigation
Conversation
rasa04
force-pushed
the
metal-calibrate-tiles
branch
from
October 24, 2026 23:36
3c6b478 to
3b5736c
Compare
…p.sh --calibrate) The Mac's part of tools/calibrate.py. The Metal decode kernels (the dense GEMVs, gr_down, the routed experts' gate/up and down) run on tiles tuned on the M4 and M5; a GPU with less ALU per byte of bandwidth wants others (M1 Max: a 2-token window's dense GEMVs 33 -> 21 ms on per-shape best tiles). - Engine: STRATA_METAL_CALIBRATE=<file> times every candidate tile of each GEMV shape and gr_down kind when a window size is first encoded, and the experts' tiles (per pair of formats) after that window's first run; outputs go to a scratch buffer, so the model's state is not touched. A tile replaces the default only when it measured >= 3% faster. STRATA_METAL_TILES=<file> reads them and never measures; a shape the file lacks, or a file from another GPU (its first line names the device), keeps the defaults. Neither set: unchanged. - tools/calibrate.py on a Mac: the measuring start, then the tiles race the defaults on the config's own arguments (a restart each, interleaved rounds) and go into the config's env only when they win by more than MIN_GAIN. One file a model. metal/setup_mac.py --calibrate applies it; a reinstall keeps it.
rasa04
force-pushed
the
metal-calibrate-tiles
branch
from
October 25, 2026 10:59
3b5736c to
ceb5caa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related discussion: #4025.
Problem. The Metal decode kernels use tiles tuned on the M4 and M5. On an M1 Max (24-core GPU) the dense GEMVs of a Qwen3.8-Flash-Next Q2_0 decode window take 33.1 ms on the default tiles and 20.7 ms on each shape's best one (
gemv_parity --one … --ntok 2).setup.sh --calibrateis not ported to the Mac.Change (opt-in; with neither variable set the dispatches are unchanged):
STRATA_METAL_CALIBRATE=<file>: the engine times every instantiated tile of the dense GEMVs,gr_downand the routed experts on the device, outputs into a scratch buffer, and keeps a tile only if it is ≥ 3% faster.STRATA_METAL_TILES=<file>: use the tiles, never measure. A shape the file lacks, a file from another GPU, or an expert tile that does not divide the model's rows keeps the default.setup.sh --calibrateon a Mac (tools/calibrate.py, like the HIPSTRATA_SH_STREAMstep): measures, races the tiles against the defaults over 3 interleaved rounds, and writesSTRATA_METAL_TILESinto the config only aboveMIN_GAIN. One file per model.Result (M1 Max, 64 GB, Q2_0 resident, MTP;
tools/ab_engine.py, 3 rounds, medians, tok/s):Quality (
tools/quant_quality.py, 4995 positions): same top token 98.4%, mean KL 0.003, perplexity 4.439 → 4.431. Near-ties can flip, since a tile changes the order of a sum.Validation (
3b5736caon7dd5cf18; speed and quality measured onf53e57a4, which lacks only the row-divisibility guard):gemv_parity(20 tiles),gr_parity(6 variants),expert_parity507/507 (every gate/up and down format × tile × ntok 1, 2, 4);python -m unittest test_calibrate test_setup_mac(57, incl. the newtest_metal_tiles); default path byte-identical to7dd5cf18(quant_quality, 4995/4995 rows).test_failed_calibration_says_the_engines_reason, which fails on a Mac without this change too (metal/setup_mac.pyis missing from the test's temp tree).Limits. The gain is confirmed only on the Mac and
--specthe calibration ran on. Window sizes it did not see and the MTP layer keep the defaults. Re-run after an update that changes the kernels.Individual runs (tok/s)
setup.sh --calibrate: default 25.9 / 26.1 / 27.8, tiles 35.0 / 35.1 / 37.3.Local changes to tools/ab_engine.py (whole answers kept, the die cooled before each start)