Skip to content

Commit bc97434

Browse files
jstjohnclaude[bot]
andauthored
Update src/megatron/bridge/peft/utils.py with keep_extra_state=True simplification.
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Signed-off-by: John St. John <jstjohn@users.noreply.github.com>
1 parent fe828d7 commit bc97434

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎src/megatron/bridge/peft/utils.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,10 @@ def sharded_state_dict(
11081108

11091109
if use_expert_axis:
11101110
keep_extra_state = self._keep_expert_extra_state()
1111-
self._replace_extra_state(linear_in_sd, linear_in_sd, keep_extra_state=keep_extra_state)
1112-
self._replace_extra_state(linear_out_sd, linear_out_sd, keep_extra_state=keep_extra_state)
1111+
if not keep_extra_state:
1112+
for sd in (linear_in_sd, linear_out_sd):
1113+
for key in [k for k in sd if "_extra_state" in k]:
1114+
del sd[key]
11131115
for key, value in list(linear_in_sd.items()):
11141116
if isinstance(value, ShardedTensor):
11151117
linear_in_sd[key] = self._apply_expert_axis_factory(value, sharded_offsets)

0 commit comments

Comments
 (0)