You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GLM Metal: masked sparse attention and the DFlash2 q4 head keep the reference's NaN and Inf - #4396
GLM's Metal kernels now give the same NaN and Inf results as the float64 reference in three places where main's GLM kernel contract recorded known failures:
Masked sparse attention (glm_sparse_nax.metal: the 64-row, 32-row and split forms). A visible NaN score failed the score > NO_SCORE test and got zero probability, so a NaN never reached the output. Visible scores are now tested for NaN first; for every finite score the predicate is the old one.
Padding entries in the same kernels. An invalid list entry loaded V from key 0, and the zero probabilities multiplied an Inf or NaN there into the output. Invalid entries now read zero V. Selected keys and the order of the three matrix multiplies are unchanged.
The DFlash2 head's q4 affine matmul (affine_mm.metal). Main forms q + 128 with an adjusted bias, which equals s*q*x + b*x for finite values but can turn opposing infinities into NaN. GLM opts into TF_AM_EXACT_NONFINITE (from affine_mm.zig): when a half-row's group sum is not finite, the kernel recomputes that half from the raw codes. Other families do not set the define, so their kernels are byte-for-byte the code they compile today.
The repaired failures leave the contract's known-findings list.
Checks on this head
Kernel contract, GLM on an M5 Ultra (tf-kernel-contract --only glm, ReleaseFast): 468 PASS and no real failure in gates 1-4. Every planted control is still red. On main the same run has nine known failures (the six masked-score cases, two padding cases and the DFlash2 q4 head).
Gate 5 (launch limits) then stops with error: UnknownLaunch, on main as well. That is a separate gate-5 mapping bug, with its own fix in flight.
Finite outputs, source level: for finite scores the masking predicate is the old one. For finite group sums the original q + 128 multiply and its bias run as before. 1,008 exact rational checks of the identity and the fallback selection pass.
Not run yet
A before/after comparison on a device: served GLM tokens and Metal decode speed with this head against main. This PR stays out of the landing queue until both match.
M3 Ultra result for this head, with #4397 applied (without it the GLM contract stops at startup on pre-M5 Macs):
tf-kernel-contract --only glm, ReleaseFast: 102 kernels, 101 pass gates 1-4, 68 of 68 planted controls red, 0 known findings. Main with #4397 alone has 5 known findings on this GPU: the q4 nonfinite metal affine_mm glm m3 cases at group sizes 32, 64 and 128, with fp32 output, and the gather form, NaN where float64 gives +Inf. All five pass here, so the exact non-finite path also covers the pre-M5 TF_GLM_M3_FAST matmul.
The one failure left, glm_index_scores_nax bytes on pre-M5, and its threadgroup limit are on main without this PR and are tracked separately.
Still to do before this lands: the device check that finite outputs are bit-identical to main's kernels.
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
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.
What this changes
GLM's Metal kernels now give the same NaN and Inf results as the float64 reference in three places where main's GLM kernel contract recorded known failures:
glm_sparse_nax.metal: the 64-row, 32-row and split forms). A visible NaN score failed thescore > NO_SCOREtest and got zero probability, so a NaN never reached the output. Visible scores are now tested for NaN first; for every finite score the predicate is the old one.affine_mm.metal). Main formsq + 128with an adjusted bias, which equalss*q*x + b*xfor finite values but can turn opposing infinities into NaN. GLM opts intoTF_AM_EXACT_NONFINITE(fromaffine_mm.zig): when a half-row's group sum is not finite, the kernel recomputes that half from the raw codes. Other families do not set the define, so their kernels are byte-for-byte the code they compile today.The repaired failures leave the contract's known-findings list.
Checks on this head
tf-kernel-contract --only glm, ReleaseFast): 468 PASS and no real failure in gates 1-4. Every planted control is still red. On main the same run has nine known failures (the six masked-score cases, two padding cases and the DFlash2 q4 head).error: UnknownLaunch, on main as well. That is a separate gate-5 mapping bug, with its own fix in flight.q + 128multiply and its bias run as before. 1,008 exact rational checks of the identity and the fallback selection pass.Not run yet