Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,11 @@ def _register_pre_backward_param_unshard_hook(module):
with_kwargs=True,
)
)
grad_acc_param_list = list(module.parameters())
grad_acc_param_list = [p for p in module.parameters() if p.requires_grad]
else:
grad_acc_param_list = list(module.parameters(recurse=False))
grad_acc_param_list = [
p for p in module.parameters(recurse=False) if p.requires_grad
]

for param in grad_acc_param_list:
self.grad_acc_hooks[f"grad_acc and reduce for {self.param_to_name[param]}"] = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,8 @@ def _reset_parameters(self, old_params, new_params):
self.param_to_direct_module[new_param] = self.param_to_direct_module[old_param]
del self.param_to_direct_module[old_param]

new_param.requires_grad_(old_param.requires_grad)

for tp_attr in ["_mcore_tp", "_tp_partition_dim", "_tp_duplicated"]:
if getattr(old_param, tp_attr, None) is not None:
setattr(new_param, tp_attr, getattr(old_param, tp_attr))
Expand Down
2 changes: 1 addition & 1 deletion megatron/core/models/gpt/gpt_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def _preprocess(
# return this extra tensor
# this is for backwards compatibility with
# legacy unit tests, which break if you
# return a 6 tuple instead of 5.
# return a 7 tuple instead of 6.
preproc_output += (rotary_pos_cos_sin,)

return preproc_output
Expand Down
6 changes: 5 additions & 1 deletion megatron/core/transformer/fsdp_dtensor_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from megatron.core import parallel_state
from megatron.core.tensor_parallel.layers import copy_tensor_model_parallel_attributes
from megatron.core.transformer.transformer_layer import TransformerLayer
from megatron.core.utils import get_attr_wrapped_model


def get_ep_layer_offset(num_experts: int | None = None) -> int:
Expand Down Expand Up @@ -183,7 +184,10 @@ def handle_swiglu_in_state_dict(model, model_state_dict, optimizer_state_dict):
assert HAVE_MEGATRON_FSDP, "This function requires Megatron-FSDP to be installed."

# Extract num_experts from model config for expert parameter processing
num_experts = model.config.num_moe_experts if hasattr(model, 'config') else None
model_config = get_attr_wrapped_model(model, "config", allow_none=True)
num_experts = (
getattr(model_config, 'num_moe_experts', None) if model_config is not None else None
)

def intersection(s1, s2):
# Only works for step=1
Expand Down
Loading