Compare commits
8 Commits
189d920111
...
ccfaee37da
| Author | SHA1 | Date |
|---|---|---|
|
|
ccfaee37da | |
|
|
cc312c1cc6 | |
|
|
e2ee878519 | |
|
|
b63a9565e3 | |
|
|
1aae25911b | |
|
|
1c876435ef | |
|
|
9fa620e2e5 | |
|
|
56d4cddfd8 |
|
|
@ -28,10 +28,13 @@ def pre_processing_chat(conversations, add_system_ratio=0.2):
|
|||
return [{'role': 'system', 'content': random.choice(SYSTEM_PROMPTS)}] + 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%概率移除空思考标签
|
||||
if '<think>\n\n</think>\n\n' in prompt_content and random.random() > empty_think_ratio:
|
||||
prompt_content = prompt_content.replace('<think>\n\n</think>\n\n', '')
|
||||
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', '')
|
||||
return prompt_content
|
||||
|
||||
class PretrainDataset(Dataset):
|
||||
|
|
@ -139,12 +142,13 @@ class DPODataset(Dataset):
|
|||
chosen_prompt = self.tokenizer.apply_chat_template(
|
||||
chosen, tokenize=False, add_generation_prompt=False
|
||||
)
|
||||
chosen_prompt = post_processing_chat(chosen_prompt)
|
||||
|
||||
rejected_prompt = self.tokenizer.apply_chat_template(
|
||||
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_prompt, truncation=True, max_length=self.max_length, padding='max_length'
|
||||
)
|
||||
|
|
@ -253,4 +257,4 @@ class AgentRLDataset(Dataset):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -91,4 +91,7 @@ def main():
|
|||
print(f'\n[Speed]: {gen_tokens / (time.time() - st):.2f} tokens/s\n\n') if args.show_speed else print('\n\n')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
try:
|
||||
main()
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
print()
|
||||
|
|
@ -158,7 +158,12 @@ class MOEFeedForward(nn.Module):
|
|||
x_flat = x.view(-1, hidden_dim)
|
||||
scores = F.softmax(self.gate(x_flat), dim=-1)
|
||||
topk_weight, topk_idx = torch.topk(scores, k=self.config.num_experts_per_tok, dim=-1, sorted=False)
|
||||
if self.config.norm_topk_prob: topk_weight = topk_weight / (topk_weight.sum(dim=-1, keepdim=True) + 1e-20)
|
||||
if self.config.norm_topk_prob:
|
||||
if self.config.num_experts_per_tok > 1:
|
||||
topk_weight = topk_weight / (topk_weight.sum(dim=-1, keepdim=True) + 1e-20)
|
||||
else:
|
||||
top1 = torch.topk(F.softmax(self.gate(x_flat.detach()), dim=-1), k=1, dim=-1, sorted=False)[0]
|
||||
topk_weight = top1 - top1.detach() + 1.0 # k=1: 1.0 forward on purpose, gradient via straight-through
|
||||
y = torch.zeros_like(x_flat)
|
||||
for i, expert in enumerate(self.experts):
|
||||
mask = (topk_idx == i)
|
||||
|
|
|
|||
Loading…
Reference in New Issue