Skip to content
Merged
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/twinkle/model/megatron/megatron.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,8 @@ def _add_base_layer_suffix(name):
base_layer_name = f'{name[:-5]}.base_layer.bias'
if not model_keys or base_layer_name in model_keys:
name = base_layer_name
if 'experts' in name:
return base_layer_name
Comment on lines +1435 to +1436
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

This logic introduces a potential UnboundLocalError. The variable base_layer_name is only defined within the if name.endswith('.weight') or elif name.endswith('.bias') blocks. If name contains 'experts' but does not end with either suffix (e.g., a buffer or a router parameter), the code will crash when attempting to return base_layer_name.

Furthermore, this change bypasses the model_keys validation for expert weights. If this bypass is intentional (to force the suffix for experts regardless of whether the key was found in model_keys), you should still ensure the variable is defined before returning it.

Suggested change
if 'experts' in name:
return base_layer_name
if 'experts' in name and (name.endswith('.weight') or name.endswith('.bias')):
return base_layer_name

return name

is_peft_format = (adapter_name != _default_adapter_name)
Expand Down
Loading