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
4 changes: 2 additions & 2 deletions modelopt/torch/distill/plugins/megatron.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def setup_distillation_config(

def _adjust_layer_index_for_pp(submodule_name, model_cfg):
"""Adjust any sequence-based layer indices found in a submodule name for Pipeline Parallelism."""
match = re.search(r"(?<=\.)\d+(?=\.)", submodule_name)
match = re.search(r"(?<=\.)\d+(?=\.|$)", submodule_name)
if not match:
return submodule_name

Expand All @@ -172,7 +172,7 @@ def _adjust_layer_index_for_pp(submodule_name, model_cfg):
if new_layer_idx < 0:
raise ValueError(f"Layer {submodule_name} does not fall on final PP rank.")

new_submodule_name = submodule_name.replace(match.group(0), str(new_layer_idx))
new_submodule_name = submodule_name.replace(f".{match.group(0)}", f".{new_layer_idx}")
if parallel_state.get_tensor_and_context_parallel_rank() == 0:
logger.info(
f'Distillation: Renamed layer "{submodule_name}" on final PP rank to "{new_submodule_name}"'
Expand Down
Loading