Repository navigation
[Engine] Metal: fit Inkling 2's mix kernels to the GPU's threadgroup limit - #359
Open
HugoLopes45 wants to merge 1 commit into
Open
HugoLopes45 wants to merge 1 commit into
HugoLopes45 wants to merge 1 commit into
Conversation
…limit On an Apple M1 Max the ink_conv_mix_rows_3_4 pipeline allows at most 832 threads per threadgroup, but the mix kernels were always launched with 1,024, so the first request stopped the engine (exit 6, the #2323 guard). The kernels stride by the threadgroup width and reduce over its SIMD groups, so they compute the same mix with fewer threads as long as those cover the row. Launch with the pipeline's limit, rounded down to whole SIMD groups, and refuse when it cannot cover the row. A GPU that allows 1,024 threads launches as before. inkling_parity now checks ink_conv_mix and ink_conv_mix_rows at Inkling 2 Mini's width (2,304) with 1 and 3 queries.
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.
Problem and result
On an Apple M1 Max (64 GB, macOS 27.2.1), Inkling 2 Mini UD-Q3_K_XL loads, but the first chat request stops the engine:
The server then returns
the engine stopped unexpectedly (exit code 6)for every request. The four Inkling 2 mix launches (ink_mix,ink_conv_mix,ink_conv_mix_rows,ink_moe_conv_mix) always ask for 1,024 threads, and this pipeline gets 832 on the M1 Max. After the change, the same model answers on the M1 Max: greedy code and tool-call requests complete with correct output.Related discussion
Same class of bug as Niko1221/Strata#2323 (a pipeline limit below the launch size, caught by its guard), here for the Inkling 2 mix kernels. No existing issue or PR found for these kernels.
Approach
The mix kernels stride by the threadgroup width (
i = tid + h * nt, at least 3 slots a thread up to 3,072 values, 4 above) and reduce overnt / 32SIMD groups, so they compute the same mix with a narrower threadgroup as long as it covers the row (Inkling 2 Mini: 3 x 832 = 2,496 >= 2,304).mix_threads()launches with the pipeline's limit rounded down to whole SIMD groups, capped at 1,024, and throws when the limit cannot cover the row instead of computing a partial row. A GPU whose pipeline allows 1,024 threads launches exactly as before. The limit comes frompipe_max_threads(), as the attention dispatch in the same file already does.On the M1 Max the reductions run over 26 SIMD groups instead of 32, so the floating-point order of the sums differs from a 1,024-thread GPU; the parity test below bounds the difference against the CPU reference.
Validation
Passed:
d62dfac(=mainforengine/metal/src/poly/inkling.cpp),engine/metalbuilt withSTRATA_METAL_POLY=ON, Release.poly_inkling_paritywith the newconv_mixescases (ink_conv_mixandink_conv_mix_rows, width 2,304, 1 and 3 queries, 1 and 4 rows):all passed, 0 mismatches, max error 4.8e-7 (norm) and 2.4e-7 (mix outputs).d62dfacstops atink_conv_mix_rowswith 3 queries, exit 6, with the message above.ctest -L poly: 48 of 49 passed; the failure is listed below../setup.sh --family inkling --model UD-Q3_K_XL --context 131072(DSpark draft on,--metal-optimize --metal-memory balanced), then/v1/chat/completionsat temperature 0: anis_primefunction that is correct for 0-29 when executed, and aget_weathertool call with{"city": "Lisbon"}(finish_reason: tool_calls).Failed:
poly_runtime_failure(strata metal: command buffer failed: injected test failure). It fails the same way on unpatchedd62dfacon this Mac, so it is not caused by this change.Not run:
min(1024, limit)), but I did not run one.ink_moe_conv_mixandink_mixhave no new test; they go through the samemix_threads().ink_mixkeeps its existing parity case, which passes.Limits
These four were the only launches in
engine/metal/src/poly/inkling.cppwith a fixed 1,024 threads; the others already size bypipe_max_threads()or ask for 256 or fewer. Metal kernels outside Inkling 2 were not reviewed.