Repository navigation
[pull] main from huggingface:main - #4
Merged
Merged
Conversation
Fix Albert autodoc directives
* Fix nan gradients in GLM5-Next KDA chunked attention
decay_mask exponentiates pairwise differences of the cumulative log-decay before the
causal mask is applied. Non-causal pairs give large positive differences (measured up to
+313.9 at chunk_size=64) that overflow to inf in float32; the following masked_fill
discards them in the forward pass, but the backward pass then computes 0 * inf = nan,
which propagates to every parameter.
Apply the mask before exp() instead, which is what the sibling chunked delta-rule models
already do: Qwen3-Next masks the non-causal cumulative-decay differences with -inf ahead
of the exponential, with a comment naming this very overflow. Those models keep the decay
per head, so their pairwise tensor is [..., C, C] and the [C, C] mask applies directly;
GLM5-Next keeps it per channel, so the tensor is [..., C, C, D] and the mask has to be
broadcast over the channel axis. The mask must be strictly upper: the diagonal holds
g_i - g_i = 0 and is still consumed by the intra-chunk term below.
Forward output is bit-identical (max abs difference 0.0 against the current code).
Verified on GLM-5.3-Flash 9B (A100, bf16): grad_norm nan -> finite, parameters with nan
grads 252 -> 0. End-to-end SFT loss now decreases (3.15 -> 0.82); before the fix the
optimizer step was skipped every step because the gradients were not finite, so the
weights never changed.
* Compute the GLM5-Next KDA decay products blockwise instead of pairwise
The previous commit stops the nan gradients, but the intra-chunk term still builds an
explicit [..., chunk, chunk, head_dim] tensor of pairwise decays and reduces it with an
elementwise product. For GLM-5.3-Flash (64 linear heads, head_dim 128, chunk 64) that
tensor alone is 0.25 GiB per layer at 128 tokens and 8 GiB per layer at 4096, before any
activation is stored, which is what makes the torch path unusable rather than merely slow.
Split the chunk recursively instead. For a pair of blocks where every row index is larger
than every column index, the anchor A = g[mid] factorises exp(g_i - g_j) into
exp(g_i - A) * exp(A - g_j), so the cross-block term becomes a single matmul over head_dim
and never materialises a pairwise tensor. Because g is a cumulative sum of negative
log-decays both factors stay in [0, 1], so no positive exponent is formed at all - the
masking from the previous commit is only needed inside the small diagonal blocks. The two
products KDA needs (key/key for the UT transform, query/key for intra-chunk attention)
share the decay factors and the right-hand side, so they are computed together.
Measured on one A100, GLM-5.3-Flash linear-attention shapes (64 heads, head_dim 128,
chunk 64), bfloat16, forward plus backward through the full function:
seq 512 seq 2048
autograd peak fwd+bwd autograd peak fwd+bwd
before 3.39 6.47 48.2 ms 13.54 30.05 182.9 ms
after (8) 0.88 1.88 52.0 ms 3.51 8.60 80.2 ms
Block size 8 was picked from a sweep over 4/8/16/32 at those shapes; it is the fastest at
seq 2048 and close to the best at seq 512 while keeping the smallest memory among the fast
variants.
Outputs and gradients match the previous commit to the precision of the arithmetic used:
2e-07 relative in float32 with TF32 off, 5e-05 in bfloat16, and up to 7e-03 once TF32 is
enabled, which is the precision of the matmul itself.
* Revert the blockwise decay rewrite and keep only the mask-before-exp NaN fix
* Add regression tests for the chunked KDA decay mask
Compare the chunked KDA path against the recurrent reference for outputs, final state and gradients under a saturated forget gate, and check that a linear attention layer still gets finite parameter gradients in that regime.
* Propagate the KDA decay mask fix to kimi_linear
Kimi Linear inherits the linear attention layer from GLM-5.3-Flash, so its generated modeling file carries the same chunked KDA path and must be regenerated with the mask applied before the exponential.
* Narrow the KDA regression test down to a single linear attention layer built from the shared model tester
* Drop the per-parameter subtest from the KDA regression test
* [docs] Add a LiteRT page under community integrations Transformers v4 documented LiteRT export through `optimum[exporters-tf]`, which was removed with the TensorFlow support in #40760. This page documents the current route: `litert-torch` converts a model from `torch.export` directly. `litert-torch export_hf` writes a `.litertlm` file for LLMs, and `litert_torch.convert` writes a `.tflite` file for other models. Also adds the toctree entry under "Local deployment" and a redirect from the removed `tflite` page to the new one. * docs(litert): apply review wording suggestions
Add supports_context_parallel to PreTrainedModel
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )