feat: add NaN weight detection and input validation (#115)#117
Open
KuaaMU wants to merge 1 commit into
Open
Conversation
Add _check_weights_for_nan() method to DFlashDraftModel that warns when NaN values are detected in model weights during inference. This helps diagnose issues like z-lab#115 where layer norm weights become NaN. Additional improvements: - Add input validation for required arguments (noise_embedding, target_hidden) - Add type hints to apply_rotary_pos_emb function - Add comprehensive docstring to DFlashDraftModel class The NaN detection runs at the start of each forward pass and only warns once to avoid flooding stderr. It suggests re-downloading the checkpoint as the most common fix for corrupted weights. Closes z-lab#115 Co-authored-by: Claude <claude@anthropic.com> Signed-off-by: KuaaMU <XCM853629353@outlook.com>
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
Add NaN weight detection and input validation to
DFlashDraftModelto help diagnose and prevent issues like #115.Changes
1. NaN Weight Detection (
_check_weights_for_nan)2. Input Validation
noise_embeddingandtarget_hiddenare provided3. Type Hints
apply_rotary_pos_embfunction4. Documentation
DFlashDraftModelclassWhy This Helps
Issue #115 reports
layers.0.input_layernorm.weight became NaN. While the root cause may be in the checkpoint or training process, this detection helps users:Test Plan
py_compilepasses ✅AI assistance used: Claude (Anthropic) for code analysis and implementation. All changes reviewed and verified by the author.