llama.cpp released a fix for discarded values leaving invalid results in graphics computations on Apple devices. It writes 0 to discarded cells, matching other backends, the implementation layers that execute operations.
1. Select zero instead of multiplying discarded values
The release page marks b12220, which includes the fix, as a prerelease. Pull request #30711, a request for code change review, was approved and merged on November 9, 2026.
Triangular operations retain values inside a specified matrix triangle and set those outside it to 0. NaN denotes a result that cannot be expressed as a valid number. This fix distinguishes masking a cell from writing 0 to it.
The previous Metal kernel, code executed on the GPU, multiplied each value by a comparison result of 0 or 1. Multiplying a discarded infinity by 0 produced NaN. The new code conditionally selects the original value or 0:
dst_row[i0] = _ggml_vec_tri_cmp<ttype>(i0, i1) ? src_row[i0] : static_cast<T>(0);2. Added test cases using special values
The change adds test_tri_special cases. They place positive and negative infinity outside the triangle and finite values in retained cells. This arrangement exposes the difference between multiplying values away and selecting 0.
The tests cover four types: upper and lower triangles, each with and without the diagonal. Rather than checking just one triangle orientation, they check special-value handling for each condition defining which cells to retain.
The test runner rejects NaN in either inputs or outputs, so the new tests use positive and negative infinity. The pull request says all four cases fail on a CPU kernel using comparison-result multiplication but pass with the fix.
3. Both existing and new tests passed
The pull request lists commands to test triangular operations on CPU and Vulkan. The author reported that all four existing and four new cases passed with both commands. The original commands and result comments follow.
test-backend-ops -o TRI -b CPU # 4 existing cases and the 4 new ones, all pass
test-backend-ops -o TRI -b Vulkan0 # same set, all passThe merged pull request shows 25 automated checks passing. Developers examining triangular operations can use these commands to check both existing cases and the new special-value cases.
4. Impact and points to verify
The fix eliminates invalid results caused by infinity in discarded cells. Its key effect is to match CPU and Vulkan, which already write 0 to those cells.
It also adds test code to maintain. Across the Metal kernel and backend operation test file, the change adds 68 lines and removes 2. Pairing a one-line computation fix with special-value tests helps reproduce the issue.
However, the pull request explicitly excludes direct verification on Metal itself and other untested backends. Neither the release notes nor the pull request provides performance measurements for the computation change.
b12220 narrowly fixes the cause of infinity producing NaN in Metal triangular operations, ensuring that discarded cells are set to 0.
