Skip to content

support ernie pp #10885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion paddlenlp/transformers/llama/modeling_auto_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ def manual_model_split(model, stage_idx, group, mode, pp_degree):

layer_lists = model.layers

# shared_params_names only support ernie
shared_params_names = [["embedding_0.w_0.dist", "ernie_lm_head_0.w_0.dist"]]

shared_mp = build_shared_param_map(model, shared_params_names)

def _build_stage(model, stage_idx, group):
new_model = None
if stage_idx == 0: # 第一个model_chunk输入特殊处理
Expand All @@ -200,7 +205,7 @@ def _build_stage(model, stage_idx, group):
new_model = LlamaChunk(
layer_lists[stage_idx * chunk_size : (stage_idx + 1) * chunk_size], is_first=False, is_last=False
)
stage = PipelineStage(new_model, stage_idx, chunk_num, group=group)
stage = PipelineStage(new_model, stage_idx, chunk_num, group=group, shared_parameters=shared_mp)
return stage

stages = []
Expand All @@ -210,6 +215,25 @@ def _build_stage(model, stage_idx, group):
return stages


def build_shared_param_map(model, shared_params_names):
shared_mp = []
for pair in shared_params_names:
assert len(pair) == 2, "Only exactly two parameters are supported for sharing."
ori_name = pair[0]
sync_name = pair[1]
ori_param = get_param_from_name(ori_name, model)
sync_param = get_param_from_name(sync_name, model)
shared_mp.append({"params": [ori_param, sync_param]})
return shared_mp


def get_param_from_name(param_name, model):
for param in model.parameters():
if param.name == param_name:
return param
raise ValueError(f"{param_name} not found in model parameters")


def get_llama_pp_schedule(model, n_microbatches, loss_fn, mode, pp_degree, group):
assert mode in ["VPP", "1F1B", "FThenB"]
stages = manual_model_split(model, group.rank, group, mode, pp_degree)
Expand Down
Loading