Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions vllm/model_executor/models/deepseek_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Initializing name_mapped to None prevents the UnboundLocalError, but we should also track whether any expert mapping was successfully loaded. If weight_loader returns False for all mappings (e.g., because the expert is not assigned to the current rank), the parameter should not be added to loaded_params. Initializing a success flag here allows for a more robust check after the loop.

                    name_mapped = None
                    success = False

for mapping in expert_mapping:
param_name, weight_name, expert_id, shard_id = mapping
if weight_name not in name:
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Instead of only checking if name_mapped is None, we should check if success is True. If success is False, it means either no mapping matched the weight name or the weight_loader did not actually load any data for this rank. In either case, we should skip adding the parameter to loaded_params to avoid incorrectly marking it as initialized when it might be empty on this rank.

Suggested change
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
if not success:
# No expert mapping matched or the weight loader
# did not load this weight (e.g. not for this rank);
# nothing was loaded for this weight, so skip it
# instead of raising UnboundLocalError or incorrectly
# marking the parameter as loaded.
continue

loaded_params.add(name_mapped)
continue
elif "attn_sink" in name:
Expand Down
Loading