-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
[Bugfix][DeepseekV4] Guard expert loader against UnboundLocalError #42835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1529,6 +1529,7 @@ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: | |||||||||||||||||||||||||||||
| and loaded_weight.dtype == torch.float8_e8m0fnu | ||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||
| loaded_weight = loaded_weight.view(torch.uint8) | ||||||||||||||||||||||||||||||
| name_mapped = None | ||||||||||||||||||||||||||||||
| for mapping in expert_mapping: | ||||||||||||||||||||||||||||||
| param_name, weight_name, expert_id, shard_id = mapping | ||||||||||||||||||||||||||||||
| if weight_name not in name: | ||||||||||||||||||||||||||||||
|
|
@@ -1554,6 +1555,13 @@ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: | |||||||||||||||||||||||||||||
| if success: | ||||||||||||||||||||||||||||||
| name = name_mapped | ||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||
| if name_mapped is None: | ||||||||||||||||||||||||||||||
| # No expert mapping matched (e.g. a non-canonical | ||||||||||||||||||||||||||||||
| # checkpoint whose expert tensor names differ from | ||||||||||||||||||||||||||||||
| # this model's expert_mapping); nothing was loaded | ||||||||||||||||||||||||||||||
| # for this weight, so skip it instead of raising | ||||||||||||||||||||||||||||||
| # UnboundLocalError. | ||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of only checking if
Suggested change
|
||||||||||||||||||||||||||||||
| loaded_params.add(name_mapped) | ||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||
| elif "attn_sink" in name: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initializing
name_mappedtoNoneprevents theUnboundLocalError, but we should also track whether any expert mapping was successfully loaded. Ifweight_loaderreturnsFalsefor all mappings (e.g., because the expert is not assigned to the current rank), the parameter should not be added toloaded_params. Initializing asuccessflag here allows for a more robust check after the loop.