[Fix] Prevent NaN failure in MesaNet - #1152
Open
Undermyth wants to merge 8 commits into
Open
Conversation
Author
|
Sorry for the late and repeated changes since we took some time to verify the fix on models. |
Undermyth
marked this pull request as ready for review
August 28, 2026 04:28
Author
|
@zhiyuan1i could you please take a look on this? I think it's ready for review |
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.
Summary
Fix for issue #1187 .
The current implementation casts
qandkafter l2norm to float16 forcely, and the dtype of states (h_kkandh_kv) are assigned as the same ask, which is float16.Such precision is not enough since
vis not normalized and accumulated toh_kv, which will soon cause NaN in fwd and bwd during training. Since other ops like DeltaNet assign states in bloat16 when training under bf16 mixed precision, assigning bfloat16 states here should be suitable.Also the precision is not enough for
h_kk, since fp16 can cause a numerically non-positive definite matrix in CG solver and thus the divergence. Lifting precision to fp32 solves the problem. We've tested the op on H100 to ensure that fp32 implementation can fit in the SRAM with dim=128.Test plan
Use the original test as MesaNet. The error bound of chunk output is slightly relaxed (from 0.006 to 0.007), seems it not likely to be achieved under
h_kvwith bfloat16Benchmark / NCU (kernel changes only)
None
Breaking changes
None
Checklist