Compare commits
5 Commits
f109aeaaa6
...
189d920111
| Author | SHA1 | Date |
|---|---|---|
|
|
189d920111 | |
|
|
7a9137d2e9 | |
|
|
7988bc81a3 | |
|
|
37ac206e9a | |
|
|
56d4cddfd8 |
|
|
@ -28,9 +28,12 @@ def pre_processing_chat(conversations, add_system_ratio=0.2):
|
||||||
return [{'role': 'system', 'content': random.choice(SYSTEM_PROMPTS)}] + conversations
|
return [{'role': 'system', 'content': random.choice(SYSTEM_PROMPTS)}] + conversations
|
||||||
return conversations
|
return conversations
|
||||||
|
|
||||||
def post_processing_chat(prompt_content, empty_think_ratio=0.2):
|
def post_processing_chat(prompt_content, empty_think_ratio=0.2, remove_empty_think=None):
|
||||||
# 以80%概率移除空思考标签
|
# 以80%概率移除空思考标签
|
||||||
if '<think>\n\n</think>\n\n' in prompt_content and random.random() > empty_think_ratio:
|
if '<think>\n\n</think>\n\n' in prompt_content:
|
||||||
|
if remove_empty_think is None:
|
||||||
|
remove_empty_think = random.random() > empty_think_ratio
|
||||||
|
if remove_empty_think:
|
||||||
prompt_content = prompt_content.replace('<think>\n\n</think>\n\n', '')
|
prompt_content = prompt_content.replace('<think>\n\n</think>\n\n', '')
|
||||||
return prompt_content
|
return prompt_content
|
||||||
|
|
||||||
|
|
@ -139,12 +142,13 @@ class DPODataset(Dataset):
|
||||||
chosen_prompt = self.tokenizer.apply_chat_template(
|
chosen_prompt = self.tokenizer.apply_chat_template(
|
||||||
chosen, tokenize=False, add_generation_prompt=False
|
chosen, tokenize=False, add_generation_prompt=False
|
||||||
)
|
)
|
||||||
chosen_prompt = post_processing_chat(chosen_prompt)
|
|
||||||
|
|
||||||
rejected_prompt = self.tokenizer.apply_chat_template(
|
rejected_prompt = self.tokenizer.apply_chat_template(
|
||||||
rejected, tokenize=False, add_generation_prompt=False
|
rejected, tokenize=False, add_generation_prompt=False
|
||||||
)
|
)
|
||||||
rejected_prompt = post_processing_chat(rejected_prompt)
|
remove_empty_think = random.random() > 0.2
|
||||||
|
chosen_prompt = post_processing_chat(chosen_prompt, remove_empty_think=remove_empty_think)
|
||||||
|
rejected_prompt = post_processing_chat(rejected_prompt, remove_empty_think=remove_empty_think)
|
||||||
chosen_encoding = self.tokenizer(
|
chosen_encoding = self.tokenizer(
|
||||||
chosen_prompt, truncation=True, max_length=self.max_length, padding='max_length'
|
chosen_prompt, truncation=True, max_length=self.max_length, padding='max_length'
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -473,7 +473,8 @@ if __name__ == "__main__":
|
||||||
Logger('torch.compile enabled')
|
Logger('torch.compile enabled')
|
||||||
rollout_engine.update_policy(model)
|
rollout_engine.update_policy(model)
|
||||||
if dist.is_initialized():
|
if dist.is_initialized():
|
||||||
model = DistributedDataParallel(model, device_ids=[local_rank])
|
# 同 train_ppo:RoPE buffer 各 rank 一致,每步广播纯属浪费
|
||||||
|
model = DistributedDataParallel(model, device_ids=[local_rank], broadcast_buffers=False)
|
||||||
rollout_engine.update_policy(model)
|
rollout_engine.update_policy(model)
|
||||||
|
|
||||||
for epoch in range(start_epoch, args.epochs):
|
for epoch in range(start_epoch, args.epochs):
|
||||||
|
|
|
||||||
|
|
@ -314,7 +314,8 @@ if __name__ == "__main__":
|
||||||
Logger('torch.compile enabled')
|
Logger('torch.compile enabled')
|
||||||
rollout_engine.update_policy(model)
|
rollout_engine.update_policy(model)
|
||||||
if dist.is_initialized():
|
if dist.is_initialized():
|
||||||
model = DistributedDataParallel(model, device_ids=[local_rank])
|
# 同 train_ppo:RoPE buffer 各 rank 一致,每步广播纯属浪费
|
||||||
|
model = DistributedDataParallel(model, device_ids=[local_rank], broadcast_buffers=False)
|
||||||
rollout_engine.update_policy(model)
|
rollout_engine.update_policy(model)
|
||||||
|
|
||||||
# ========== 8. 开始训练 ==========
|
# ========== 8. 开始训练 ==========
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ def rep_penalty(text, n=3, cap=0.5):
|
||||||
class CriticModel(MiniMindForCausalLM):
|
class CriticModel(MiniMindForCausalLM):
|
||||||
def __init__(self, params):
|
def __init__(self, params):
|
||||||
super().__init__(params)
|
super().__init__(params)
|
||||||
# 替换lm_head为输出单一价值的线性层
|
# lm_head 不参与 forward,仅靠 tie_word_embeddings 与 embed_tokens 共享权重,解绑后 DDP 会报未使用参数
|
||||||
self.value_head = nn.Linear(params.hidden_size, 1)
|
self.value_head = nn.Linear(params.hidden_size, 1)
|
||||||
|
|
||||||
def forward(self, input_ids=None, attention_mask=None, **kwargs):
|
def forward(self, input_ids=None, attention_mask=None, **kwargs):
|
||||||
|
|
@ -429,8 +429,9 @@ if __name__ == "__main__":
|
||||||
Logger('torch.compile enabled')
|
Logger('torch.compile enabled')
|
||||||
rollout_engine.update_policy(actor_model)
|
rollout_engine.update_policy(actor_model)
|
||||||
if dist.is_initialized():
|
if dist.is_initialized():
|
||||||
actor_model = DistributedDataParallel(actor_model, device_ids=[local_rank])
|
# freqs_cos/freqs_sin 各 rank 由 config 确定性算出,默认每步广播一次纯属浪费
|
||||||
critic_model = DistributedDataParallel(critic_model, device_ids=[local_rank])
|
actor_model = DistributedDataParallel(actor_model, device_ids=[local_rank], broadcast_buffers=False)
|
||||||
|
critic_model = DistributedDataParallel(critic_model, device_ids=[local_rank], broadcast_buffers=False)
|
||||||
rollout_engine.update_policy(actor_model)
|
rollout_engine.update_policy(actor_model)
|
||||||
|
|
||||||
# ========== 8. 开始训练 ==========
|
# ========== 8. 开始训练 ==========
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue