repo_name
stringlengths 8
65
| repo_url
stringlengths 27
84
| license
stringclasses 6
values | file_path
stringlengths 6
85
| file_url
stringlengths 83
181
| timestamp
stringlengths 26
26
| reward_functions
listlengths 1
20
| trainer_usages
listlengths 1
23
|
|---|---|---|---|---|---|---|---|
dstackai/dstack
|
https://github.com/dstackai/dstack
|
Mozilla Public License 2.0
|
examples/llms/deepseek/trl/amd/grpo_train.py
|
https://github.com/dstackai/dstack/blob/58181d1fe372488d9a64075c24d975935411f31d/examples/llms/deepseek/trl/amd/grpo_train.py
|
2025-03-24T10:14:18.106059
|
[
{
"name": "reward_len",
"code": "def reward_len(completions, **kwargs):\n return [abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "reward_len",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
philschmid/deep-learning-pytorch-huggingface
|
https://github.com/philschmid/deep-learning-pytorch-huggingface
|
MIT License
|
training/scripts/run_r1_grpo.py
|
https://github.com/philschmid/deep-learning-pytorch-huggingface/blob/59b37973074de90004d10e5ff636f98160c9743a/training/scripts/run_r1_grpo.py
|
2025-03-24T10:14:24.890615
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_args)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
huihuihenqiang/wechat-simulate-human
|
https://github.com/huihuihenqiang/wechat-simulate-human
|
Unknown
|
ft/deepseek_r1_train.py
|
https://github.com/huihuihenqiang/wechat-simulate-human/blob/26042f23d5c26501816a2d4ef498134e94349085/ft/deepseek_r1_train.py
|
2025-03-24T10:14:27.153189
|
[
{
"name": "mark_reward (from list item 0)",
"code": "def mark_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n return [mark_num(response) for response in responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "soft_format_reward (from list item 1)",
"code": "def soft_format_reward(completions, **kwargs):\n pattern = '<think>.*?</think>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "hard_format_reward (from list item 2)",
"code": "def hard_format_reward(completions, **kwargs):\n pattern = '^<think>\\\\n.*?n</think>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "digit_reward (from list item 3)",
"code": "def digit_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward (from list item 4)",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "mark_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def mark_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n return [mark_num(response) for response in responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def soft_format_reward(completions, **kwargs):\n pattern = '<think>.*?</think>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "hard_format_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def hard_format_reward(completions, **kwargs):\n pattern = '^<think>\\\\n.*?n</think>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "digit_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def digit_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward]",
"args": "training_args",
"train_dataset": "data",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Doriandarko/MLX-GRPO
|
https://github.com/Doriandarko/MLX-GRPO
|
Unknown
|
mlx-grpo.py
|
https://github.com/Doriandarko/MLX-GRPO/blob/eaacf96e4ad464860144f52b9823408f0ae7c295/mlx-grpo.py
|
2025-03-24T10:14:29.408549
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "MLXGRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "config",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": "tokenizer",
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
michaelhla/pro-1
|
https://github.com/michaelhla/pro-1
|
Apache License 2.0
|
train/unsloth-grpo.py
|
https://github.com/michaelhla/pro-1/blob/e205302deb82e971311125869e74efa4feb636fc/train/unsloth-grpo.py
|
2025-03-24T10:14:31.663908
|
[
{
"name": "stability_reward_func (from list item 0)",
"code": "def stability_reward_func(prompts, completions, sequences, orig_stabs, **kwargs):\n \"\"\"Custom reward function for stability optimization with LLM-based soft rewards\"\"\"\n rewards = []\n direct_extraction_success = 0\n lm_applier_success = 0\n extraction_failures = 0\n for i, (prompt, completion, sequence, orig_stab) in enumerate(zip(prompts, completions, sequences, orig_stabs)):\n try:\n reward = 0.0\n print(f'COMPLETION {i}')\n print(completion)\n print('-' * 100)\n think_match = re.search('<think>(.*?)</think>', completion, re.DOTALL)\n reasoning = think_match.group(1).strip() if think_match else completion\n modified_sequence = lm_sequence_applier(sequence, reasoning)\n extraction_method = 'lm_applier'\n if modified_sequence:\n lm_applier_success += 1\n else:\n print(f'LM sequence applier failed for completion {i}, trying direct extraction...')\n modified_sequence = extract_sequence_from_response(completion)\n extraction_method = 'direct'\n if modified_sequence and (not is_valid_amino_acid_sequence(modified_sequence)):\n print(f'Extracted sequence contains invalid amino acids')\n modified_sequence = None\n if modified_sequence:\n direct_extraction_success += 1\n else:\n print(f'Direct extraction also failed for completion {i}')\n extraction_failures += 1\n rewards.append(reward)\n continue\n print(f'Original sequence length: {len(sequence)}')\n print(f'Modified sequence length: {len(modified_sequence)}')\n stab_calc = calculate_relative_stability(original_seq=sequence, modified_seq=modified_sequence, calculator=calculator, orig_stab=orig_stab)\n if stab_calc > 0.0:\n reward += STABILITY_REWARD\n llm_judgments = []\n for goal in ['creativity']:\n try:\n start_time = time.time()\n llm_judgment = get_llm_judgment(completion, sequence, modified_sequence, prompt, goal)\n end_time = time.time()\n reward += lm_reward_coeffs[goal] * llm_judgment\n print(f'{goal} reward: {llm_judgment} in {end_time - start_time:.2f} seconds')\n except Exception as e:\n print(f'Error getting LLM judgment: {e}')\n wandb.log({f'reward/completion_{i}/base_stability_reward': reward, f'reward/completion_{i}/stability_reward': STABILITY_REWARD if stab_calc > 0.0 else 0.0, f'reward/completion_{i}/creativity_reward': lm_reward_coeffs['creativity'] * llm_judgment if llm_judgment else 0.0, f'reward/completion_{i}/extraction_method': extraction_method})\n rewards.append(reward)\n except Exception as e:\n print(f'Error calculating rewards: {e}')\n extraction_failures += 1\n rewards.append(reward)\n total_completions = len(completions)\n if total_completions > 0:\n wandb.log({'extraction/direct_success_rate': direct_extraction_success / total_completions, 'extraction/lm_applier_success_rate': lm_applier_success / total_completions, 'extraction/failure_rate': extraction_failures / total_completions})\n print(f'Extraction stats: Direct: {direct_extraction_success}/{total_completions}, LM Applier: {lm_applier_success}/{total_completions}, Failures: {extraction_failures}/{total_completions}')\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "stability_reward_func (from [stability_reward_func])",
"code": "def stability_reward_func(prompts, completions, sequences, orig_stabs, **kwargs):\n \"\"\"Custom reward function for stability optimization with LLM-based soft rewards\"\"\"\n rewards = []\n direct_extraction_success = 0\n lm_applier_success = 0\n extraction_failures = 0\n for i, (prompt, completion, sequence, orig_stab) in enumerate(zip(prompts, completions, sequences, orig_stabs)):\n try:\n reward = 0.0\n print(f'COMPLETION {i}')\n print(completion)\n print('-' * 100)\n think_match = re.search('<think>(.*?)</think>', completion, re.DOTALL)\n reasoning = think_match.group(1).strip() if think_match else completion\n modified_sequence = lm_sequence_applier(sequence, reasoning)\n extraction_method = 'lm_applier'\n if modified_sequence:\n lm_applier_success += 1\n else:\n print(f'LM sequence applier failed for completion {i}, trying direct extraction...')\n modified_sequence = extract_sequence_from_response(completion)\n extraction_method = 'direct'\n if modified_sequence and (not is_valid_amino_acid_sequence(modified_sequence)):\n print(f'Extracted sequence contains invalid amino acids')\n modified_sequence = None\n if modified_sequence:\n direct_extraction_success += 1\n else:\n print(f'Direct extraction also failed for completion {i}')\n extraction_failures += 1\n rewards.append(reward)\n continue\n print(f'Original sequence length: {len(sequence)}')\n print(f'Modified sequence length: {len(modified_sequence)}')\n stab_calc = calculate_relative_stability(original_seq=sequence, modified_seq=modified_sequence, calculator=calculator, orig_stab=orig_stab)\n if stab_calc > 0.0:\n reward += STABILITY_REWARD\n llm_judgments = []\n for goal in ['creativity']:\n try:\n start_time = time.time()\n llm_judgment = get_llm_judgment(completion, sequence, modified_sequence, prompt, goal)\n end_time = time.time()\n reward += lm_reward_coeffs[goal] * llm_judgment\n print(f'{goal} reward: {llm_judgment} in {end_time - start_time:.2f} seconds')\n except Exception as e:\n print(f'Error getting LLM judgment: {e}')\n wandb.log({f'reward/completion_{i}/base_stability_reward': reward, f'reward/completion_{i}/stability_reward': STABILITY_REWARD if stab_calc > 0.0 else 0.0, f'reward/completion_{i}/creativity_reward': lm_reward_coeffs['creativity'] * llm_judgment if llm_judgment else 0.0, f'reward/completion_{i}/extraction_method': extraction_method})\n rewards.append(reward)\n except Exception as e:\n print(f'Error calculating rewards: {e}')\n extraction_failures += 1\n rewards.append(reward)\n total_completions = len(completions)\n if total_completions > 0:\n wandb.log({'extraction/direct_success_rate': direct_extraction_success / total_completions, 'extraction/lm_applier_success_rate': lm_applier_success / total_completions, 'extraction/failure_rate': extraction_failures / total_completions})\n print(f'Extraction stats: Direct: {direct_extraction_success}/{total_completions}, LM Applier: {lm_applier_success}/{total_completions}, Failures: {extraction_failures}/{total_completions}')\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[stability_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": "[WandBLoggingCallback(), CheckpointCallback(checkpoint_dir=f'./{RUN_NAME}/checkpoints', checkpoint_freq=8, max_checkpoints=5)]",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
transformerlab/transformerlab-api
|
https://github.com/transformerlab/transformerlab-api
|
GNU Affero General Public License v3.0
|
transformerlab/plugins/unsloth_grpo_trainer/main.py
|
https://github.com/transformerlab/transformerlab-api/blob/b52bec9ee4707833a1f32cfe8130f6e7f618d52f/transformerlab/plugins/unsloth_grpo_trainer/main.py
|
2025-03-24T10:14:33.958267
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c, start_thinking_string, end_thinking_string, start_answer_string, end_answer_string) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 1)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r, start_answer_string, end_answer_string) for r in responses]\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "int_reward_func (from list item 2)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the answer is a number\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "strict_format_reward_func (from list item 3)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks strictly if the completion has a specific format.\"\"\"\n pattern = f'^{start_thinking_string}\\\\n.*?\\\\n{end_thinking_string}\\\\n{start_answer_string}\\\\n.*?\\\\n{end_answer_string}\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from list item 4)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = f'{start_thinking_string}.*?{end_thinking_string}\\\\s*{start_answer_string}.*?{end_answer_string}'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, correctness_reward_func, int_reward_func, strict_format_reward_func, soft_format_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c, start_thinking_string, end_thinking_string, start_answer_string, end_answer_string) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, correctness_reward_func, int_reward_func, strict_format_reward_func, soft_format_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r, start_answer_string, end_answer_string) for r in responses]\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, correctness_reward_func, int_reward_func, strict_format_reward_func, soft_format_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the answer is a number\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, correctness_reward_func, int_reward_func, strict_format_reward_func, soft_format_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks strictly if the completion has a specific format.\"\"\"\n pattern = f'^{start_thinking_string}\\\\n.*?\\\\n{end_thinking_string}\\\\n{start_answer_string}\\\\n.*?\\\\n{end_answer_string}\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, correctness_reward_func, int_reward_func, strict_format_reward_func, soft_format_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = f'{start_thinking_string}.*?{end_thinking_string}\\\\s*{start_answer_string}.*?{end_answer_string}'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, correctness_reward_func, int_reward_func, strict_format_reward_func, soft_format_reward_func]",
"args": "args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "[progress_callback]",
"tokenizer": "tokenizer",
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
JinSeoung-Oh/Reference
|
https://github.com/JinSeoung-Oh/Reference
|
Unknown
|
Reasoning/ReasoningModels.py
|
https://github.com/JinSeoung-Oh/Reference/blob/e49eb8aea5ea65f0c3b687ece28f075d392d8156/Reasoning/ReasoningModels.py
|
2025-03-24T10:14:36.212741
|
[
{
"name": "custom_reward_func (from list item 0)",
"code": "def custom_reward_func(prompts, completions, answer, min_reasoning_length=10, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses_answer = [extract_xml_answer(r, tag='answer') for r in responses]\n extracted_responses_reasoning = [extract_xml_answer(r, tag='reasoning') for r in responses]\n extracted_responses_validate = [extract_xml_answer(r, tag='validate') for r in responses]\n rewards = []\n for original_response, extracted_answer, extracted_reasoning, extracted_validate in zip(responses, extracted_responses_answer, extracted_responses_reasoning, extracted_responses_validate):\n is_correct = extracted_answer == answer[0]\n is_int = extracted_answer.isdigit()\n has_answer_tags = '<answer>' in original_response and '</answer>' in original_response\n has_reasoning_tags = '<reasoning>' in original_response and '</reasoning>' in original_response\n has_validate_tags = '<validate>' in original_response and '</validate>' in original_response\n reasoning_length = len(word_tokenize(extracted_reasoning.lower()))\n validate_length = len(word_tokenize(extracted_validate.lower()))\n reward = 0.0\n reasoning_reward = 0.0\n if is_correct:\n reward += 5.0\n if is_int:\n reward += 0.5\n if has_validate_tags:\n reward *= 1.25\n if validate_length >= 5:\n min_validate_length = 5\n max_validate_length = 256\n max_validate_bonus = 3.0\n if validate_length >= min_validate_length:\n if validate_length >= max_validate_length:\n validate_bonus = max_validate_bonus\n else:\n validate_bonus = (validate_length - min_validate_length) / (max_validate_length - min_validate_length) * max_validate_bonus\n else:\n validate_bonus = 0.0\n else:\n validate_bonus = 0.0\n else:\n validate_bonus = 0.0\n if has_reasoning_tags:\n reward *= 1.25\n if reasoning_length >= 5:\n min_scaling_length = 5\n max_scaling_length = 1024\n max_scaling_bonus = 10\n if reasoning_length <= min_scaling_length:\n reasoning_reward = 0.0\n elif reasoning_length >= max_scaling_length:\n reasoning_reward = 5.0\n else:\n reasoning_reward = (reasoning_length - min_scaling_length) / (max_scaling_length - min_scaling_length) * max_scaling_bonus\n else:\n reasoning_reward = 0.0\n else:\n reasoning_reward = 0.0\n total_reward = reward + reasoning_reward + validate_bonus\n if has_validate_tags:\n validate_lower = extracted_validate.lower()\n if re.search('(wait|but|rethink)(?=.{20,})', validate_lower, re.DOTALL):\n total_reward *= 10.0\n rewards.append(total_reward)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "custom_reward_func (from [custom_reward_func])",
"code": "def custom_reward_func(prompts, completions, answer, min_reasoning_length=10, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses_answer = [extract_xml_answer(r, tag='answer') for r in responses]\n extracted_responses_reasoning = [extract_xml_answer(r, tag='reasoning') for r in responses]\n extracted_responses_validate = [extract_xml_answer(r, tag='validate') for r in responses]\n rewards = []\n for original_response, extracted_answer, extracted_reasoning, extracted_validate in zip(responses, extracted_responses_answer, extracted_responses_reasoning, extracted_responses_validate):\n is_correct = extracted_answer == answer[0]\n is_int = extracted_answer.isdigit()\n has_answer_tags = '<answer>' in original_response and '</answer>' in original_response\n has_reasoning_tags = '<reasoning>' in original_response and '</reasoning>' in original_response\n has_validate_tags = '<validate>' in original_response and '</validate>' in original_response\n reasoning_length = len(word_tokenize(extracted_reasoning.lower()))\n validate_length = len(word_tokenize(extracted_validate.lower()))\n reward = 0.0\n reasoning_reward = 0.0\n if is_correct:\n reward += 5.0\n if is_int:\n reward += 0.5\n if has_validate_tags:\n reward *= 1.25\n if validate_length >= 5:\n min_validate_length = 5\n max_validate_length = 256\n max_validate_bonus = 3.0\n if validate_length >= min_validate_length:\n if validate_length >= max_validate_length:\n validate_bonus = max_validate_bonus\n else:\n validate_bonus = (validate_length - min_validate_length) / (max_validate_length - min_validate_length) * max_validate_bonus\n else:\n validate_bonus = 0.0\n else:\n validate_bonus = 0.0\n else:\n validate_bonus = 0.0\n if has_reasoning_tags:\n reward *= 1.25\n if reasoning_length >= 5:\n min_scaling_length = 5\n max_scaling_length = 1024\n max_scaling_bonus = 10\n if reasoning_length <= min_scaling_length:\n reasoning_reward = 0.0\n elif reasoning_length >= max_scaling_length:\n reasoning_reward = 5.0\n else:\n reasoning_reward = (reasoning_length - min_scaling_length) / (max_scaling_length - min_scaling_length) * max_scaling_bonus\n else:\n reasoning_reward = 0.0\n else:\n reasoning_reward = 0.0\n total_reward = reward + reasoning_reward + validate_bonus\n if has_validate_tags:\n validate_lower = extracted_validate.lower()\n if re.search('(wait|but|rethink)(?=.{20,})', validate_lower, re.DOTALL):\n total_reward *= 10.0\n rewards.append(total_reward)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[custom_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
lmassaron/Gemma-2-2B-IT-GRPO
|
https://github.com/lmassaron/Gemma-2-2B-IT-GRPO
|
Unknown
|
gemma-grpo.py
|
https://github.com/lmassaron/Gemma-2-2B-IT-GRPO/blob/23802c018aa1cb9ac74fa14bf2391769c44ebb2b/gemma-grpo.py
|
2025-03-24T10:14:45.291361
|
[
{
"name": "correctness_reward_func (from list item 0)",
"code": "def correctness_reward_func(completions, answer, **kwargs):\n \"\"\"Reward function that checks if the answer is correct.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_last_xml_answer(response) for response in responses]\n rewards = [2.0 if extracted == correct else 0.0 for extracted, correct in zip(extracted_responses, answer)]\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward_func (from list item 1)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"Reward function that checks if the completion has the correct format.\"\"\"\n pattern = '^<reasoning>[\\\\s\\\\S]*?<\\\\/reasoning>\\\\s*<answer>[\\\\s\\\\S]*?<\\\\/answer>$'\n responses = [completion[0]['content'] for completion in completions]\n rewards = [1.0 if re.match(pattern, response) else 0.0 for response in responses]\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from [correctness_reward_func, format_reward_func])",
"code": "def correctness_reward_func(completions, answer, **kwargs):\n \"\"\"Reward function that checks if the answer is correct.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_last_xml_answer(response) for response in responses]\n rewards = [2.0 if extracted == correct else 0.0 for extracted, correct in zip(extracted_responses, answer)]\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward_func (from [correctness_reward_func, format_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"Reward function that checks if the completion has the correct format.\"\"\"\n pattern = '^<reasoning>[\\\\s\\\\S]*?<\\\\/reasoning>\\\\s*<answer>[\\\\s\\\\S]*?<\\\\/answer>$'\n responses = [completion[0]['content'] for completion in completions]\n rewards = [1.0 if re.match(pattern, response) else 0.0 for response in responses]\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "params.MODEL_NAME",
"reward_funcs": "[correctness_reward_func, format_reward_func]",
"args": "training_args",
"train_dataset": "gsm8k_train",
"eval_dataset": null,
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
yaosheng216/torch_demo
|
https://github.com/yaosheng216/torch_demo
|
Unknown
|
grpo/distillation_qwen.py
|
https://github.com/yaosheng216/torch_demo/blob/7c441b4fd4f4f71a62035761c206ed7aeba2439a/grpo/distillation_qwen.py
|
2025-03-24T10:14:54.394361
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
erayalp808/GRPO-fine-tuning-turkish-gpt2-350m
|
https://github.com/erayalp808/GRPO-fine-tuning-turkish-gpt2-350m
|
Unknown
|
grpo_training.py
|
https://github.com/erayalp808/GRPO-fine-tuning-turkish-gpt2-350m/blob/5428820ca46cf074d97f957f126b3255a567c441/grpo_training.py
|
2025-03-24T10:15:03.493678
|
[
{
"name": "correctness_reward_func (from list item 0)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_final_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "strict_format_reward_func (from list item 1)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<sebep>\\\\n.*?\\\\n</sebep>\\\\n<cevap>\\\\n.*?\\\\n</cevap>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from list item 2)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<sebep>.*?</sebep>\\\\s*<cevap>.*?</cevap>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "xmlcount_reward_func (from list item 3)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [correctness_reward_func, strict_format_reward_func, soft_format_reward_func, xmlcount_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_final_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "strict_format_reward_func (from [correctness_reward_func, strict_format_reward_func, soft_format_reward_func, xmlcount_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<sebep>\\\\n.*?\\\\n</sebep>\\\\n<cevap>\\\\n.*?\\\\n</cevap>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from [correctness_reward_func, strict_format_reward_func, soft_format_reward_func, xmlcount_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<sebep>.*?</sebep>\\\\s*<cevap>.*?</cevap>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "xmlcount_reward_func (from [correctness_reward_func, strict_format_reward_func, soft_format_reward_func, xmlcount_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "lora_model",
"reward_funcs": "[correctness_reward_func, strict_format_reward_func, soft_format_reward_func, xmlcount_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Asad-Shahab/sudokuLLM
|
https://github.com/Asad-Shahab/sudokuLLM
|
MIT License
|
finetune.py
|
https://github.com/Asad-Shahab/sudokuLLM/blob/4593b0f4b3d80f3afebf18653a279e6cea3b0068/finetune.py
|
2025-03-24T10:15:24.265651
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function for XML formatting details.\"\"\"\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"More lenient reward function for XML format checking.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n return [0.5 if re.match(pattern, r, re.DOTALL) else 0.0 for r in responses]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the correct XML format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n return [0.5 if re.match(pattern, r, re.DOTALL) else 0.0 for r in responses]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if all numbers in the solution are 1-4.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n rewards = []\n for response in responses:\n grid = extract_grid_from_answer(response)\n if grid is None:\n rewards.append(0.0)\n continue\n try:\n if all((all((num in [1, 2, 3, 4] for num in row)) for row in grid)):\n rewards.append(0.5)\n else:\n rewards.append(0.0)\n except:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the Sudoku solution is correct.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n rewards = []\n for response, correct_answer in zip(responses, answer):\n predicted_grid = extract_grid_from_answer(response)\n correct_grid = extract_grid_from_answer(correct_answer)\n if predicted_grid is None or correct_grid is None:\n rewards.append(0.0)\n continue\n if predicted_grid == correct_grid and is_valid_sudoku_solution(predicted_grid):\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function for XML formatting details.\"\"\"\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"More lenient reward function for XML format checking.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n return [0.5 if re.match(pattern, r, re.DOTALL) else 0.0 for r in responses]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the correct XML format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n return [0.5 if re.match(pattern, r, re.DOTALL) else 0.0 for r in responses]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if all numbers in the solution are 1-4.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n rewards = []\n for response in responses:\n grid = extract_grid_from_answer(response)\n if grid is None:\n rewards.append(0.0)\n continue\n try:\n if all((all((num in [1, 2, 3, 4] for num in row)) for row in grid)):\n rewards.append(0.5)\n else:\n rewards.append(0.0)\n except:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the Sudoku solution is correct.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n rewards = []\n for response, correct_answer in zip(responses, answer):\n predicted_grid = extract_grid_from_answer(response)\n correct_grid = extract_grid_from_answer(correct_answer)\n if predicted_grid is None or correct_grid is None:\n rewards.append(0.0)\n continue\n if predicted_grid == correct_grid and is_valid_sudoku_solution(predicted_grid):\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
alxndrTL/gpu-rl
|
https://github.com/alxndrTL/gpu-rl
|
Unknown
|
grpo_gsm8k.py
|
https://github.com/alxndrTL/gpu-rl/blob/1f2bd13c9864049ec94e356f20f0ffb7a1f4b1e3/grpo_gsm8k.py
|
2025-03-24T10:15:26.599891
|
[
{
"name": "format_reasoning_reward (from list item 0)",
"code": "def format_reasoning_reward(prompts, completions, answer, **kwargs) -> list[float]:\n parsed_responses = parse_responses(completions)\n rewards = [0.5 if r['thinking_content'] and r['response'] else 0.0 for r in parsed_responses]\n return rewards",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "format_number_reward (from list item 1)",
"code": "def format_number_reward(prompts, completions, answer, **kwargs) -> list[float]:\n parsed_responses = parse_responses(completions)\n rewards = [0.5 if r['response'].isdigit() else 0.0 for r in parsed_responses]\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "accuracy_reward (from list item 2)",
"code": "def accuracy_reward(prompts, completions, answer, **kwargs) -> list[float]:\n parsed_responses = parse_responses(completions)\n rewards = []\n for r, a in zip(parsed_responses, answer):\n response = r['response'].strip()\n numbers = re.findall('-?\\\\d+', response)\n last_number = numbers[-1] if numbers else ''\n rewards.append(2.0 if last_number == str(a) else 0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "log_rewards (from list item 3)",
"code": "def log_rewards(prompts, completions, answer, **kwargs):\n return 0\n rewards = {'accuracy': accuracy_reward(prompts, completions, answer), 'format_number': format_number_reward(prompts, completions, answer), 'format_reasoning': format_reasoning_reward(prompts, completions, answer)}\n example_response = get_completion_content(completions[0])\n example_parsed = parse_reasoning_response(example_response)\n example_answer = answer[0]\n example_prompt = prompts[0][-1]['content']\n print(f'-' * 50 + f'\\nExample prompt:\\n{example_prompt}\\n' + f'-' * 10 + f'\\nExample response:\\n{example_response}\\n' + f'-' * 10 + f'\\nExample answer:\\n{example_answer}\\n' + f'-' * 10 + f'\\nExample Correct?: {example_parsed['response'] == example_answer}\\n' + f'-' * 10 + f'\\nRewards:\\n{json.dumps(rewards, indent=2)}')\n return 0",
"label": "{\"label\": \"DEBUGGING\"}"
},
{
"name": "format_reasoning_reward (from [format_reasoning_reward, format_number_reward, accuracy_reward, log_rewards])",
"code": "def format_reasoning_reward(prompts, completions, answer, **kwargs) -> list[float]:\n parsed_responses = parse_responses(completions)\n rewards = [0.5 if r['thinking_content'] and r['response'] else 0.0 for r in parsed_responses]\n return rewards",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "format_number_reward (from [format_reasoning_reward, format_number_reward, accuracy_reward, log_rewards])",
"code": "def format_number_reward(prompts, completions, answer, **kwargs) -> list[float]:\n parsed_responses = parse_responses(completions)\n rewards = [0.5 if r['response'].isdigit() else 0.0 for r in parsed_responses]\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "accuracy_reward (from [format_reasoning_reward, format_number_reward, accuracy_reward, log_rewards])",
"code": "def accuracy_reward(prompts, completions, answer, **kwargs) -> list[float]:\n parsed_responses = parse_responses(completions)\n rewards = []\n for r, a in zip(parsed_responses, answer):\n response = r['response'].strip()\n numbers = re.findall('-?\\\\d+', response)\n last_number = numbers[-1] if numbers else ''\n rewards.append(2.0 if last_number == str(a) else 0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "log_rewards (from [format_reasoning_reward, format_number_reward, accuracy_reward, log_rewards])",
"code": "def log_rewards(prompts, completions, answer, **kwargs):\n return 0\n rewards = {'accuracy': accuracy_reward(prompts, completions, answer), 'format_number': format_number_reward(prompts, completions, answer), 'format_reasoning': format_reasoning_reward(prompts, completions, answer)}\n example_response = get_completion_content(completions[0])\n example_parsed = parse_reasoning_response(example_response)\n example_answer = answer[0]\n example_prompt = prompts[0][-1]['content']\n print(f'-' * 50 + f'\\nExample prompt:\\n{example_prompt}\\n' + f'-' * 10 + f'\\nExample response:\\n{example_response}\\n' + f'-' * 10 + f'\\nExample answer:\\n{example_answer}\\n' + f'-' * 10 + f'\\nExample Correct?: {example_parsed['response'] == example_answer}\\n' + f'-' * 10 + f'\\nRewards:\\n{json.dumps(rewards, indent=2)}')\n return 0",
"label": "{\"label\": \"DEBUGGING\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reasoning_reward, format_number_reward, accuracy_reward, log_rewards]",
"args": "training_args",
"train_dataset": "data",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Sam-de-Ham/finetuning-tests
|
https://github.com/Sam-de-Ham/finetuning-tests
|
Unknown
|
full_training_freeze.py
|
https://github.com/Sam-de-Ham/finetuning-tests/blob/7617ee1361314a054f353d2764affb6ace27ec50/full_training_freeze.py
|
2025-03-24T10:15:28.888442
|
[
{
"name": "reward_len",
"code": "def reward_len(completions, **kwargs):\n return [-abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B'",
"reward_funcs": "reward_len",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Sam-de-Ham/finetuning-tests
|
https://github.com/Sam-de-Ham/finetuning-tests
|
Unknown
|
full_training_simple.py
|
https://github.com/Sam-de-Ham/finetuning-tests/blob/7617ee1361314a054f353d2764affb6ace27ec50/full_training_simple.py
|
2025-03-24T10:15:31.105297
|
[
{
"name": "reward_len",
"code": "def reward_len(completions, **kwargs):\n return [-abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B'",
"reward_funcs": "reward_len",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
summerspringwei/alpaca-lora-decompilation
|
https://github.com/summerspringwei/alpaca-lora-decompilation
|
Apache License 2.0
|
models/llmcompiler/grpo_example.py
|
https://github.com/summerspringwei/alpaca-lora-decompilation/blob/3d5fb5344992dd9c6e8a6447feee89dc889921fd/models/llmcompiler/grpo_example.py
|
2025-03-24T10:15:37.883093
|
[
{
"name": "reward_len",
"code": "def reward_len(completions, **kwargs):\n return [-abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'Qwen/Qwen2-0.5B-Instruct'",
"reward_funcs": "reward_len",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
meetrais/LLM-Fine-Tuning
|
https://github.com/meetrais/LLM-Fine-Tuning
|
Unknown
|
Qwen2.5_3B_GRPO.py
|
https://github.com/meetrais/LLM-Fine-Tuning/blob/d5e226e401894795c38e671fef4e117254cfeb51/Qwen2.5_3B_GRPO.py
|
2025-03-24T10:15:47.125877
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
MarcoTuc/xent
|
https://github.com/MarcoTuc/xent
|
Unknown
|
llama-grpo-xent/lab.py
|
https://github.com/MarcoTuc/xent/blob/2a46ba203123eda2e8f195025309af53c0899555/llama-grpo-xent/lab.py
|
2025-03-24T10:15:56.616591
|
[
{
"name": "dummy_reward (from list item 0)",
"code": "def dummy_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n print(f'{len(responses)} completions have been produced')\n for response in responses:\n print(response)\n print('\\n\\n')\n return 0",
"label": "{\"label\": \"DEBUGGING\"}"
},
{
"name": "dummy_reward (from [dummy_reward])",
"code": "def dummy_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n print(f'{len(responses)} completions have been produced')\n for response in responses:\n print(response)\n print('\\n\\n')\n return 0",
"label": "{\"label\": \"DEBUGGING\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[dummy_reward]",
"args": "training_args",
"train_dataset": "dataset['train']",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Sam-de-Ham/finetuning-tests
|
https://github.com/Sam-de-Ham/finetuning-tests
|
Unknown
|
full_training_simple_grpo.py
|
https://github.com/Sam-de-Ham/finetuning-tests/blob/7617ee1361314a054f353d2764affb6ace27ec50/full_training_simple_grpo.py
|
2025-03-24T10:16:01.156066
|
[
{
"name": "reward_len",
"code": "def reward_len(completions, **kwargs):\n return [-abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "reward_len",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
The-Swarm-Corporation/AgentGym
|
https://github.com/The-Swarm-Corporation/AgentGym
|
MIT License
|
grpo_example_two.py
|
https://github.com/The-Swarm-Corporation/AgentGym/blob/baa5184fdbdc48bd64f5bde17909fa8c482c2851/grpo_example_two.py
|
2025-03-24T10:16:07.952736
|
[
{
"name": "reward_len",
"code": "def reward_len(completions, **kwargs):\n return [abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'Qwen/Qwen2-0.5B-Instruct'",
"reward_funcs": "reward_len",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
haoruilee/Awesome-GRPO-training-example
|
https://github.com/haoruilee/Awesome-GRPO-training-example
|
Unknown
|
GRPO-Llama-1B.py
|
https://github.com/haoruilee/Awesome-GRPO-training-example/blob/1a0cf86a50ed4d4602a1b28dbe44c23a83573a11/GRPO-Llama-1B.py
|
2025-03-24T10:16:12.544588
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
xiiiiiiiiii/strategicLearning
|
https://github.com/xiiiiiiiiii/strategicLearning
|
Unknown
|
train_grpo_gsm8k.py
|
https://github.com/xiiiiiiiiii/strategicLearning/blob/f92d0b57e9f7727e0cdad8a5f3ee04b163071ab3/train_grpo_gsm8k.py
|
2025-03-24T10:16:14.791293
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
datawhalechina/unlock-deepseek
|
https://github.com/datawhalechina/unlock-deepseek
|
Unknown
|
Datawhale-R1/train_Datawhale-R1_unsloth.py
|
https://github.com/datawhalechina/unlock-deepseek/blob/7bfaaf6f93dcf2249525392d5310881a58f6f79b/Datawhale-R1/train_Datawhale-R1_unsloth.py
|
2025-03-24T10:16:21.520168
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(prompts, completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for prompt, completion, gt, numbers in zip(prompts, completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if random.random() < 0.3:\n print('-' * 20, f'\\nQuestion:\\n{prompt}', f'\\nCompletion:\\n{completion}', f'\\nResult:\\n{result}', f'\\nTarget:\\n{gt}', f'\\nNumbers:\\n{numbers}')\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(f'\\nQuestion:\\n{prompt}\\nCompletion:\\n{completion}\\nResult:\\n{result}\\nTarget:\\n{gt}\\nNumbers:\\n{numbers}')\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(prompts, completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for prompt, completion, gt, numbers in zip(prompts, completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if random.random() < 0.3:\n print('-' * 20, f'\\nQuestion:\\n{prompt}', f'\\nCompletion:\\n{completion}', f'\\nResult:\\n{result}', f'\\nTarget:\\n{gt}', f'\\nNumbers:\\n{numbers}')\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(f'\\nQuestion:\\n{prompt}\\nCompletion:\\n{completion}\\nResult:\\n{result}\\nTarget:\\n{gt}\\nNumbers:\\n{numbers}')\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Manto/chess-reasoning-zero
|
https://github.com/Manto/chess-reasoning-zero
|
MIT License
|
qwen-1.5b.countdown.py
|
https://github.com/Manto/chess-reasoning-zero/blob/a887574cccdee0a752c80181ce3d6f428acbd52a/qwen-1.5b.countdown.py
|
2025-03-24T10:16:23.784558
|
[
{
"name": "countdown_reward_func",
"code": "def countdown_reward_func(prompts, completions, ground_truth, **kwargs) -> list[float]:\n scores = []\n for prompt, completion, truth in zip(prompts, completions, ground_truth):\n score = compute_score(completion[0]['content'], truth)\n scores.append(score)\n print(scores)\n return scores",
"label": "{\"label\": \"DEBUGGING\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "countdown_reward_func",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "lora_config",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
summerspringwei/alpaca-lora-decompilation
|
https://github.com/summerspringwei/alpaca-lora-decompilation
|
Apache License 2.0
|
models/llmcompiler/grpo_exebench.py
|
https://github.com/summerspringwei/alpaca-lora-decompilation/blob/3d5fb5344992dd9c6e8a6447feee89dc889921fd/models/llmcompiler/grpo_exebench.py
|
2025-03-24T10:16:28.246568
|
[
{
"name": "reward_compilation",
"code": "def reward_compilation(completions, **kwargs):\n original_input = [{} for _ in range(len(completions))]\n predict_list_length = []\n for k, v in kwargs.items():\n for i in range(len(v)):\n original_input[i][k] = v[i]\n validation_list = []\n for row, completion in zip(original_input, completions):\n print(len(tokenizer(completion)['input_ids']))\n match_results = extract_llmcompiler_code_blocks(completion)\n predict_ir = 'Failed to extract IR'\n if len(match_results) > 0:\n predict_ir = match_results[0]\n record = {'file': row['path'], 'predict': [predict_ir], 'output': row['llvm_ir']['code'][-1]}\n record = validate_by_execution(record, row, validation_dir)\n validation_list.append(record)\n predict_list_length.append(len(tokenizer(predict_ir)['input_ids']))\n predict_reward = [1 if r['predict_compile_success'][0] is True else 0 for r in validation_list]\n executable_reward = [1 if r['predict_execution_success'][0] is True else 0 for r in validation_list]\n wandb.log({'results': wandb.Table(columns=['compile', 'executable'], data=[[p, e] for p, e in zip(predict_reward, executable_reward)])})\n return predict_reward",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_path",
"reward_funcs": "reward_compilation",
"args": "training_args",
"train_dataset": "exebench_dataset",
"eval_dataset": null,
"peft_config": "lora_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Oxen-AI/GRPO-With-Cargo-Feedback
|
https://github.com/Oxen-AI/GRPO-With-Cargo-Feedback
|
MIT License
|
train.py
|
https://github.com/Oxen-AI/GRPO-With-Cargo-Feedback/blob/11d0f570898f5764d9a366898ccb3da4c745a378/train.py
|
2025-03-24T10:16:32.752977
|
[
{
"name": "cargo_build_reward_func (from list item 0)",
"code": "@experiment.log(f'cargo_build_rewards.jsonl')\ndef cargo_build_reward_func(prompts, completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_answers = [extract_rust_code(r) for r in responses]\n results = []\n for i, answer in enumerate(extracted_answers):\n data = {'rust_code': answer}\n tools = [RustTool('build')]\n cargo_results = setup_and_test_rust_project(data, tools)\n score = 1.0 if cargo_results['build_passed'] else 0.0\n results.append(score)\n return results",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "cargo_clippy_reward_func (from list item 1)",
"code": "@experiment.log(f'cargo_clippy_rewards.jsonl')\ndef cargo_clippy_reward_func(prompts, completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_answers = [extract_rust_code(r) for r in responses]\n results = []\n for i, answer in enumerate(extracted_answers):\n data = {'rust_code': answer}\n tools = [RustTool('clippy')]\n cargo_results = setup_and_test_rust_project(data, tools)\n score = 1.0 if cargo_results['clippy_passed'] else 0.0\n results.append(score)\n return results",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "cargo_test_reward_func (from list item 2)",
"code": "@experiment.log(f'cargo_test_rewards.jsonl')\ndef cargo_test_reward_func(prompts, completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_codes = [extract_rust_code(r) for r in responses]\n extracted_tests = [extract_test_code(c) for c in extracted_codes]\n results = []\n for i, answer in enumerate(extracted_codes):\n score = 0.0\n if extracted_tests[i]:\n data = {'rust_code': answer}\n tools = [RustTool('test')]\n cargo_results = setup_and_test_rust_project(data, tools)\n score = 2.0 if cargo_results['test_passed'] else 0.0\n results.append(score)\n return results",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "non_empty_reward_func (from list item 3)",
"code": "@experiment.log(f'non_empty_rewards.jsonl')\ndef non_empty_reward_func(prompts, completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [response_contains_more_than_non_empty_line(c) for c in contents]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "test_block_count_reward_func (from list item 4)",
"code": "@experiment.log(f'test_block_count_rewards.jsonl')\ndef test_block_count_reward_func(prompts, completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [response_contains_one_test_block(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "tests_have_asserts_reward_func (from list item 5)",
"code": "@experiment.log(f'tests_have_asserts_rewards.jsonl')\ndef tests_have_asserts_reward_func(prompts, completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [response_contains_asserts(c) for c in contents]",
"label": "{\"label\": \"DEBUGGING\"}"
},
{
"name": "cargo_build_reward_func (from [cargo_build_reward_func, cargo_clippy_reward_func, cargo_test_reward_func, non_empty_reward_func, test_block_count_reward_func, tests_have_asserts_reward_func])",
"code": "@experiment.log(f'cargo_build_rewards.jsonl')\ndef cargo_build_reward_func(prompts, completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_answers = [extract_rust_code(r) for r in responses]\n results = []\n for i, answer in enumerate(extracted_answers):\n data = {'rust_code': answer}\n tools = [RustTool('build')]\n cargo_results = setup_and_test_rust_project(data, tools)\n score = 1.0 if cargo_results['build_passed'] else 0.0\n results.append(score)\n return results",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "cargo_clippy_reward_func (from [cargo_build_reward_func, cargo_clippy_reward_func, cargo_test_reward_func, non_empty_reward_func, test_block_count_reward_func, tests_have_asserts_reward_func])",
"code": "@experiment.log(f'cargo_clippy_rewards.jsonl')\ndef cargo_clippy_reward_func(prompts, completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_answers = [extract_rust_code(r) for r in responses]\n results = []\n for i, answer in enumerate(extracted_answers):\n data = {'rust_code': answer}\n tools = [RustTool('clippy')]\n cargo_results = setup_and_test_rust_project(data, tools)\n score = 1.0 if cargo_results['clippy_passed'] else 0.0\n results.append(score)\n return results",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "cargo_test_reward_func (from [cargo_build_reward_func, cargo_clippy_reward_func, cargo_test_reward_func, non_empty_reward_func, test_block_count_reward_func, tests_have_asserts_reward_func])",
"code": "@experiment.log(f'cargo_test_rewards.jsonl')\ndef cargo_test_reward_func(prompts, completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_codes = [extract_rust_code(r) for r in responses]\n extracted_tests = [extract_test_code(c) for c in extracted_codes]\n results = []\n for i, answer in enumerate(extracted_codes):\n score = 0.0\n if extracted_tests[i]:\n data = {'rust_code': answer}\n tools = [RustTool('test')]\n cargo_results = setup_and_test_rust_project(data, tools)\n score = 2.0 if cargo_results['test_passed'] else 0.0\n results.append(score)\n return results",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "non_empty_reward_func (from [cargo_build_reward_func, cargo_clippy_reward_func, cargo_test_reward_func, non_empty_reward_func, test_block_count_reward_func, tests_have_asserts_reward_func])",
"code": "@experiment.log(f'non_empty_rewards.jsonl')\ndef non_empty_reward_func(prompts, completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [response_contains_more_than_non_empty_line(c) for c in contents]",
"label": "{\"label\": \"DEBUGGING\"}"
},
{
"name": "test_block_count_reward_func (from [cargo_build_reward_func, cargo_clippy_reward_func, cargo_test_reward_func, non_empty_reward_func, test_block_count_reward_func, tests_have_asserts_reward_func])",
"code": "@experiment.log(f'test_block_count_rewards.jsonl')\ndef test_block_count_reward_func(prompts, completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [response_contains_one_test_block(c) for c in contents]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "tests_have_asserts_reward_func (from [cargo_build_reward_func, cargo_clippy_reward_func, cargo_test_reward_func, non_empty_reward_func, test_block_count_reward_func, tests_have_asserts_reward_func])",
"code": "@experiment.log(f'tests_have_asserts_rewards.jsonl')\ndef tests_have_asserts_reward_func(prompts, completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [response_contains_asserts(c) for c in contents]",
"label": "{\"label\": \"DEBUGGING\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[cargo_build_reward_func, cargo_clippy_reward_func, cargo_test_reward_func, non_empty_reward_func, test_block_count_reward_func, tests_have_asserts_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": null,
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": "[OxenTrainerCallback(experiment, bar, commit_every=commit_every.value)]",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
awdemos/awdemos
|
https://github.com/awdemos/awdemos
|
Unknown
|
demos/llm/alpha_maze_finder_grpo/alphamaze_solver.py
|
https://github.com/awdemos/awdemos/blob/f59b9335803e762618c92ec7b6e655a693607555/demos/llm/alpha_maze_finder_grpo/alphamaze_solver.py
|
2025-03-24T10:16:37.352898
|
[
{
"name": "maze_reward (from list item 0)",
"code": "def maze_reward(completions, prompts, **kwargs):\n rewards = []\n for completion in completions:\n game = MazeGame()\n moves = completion.split()\n for move in moves:\n _, done = game.move(move)\n if done:\n rewards.append(1.0)\n break\n else:\n rewards.append(-1.0)\n rewards_tensor = torch.tensor(rewards, dtype=torch.float32, requires_grad=False)\n device = kwargs.get('model', torch.device('cpu')).device if isinstance(kwargs.get('model'), torch.nn.Module) else torch.device('cpu')\n return rewards_tensor.to(device)",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "maze_reward (from [maze_reward])",
"code": "def maze_reward(completions, prompts, **kwargs):\n rewards = []\n for completion in completions:\n game = MazeGame()\n moves = completion.split()\n for move in moves:\n _, done = game.move(move)\n if done:\n rewards.append(1.0)\n break\n else:\n rewards.append(-1.0)\n rewards_tensor = torch.tensor(rewards, dtype=torch.float32, requires_grad=False)\n device = kwargs.get('model', torch.device('cpu')).device if isinstance(kwargs.get('model'), torch.nn.Module) else torch.device('cpu')\n return rewards_tensor.to(device)",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "CustomGRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[maze_reward]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": "tokenizer",
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": "MazeGame",
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
HarleyCoops/TrainingRun
|
https://github.com/HarleyCoops/TrainingRun
|
Unknown
|
grpo_demo.py
|
https://github.com/HarleyCoops/TrainingRun/blob/371054d5438de5f97e2b54d8bdfd8deebbd3fe85/grpo_demo.py
|
2025-03-24T10:16:39.741640
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
erfanzar/EasyDeL
|
https://github.com/erfanzar/EasyDeL
|
Apache License 2.0
|
easydel/scripts/finetune/gsm8k_grpo.py
|
https://github.com/erfanzar/EasyDeL/blob/64a77804783cb790bff1f8c744163915f55aea5f/easydel/scripts/finetune/gsm8k_grpo.py
|
2025-03-24T10:16:46.626204
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [runtime_config.xml_full_match_reward if match else runtime_config.xml_full_match_reject for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [runtime_config.xml_full_match_reward if match else runtime_config.xml_full_match_reject for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, batch, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n answer = processor.batch_decode(batch['answer_ids']) * runtime_config.num_return_sequences\n return [runtime_config.correctness_reward if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [runtime_config.xml_full_match_reward if match else runtime_config.xml_full_match_reject for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [runtime_config.xml_full_match_reward if match else runtime_config.xml_full_match_reject for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, batch, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n answer = processor.batch_decode(batch['answer_ids']) * runtime_config.num_return_sequences\n return [runtime_config.correctness_reward if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": null,
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "processor",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": "grpo_config",
"vinference": "vinference",
"data_tokenize_fn": "data_tokenize_fn",
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
benglard/consciousness
|
https://github.com/benglard/consciousness
|
Unknown
|
llm_safety.py
|
https://github.com/benglard/consciousness/blob/dc7e58655c53bb34d2bc9c1b6fb0c2f26a77b339/llm_safety.py
|
2025-03-24T10:16:48.956696
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if a in r else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "smol_model_predictor (from list item 5)",
"code": "def smol_model_predictor(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n with torch.inference_mode():\n inputs = tokenizer(responses, return_tensors='pt', padding=True, truncation=True).to(device)\n per_token_logps = _get_model_logps(smol_model, inputs)\n out_attn_mask = inputs.attention_mask[:, 1:]\n avg_logps = (per_token_logps * out_attn_mask).sum(dim=1) / out_attn_mask.sum(dim=1)\n return avg_logps.tolist()",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func, smol_model_predictor])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func, smol_model_predictor])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func, smol_model_predictor])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func, smol_model_predictor])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func, smol_model_predictor])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if a in r else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "smol_model_predictor (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func, smol_model_predictor])",
"code": "def smol_model_predictor(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n with torch.inference_mode():\n inputs = tokenizer(responses, return_tensors='pt', padding=True, truncation=True).to(device)\n per_token_logps = _get_model_logps(smol_model, inputs)\n out_attn_mask = inputs.attention_mask[:, 1:]\n avg_logps = (per_token_logps * out_attn_mask).sum(dim=1) / out_attn_mask.sum(dim=1)\n return avg_logps.tolist()",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func, smol_model_predictor]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
nnebp/GPRO-s-game-of-life
|
https://github.com/nnebp/GPRO-s-game-of-life
|
Unknown
|
train_gsm8k_mps.py
|
https://github.com/nnebp/GPRO-s-game-of-life/blob/169c46a84cde5f6deb941bed685fdab0ffd1e11b/train_gsm8k_mps.py
|
2025-03-24T10:16:51.195643
|
[
{
"name": "correctness_reward (from list item 0)",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n \"\"\"Reward function for correct answers\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted = [extract_xml_answer(r) for r in responses]\n return [2.0 if r.strip() == a.strip() else 0.0 for r, a in zip(extracted, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward (from list item 1)",
"code": "def format_reward(completions, **kwargs):\n \"\"\"Reward function for proper format\"\"\"\n pattern = '<reasoning>[\\\\s\\\\S]*?</reasoning>\\\\s*<answer>[\\\\s\\\\S]*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.search(pattern, r)) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "numeric_answer_reward (from list item 2)",
"code": "def numeric_answer_reward(completions, **kwargs):\n \"\"\"Reward function that checks if the answer is numeric\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted = [extract_xml_answer(r) for r in responses]\n\n def is_numeric(text):\n text = text.replace(',', '').replace('$', '').strip()\n try:\n float(text)\n return True\n except:\n return False\n return [0.5 if is_numeric(r) else 0.0 for r in extracted]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward (from [correctness_reward, format_reward, numeric_answer_reward])",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n \"\"\"Reward function for correct answers\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted = [extract_xml_answer(r) for r in responses]\n return [2.0 if r.strip() == a.strip() else 0.0 for r, a in zip(extracted, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward (from [correctness_reward, format_reward, numeric_answer_reward])",
"code": "def format_reward(completions, **kwargs):\n \"\"\"Reward function for proper format\"\"\"\n pattern = '<reasoning>[\\\\s\\\\S]*?</reasoning>\\\\s*<answer>[\\\\s\\\\S]*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.search(pattern, r)) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "numeric_answer_reward (from [correctness_reward, format_reward, numeric_answer_reward])",
"code": "def numeric_answer_reward(completions, **kwargs):\n \"\"\"Reward function that checks if the answer is numeric\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted = [extract_xml_answer(r) for r in responses]\n\n def is_numeric(text):\n text = text.replace(',', '').replace('$', '').strip()\n try:\n float(text)\n return True\n except:\n return False\n return [0.5 if is_numeric(r) else 0.0 for r in extracted]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "args.model_name",
"reward_funcs": "[correctness_reward, format_reward, numeric_answer_reward]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": "tokenizer",
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
jianzhnie/Open-R1
|
https://github.com/jianzhnie/Open-R1
|
Apache License 2.0
|
examples/grpo_gsm8k.py
|
https://github.com/jianzhnie/Open-R1/blob/cbcaa40cf795a99a394db4806685018d06452c23/examples/grpo_gsm8k.py
|
2025-03-24T10:16:53.561361
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
jiangqx0225/llm_run_file
|
https://github.com/jiangqx0225/llm_run_file
|
Unknown
|
unsloth_grpo.py
|
https://github.com/jiangqx0225/llm_run_file/blob/c698e03108035ef3511df5afcc7f2029d25e90a7/unsloth_grpo.py
|
2025-03-24T10:16:55.859060
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
idanshen/multi_ref
|
https://github.com/idanshen/multi_ref
|
Unknown
|
gsm8k_grpo.py
|
https://github.com/idanshen/multi_ref/blob/53c9484f9963d0eb6c320eb7741ca08018aaa350/gsm8k_grpo.py
|
2025-03-24T10:17:00.417588
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": "ref_model",
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
yhfgyyf/GRPO_script
|
https://github.com/yhfgyyf/GRPO_script
|
Unknown
|
grpo_bleu.py
|
https://github.com/yhfgyyf/GRPO_script/blob/af9b2066201156eb07b270f60ccb50b552611249/grpo_bleu.py
|
2025-03-24T10:17:02.749926
|
[
{
"name": "assistant_format_count_reward (from list item 0)",
"code": "def assistant_format_count_reward(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_assistant_format(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "assistant_format_reward_func (from list item 1)",
"code": "def assistant_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the correct [ASSISTANT]...[/ASSISTANT] format.\"\"\"\n pattern = '^\\\\[ASSISTANT\\\\](.*?)\\\\[/ASSISTANT\\\\]$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r, re.DOTALL) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_assistant_format_reward_func (from list item 2)",
"code": "def soft_assistant_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion contains [ASSISTANT]...[/ASSISTANT] tags.\"\"\"\n pattern = '\\\\[ASSISTANT\\\\](.*?)\\\\[/ASSISTANT\\\\]'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.search(pattern, r, re.DOTALL) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "bleu_reward_func (from list item 3)",
"code": "def bleu_reward_func(prompts, completions, **kwargs) -> list[float]:\n \"\"\"\n 计算BLEU奖励分数\n Args:\n prompts: 输入提示\n completions: 模型生成的完成\n Returns:\n float: 奖励分数\n \"\"\"\n responses = []\n for completion in completions:\n if isinstance(completion, list):\n response = completion[0]['content'].replace('[/ASSISTANT]', '')\n else:\n response = completion['content'].replace('[/ASSISTANT]', '')\n if isinstance(response, list):\n response = ' '.join(response)\n responses.append(response)\n query = prompts[0][-1]['content']\n if isinstance(query, list):\n query = ' '.join(query)\n rewards = []\n for response in responses:\n try:\n bleu_score = calculate_bleu4(response, query)\n if bleu_score < 0.4:\n reward = 0.0\n elif bleu_score == 1.0:\n reward = 2.0\n else:\n reward = 1.0 + (bleu_score - 0.4) / 0.6\n rewards.append(reward)\n except Exception as e:\n print(f'Error calculating BLEU score: {e}')\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "assistant_format_count_reward (from [assistant_format_count_reward, assistant_format_reward_func, soft_assistant_format_reward_func, bleu_reward_func])",
"code": "def assistant_format_count_reward(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_assistant_format(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "assistant_format_reward_func (from [assistant_format_count_reward, assistant_format_reward_func, soft_assistant_format_reward_func, bleu_reward_func])",
"code": "def assistant_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the correct [ASSISTANT]...[/ASSISTANT] format.\"\"\"\n pattern = '^\\\\[ASSISTANT\\\\](.*?)\\\\[/ASSISTANT\\\\]$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r, re.DOTALL) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_assistant_format_reward_func (from [assistant_format_count_reward, assistant_format_reward_func, soft_assistant_format_reward_func, bleu_reward_func])",
"code": "def soft_assistant_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion contains [ASSISTANT]...[/ASSISTANT] tags.\"\"\"\n pattern = '\\\\[ASSISTANT\\\\](.*?)\\\\[/ASSISTANT\\\\]'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.search(pattern, r, re.DOTALL) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "bleu_reward_func (from [assistant_format_count_reward, assistant_format_reward_func, soft_assistant_format_reward_func, bleu_reward_func])",
"code": "def bleu_reward_func(prompts, completions, **kwargs) -> list[float]:\n \"\"\"\n 计算BLEU奖励分数\n Args:\n prompts: 输入提示\n completions: 模型生成的完成\n Returns:\n float: 奖励分数\n \"\"\"\n responses = []\n for completion in completions:\n if isinstance(completion, list):\n response = completion[0]['content'].replace('[/ASSISTANT]', '')\n else:\n response = completion['content'].replace('[/ASSISTANT]', '')\n if isinstance(response, list):\n response = ' '.join(response)\n responses.append(response)\n query = prompts[0][-1]['content']\n if isinstance(query, list):\n query = ' '.join(query)\n rewards = []\n for response in responses:\n try:\n bleu_score = calculate_bleu4(response, query)\n if bleu_score < 0.4:\n reward = 0.0\n elif bleu_score == 1.0:\n reward = 2.0\n else:\n reward = 1.0 + (bleu_score - 0.4) / 0.6\n rewards.append(reward)\n except Exception as e:\n print(f'Error calculating BLEU score: {e}')\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[assistant_format_count_reward, assistant_format_reward_func, soft_assistant_format_reward_func, bleu_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Legionof7/GRPOdx
|
https://github.com/Legionof7/GRPOdx
|
Unknown
|
Tic Tac Toe Game.py
|
https://github.com/Legionof7/GRPOdx/blob/b039810b169606493a1e3202dbf1b4d9cec02942/Tic%20Tac%20Toe%20Game.py
|
2025-03-24T10:17:18.716467
|
[
{
"name": "game_reward (from list item 0)",
"code": "def game_reward(completions, **kwargs) -> list[float]:\n return [0.0 for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "game_reward (from [game_reward])",
"code": "def game_reward(completions, **kwargs) -> list[float]:\n return [0.0 for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "CustomGRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[game_reward]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": "TicTacToeGame",
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
avinashreddydev/low-thinking
|
https://github.com/avinashreddydev/low-thinking
|
Apache License 2.0
|
src/grpo_train_math.py
|
https://github.com/avinashreddydev/low-thinking/blob/95a2a8b79d7a863174e5ed33ed199a4116490f8a/src/grpo_train_math.py
|
2025-03-24T10:17:20.948825
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the correct format.\"\"\"\n pattern = '^<reasoning>(?:(?!</reasoning>).)*</reasoning>\\\\n<answer>(?:(?!</answer>).)*</answer>$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.match(pattern, r, re.DOTALL)) for r in responses]\n return [1.0 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from list item 1)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the answer is correct.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [strip_string(extract_xml_answer(r)) for r in responses]\n reasoning_tokens = [extract_reasoning_tokens(r) for r in responses]\n reasoning_lengths = [len(rt.split()) for rt in reasoning_tokens if rt]\n if reasoning_lengths:\n avg_reasoning_length = sum(reasoning_lengths) / len(reasoning_lengths)\n max_reasoning_length = max(reasoning_lengths)\n min_reasoning_length = min(reasoning_lengths)\n else:\n avg_reasoning_length = 0\n max_reasoning_length = 0\n min_reasoning_length = 0\n wandb.log({'avg_reasoning_tokens_length': avg_reasoning_length, 'max_reasoning_tokens_length': max_reasoning_length, 'min_reasoning_tokens_length': min_reasoning_length})\n answer = [strip_string(a) for a in answer]\n print(f'\\n\\n===============================================================\\n\\n\\nCorrect Answer:\\n{answer[0]}\\n\\n---------------------------------------------------------------\\n\\n\\nExtracted: {extracted_responses[0]}\\n\\nCorrectness of all {len(completions)} responses: ' + ''.join(('Y' if RESPONSE_COMPARATOR['di-zhang-fdu/MATH500'](r, a) == True else 'N' for r, a in zip(extracted_responses, answer))))\n reward_list = [2.0 if RESPONSE_COMPARATOR['di-zhang-fdu/MATH500'](r, a) == True else 0.0 for r, a in zip(extracted_responses, answer)]\n return reward_list",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward_func (from [format_reward_func, correctness_reward_func])",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the correct format.\"\"\"\n pattern = '^<reasoning>(?:(?!</reasoning>).)*</reasoning>\\\\n<answer>(?:(?!</answer>).)*</answer>$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.match(pattern, r, re.DOTALL)) for r in responses]\n return [1.0 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from [format_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the answer is correct.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [strip_string(extract_xml_answer(r)) for r in responses]\n reasoning_tokens = [extract_reasoning_tokens(r) for r in responses]\n reasoning_lengths = [len(rt.split()) for rt in reasoning_tokens if rt]\n if reasoning_lengths:\n avg_reasoning_length = sum(reasoning_lengths) / len(reasoning_lengths)\n max_reasoning_length = max(reasoning_lengths)\n min_reasoning_length = min(reasoning_lengths)\n else:\n avg_reasoning_length = 0\n max_reasoning_length = 0\n min_reasoning_length = 0\n wandb.log({'avg_reasoning_tokens_length': avg_reasoning_length, 'max_reasoning_tokens_length': max_reasoning_length, 'min_reasoning_tokens_length': min_reasoning_length})\n answer = [strip_string(a) for a in answer]\n print(f'\\n\\n===============================================================\\n\\n\\nCorrect Answer:\\n{answer[0]}\\n\\n---------------------------------------------------------------\\n\\n\\nExtracted: {extracted_responses[0]}\\n\\nCorrectness of all {len(completions)} responses: ' + ''.join(('Y' if RESPONSE_COMPARATOR['di-zhang-fdu/MATH500'](r, a) == True else 'N' for r, a in zip(extracted_responses, answer))))\n reward_list = [2.0 if RESPONSE_COMPARATOR['di-zhang-fdu/MATH500'](r, a) == True else 0.0 for r, a in zip(extracted_responses, answer)]\n return reward_list",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset_train",
"eval_dataset": "dataset_test",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
zzlzero/CodeLess
|
https://github.com/zzlzero/CodeLess
|
Unknown
|
run_grpo.py
|
https://github.com/zzlzero/CodeLess/blob/b2cb84a16a1764945fd93f4ca6d7fb39a55858b1/run_grpo.py
|
2025-03-24T10:17:23.255479
|
[
{
"name": "len_reward_func (from list item 0)",
"code": "def len_reward_func(completions, **kwargs):\n rewards = []\n max_len = max((len(completion) for completion in completions))\n for completion in completions:\n generation = task.postprocess_generation(completion)\n rewards.append(0.5 - (len(completion) - len(generation)) / (max_len - len(generation) + 1e-06))\n return rewards",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "correct_code_reward_func (from list item 1)",
"code": "def correct_code_reward_func(prompts, completions, test_list, **kwargs):\n generations = []\n references = []\n rewards = []\n for prompt, test, completion in zip(prompts, test_list, completions):\n generation = task.postprocess_generation(completion)\n reference = '\\n'.join(test)\n test_program = generation + '\\n' + reference\n import tempfile\n import subprocess\n with tempfile.NamedTemporaryFile(suffix='.py', delete=False) as temp_file:\n temp_filename = temp_file.name\n temp_file.write(test_program.encode('utf-8'))\n try:\n result = subprocess.run(['python', temp_filename], capture_output=True, text=True, timeout=10)\n if result.returncode == 0:\n rewards.append(1.0)\n if torch.rand(1).item() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_code_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(f'Prompt:\\n{prompt}\\n\\nGeneration:\\n{generation}\\n\\nTest:\\n{reference}\\n')\n else:\n print(f'Test failed with error: {result.stderr}')\n rewards.append(0.0)\n except subprocess.TimeoutExpired:\n print('Test timeout: 执行代码超时')\n rewards.append(0.0)\n except Exception as e:\n print(f'Execution error: {str(e)}')\n rewards.append(0.0)\n finally:\n try:\n os.unlink(temp_filename)\n except:\n pass\n print(f'Reward: {rewards[-1]}')\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "len_reward_func (from [len_reward_func, correct_code_reward_func])",
"code": "def len_reward_func(completions, **kwargs):\n rewards = []\n max_len = max((len(completion) for completion in completions))\n for completion in completions:\n generation = task.postprocess_generation(completion)\n rewards.append(0.5 - (len(completion) - len(generation)) / (max_len - len(generation) + 1e-06))\n return rewards",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "correct_code_reward_func (from [len_reward_func, correct_code_reward_func])",
"code": "def correct_code_reward_func(prompts, completions, test_list, **kwargs):\n generations = []\n references = []\n rewards = []\n for prompt, test, completion in zip(prompts, test_list, completions):\n generation = task.postprocess_generation(completion)\n reference = '\\n'.join(test)\n test_program = generation + '\\n' + reference\n import tempfile\n import subprocess\n with tempfile.NamedTemporaryFile(suffix='.py', delete=False) as temp_file:\n temp_filename = temp_file.name\n temp_file.write(test_program.encode('utf-8'))\n try:\n result = subprocess.run(['python', temp_filename], capture_output=True, text=True, timeout=10)\n if result.returncode == 0:\n rewards.append(1.0)\n if torch.rand(1).item() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_code_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(f'Prompt:\\n{prompt}\\n\\nGeneration:\\n{generation}\\n\\nTest:\\n{reference}\\n')\n else:\n print(f'Test failed with error: {result.stderr}')\n rewards.append(0.0)\n except subprocess.TimeoutExpired:\n print('Test timeout: 执行代码超时')\n rewards.append(0.0)\n except Exception as e:\n print(f'Execution error: {str(e)}')\n rewards.append(0.0)\n finally:\n try:\n os.unlink(temp_filename)\n except:\n pass\n print(f'Reward: {rewards[-1]}')\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[len_reward_func, correct_code_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_args)",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
menloresearch/visual-thinker
|
https://github.com/menloresearch/visual-thinker
|
Unknown
|
training/grpo_stage.py
|
https://github.com/menloresearch/visual-thinker/blob/bb74ee6fbf72b34321edcf2bb958921f694ab622/training/grpo_stage.py
|
2025-03-24T10:17:27.798388
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> List[float]:\n \"\"\"\n Reward function based on proper XML tag usage.\n \n Args:\n completions: Model completions\n \n Returns:\n List of reward scores\n \"\"\"\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 1)",
"code": "def int_reward_func(completions, **kwargs) -> List[float]:\n \"\"\"\n Reward function that checks if responses contain valid direction tokens.\n \n Args:\n completions: Model completions\n \n Returns:\n List of reward scores\n \"\"\"\n allowed_tokens = {'<|up|>', '<|down|>', '<|right|>', '<|left|>'}\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n\n def is_valid_sequence(seq):\n seq_no_whitespace = re.sub('\\\\s+', '', seq)\n if not seq_no_whitespace:\n return False\n found_tokens = re.findall('<\\\\|(?:up|down|right|left)\\\\|>', seq_no_whitespace)\n reconstructed = ''.join(found_tokens)\n if reconstructed != seq_no_whitespace:\n return False\n return all((token in allowed_tokens for token in found_tokens))\n return [1.0 if is_valid_sequence(r) else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward_func (from list item 2)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> List[float]:\n \"\"\"\n Reward function that checks correctness of answers.\n \n Args:\n prompts: Input prompts\n completions: Model completions\n answer: Ground truth answers\n \n Returns:\n List of reward scores\n \"\"\"\n rewards = []\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n logger.debug('-' * 20)\n logger.debug(f'Question:\\n{q}')\n logger.debug(f'\\nAnswer:\\n{answer[0]}')\n logger.debug(f'\\nResponse:\\n{responses[0]}')\n logger.debug(f'\\nExtracted:\\n{extracted_responses[0]}')\n for r, a in zip(extracted_responses, answer):\n if r == a:\n direction = r.split('|><|')\n rewards.append(len(direction) * 0.2)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> List[float]:\n \"\"\"\n Reward function based on proper XML tag usage.\n \n Args:\n completions: Model completions\n \n Returns:\n List of reward scores\n \"\"\"\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> List[float]:\n \"\"\"\n Reward function that checks if responses contain valid direction tokens.\n \n Args:\n completions: Model completions\n \n Returns:\n List of reward scores\n \"\"\"\n allowed_tokens = {'<|up|>', '<|down|>', '<|right|>', '<|left|>'}\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n\n def is_valid_sequence(seq):\n seq_no_whitespace = re.sub('\\\\s+', '', seq)\n if not seq_no_whitespace:\n return False\n found_tokens = re.findall('<\\\\|(?:up|down|right|left)\\\\|>', seq_no_whitespace)\n reconstructed = ''.join(found_tokens)\n if reconstructed != seq_no_whitespace:\n return False\n return all((token in allowed_tokens for token in found_tokens))\n return [1.0 if is_valid_sequence(r) else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> List[float]:\n \"\"\"\n Reward function that checks correctness of answers.\n \n Args:\n prompts: Input prompts\n completions: Model completions\n answer: Ground truth answers\n \n Returns:\n List of reward scores\n \"\"\"\n rewards = []\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n logger.debug('-' * 20)\n logger.debug(f'Question:\\n{q}')\n logger.debug(f'\\nAnswer:\\n{answer[0]}')\n logger.debug(f'\\nResponse:\\n{responses[0]}')\n logger.debug(f'\\nExtracted:\\n{extracted_responses[0]}')\n for r, a in zip(extracted_responses, answer):\n if r == a:\n direction = r.split('|><|')\n rewards.append(len(direction) * 0.2)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
vpareek2/llm-experiments
|
https://github.com/vpareek2/llm-experiments
|
MIT License
|
llama-r1/grpo_trl.py
|
https://github.com/vpareek2/llm-experiments/blob/188644b99675411b0368d92c0cd29ddec0a0821f/llama-r1/grpo_trl.py
|
2025-03-24T10:17:30.134516
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
bbirdxr/GRPO-Qwen2.5-7B-Medicine
|
https://github.com/bbirdxr/GRPO-Qwen2.5-7B-Medicine
|
Unknown
|
trl_grpo.py
|
https://github.com/bbirdxr/GRPO-Qwen2.5-7B-Medicine/blob/7617ccef6880d8cc13137df8def964b619143665/trl_grpo.py
|
2025-03-24T10:17:32.445182
|
[
{
"name": "reward_think_ratio (from list item 0)",
"code": "def reward_think_ratio(completions, **kwargs):\n scores = []\n for completion in completions:\n think_count = completion.count('<think>')\n think_end_count = completion.count('</think>')\n score = -abs(think_count - think_end_count) * 0.5 - abs(think_count - 1) - abs(think_end_count - 1)\n other_tags_count = sum((1 for tag in completion.split('<') if tag and tag.split('>')[0] not in ['think', '/think']))\n score -= other_tags_count\n scores.append(score)\n return scores",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "similarity_sentence_score (from list item 1)",
"code": "def similarity_sentence_score(completions, target, **kwargs):\n scores = []\n for c, t in zip(completions, target):\n c = extract_final_answer(c)\n t = extract_final_answer(t)\n embeddings1 = similarity_model.encode(c)\n embeddings2 = similarity_model.encode(t)\n cosine_scores = cos_sim(embeddings1, embeddings2)\n scores.append(cosine_scores)\n return scores",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correct_score (from list item 2)",
"code": "def correct_score(completions, target, type, clear_answer, **kwargs):\n scores = []\n for c, t, ty, a in zip(completions, target, type, clear_answer):\n print(c)\n c = extract_final_answer(c)\n score = 0.0\n if a in c:\n score += 1.0\n else:\n score += 0.0\n if '最终答案' in c:\n score += 0.5\n else:\n score += 0.0\n scores.append(score)\n return scores",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "reward_think_ratio (from [reward_think_ratio, similarity_sentence_score, correct_score])",
"code": "def reward_think_ratio(completions, **kwargs):\n scores = []\n for completion in completions:\n think_count = completion.count('<think>')\n think_end_count = completion.count('</think>')\n score = -abs(think_count - think_end_count) * 0.5 - abs(think_count - 1) - abs(think_end_count - 1)\n other_tags_count = sum((1 for tag in completion.split('<') if tag and tag.split('>')[0] not in ['think', '/think']))\n score -= other_tags_count\n scores.append(score)\n return scores",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "similarity_sentence_score (from [reward_think_ratio, similarity_sentence_score, correct_score])",
"code": "def similarity_sentence_score(completions, target, **kwargs):\n scores = []\n for c, t in zip(completions, target):\n c = extract_final_answer(c)\n t = extract_final_answer(t)\n embeddings1 = similarity_model.encode(c)\n embeddings2 = similarity_model.encode(t)\n cosine_scores = cos_sim(embeddings1, embeddings2)\n scores.append(cosine_scores)\n return scores",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "correct_score (from [reward_think_ratio, similarity_sentence_score, correct_score])",
"code": "def correct_score(completions, target, type, clear_answer, **kwargs):\n scores = []\n for c, t, ty, a in zip(completions, target, type, clear_answer):\n print(c)\n c = extract_final_answer(c)\n score = 0.0\n if a in c:\n score += 1.0\n else:\n score += 0.0\n if '最终答案' in c:\n score += 0.5\n else:\n score += 0.0\n scores.append(score)\n return scores",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[reward_think_ratio, similarity_sentence_score, correct_score]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
uukuguy/Replicate-R1
|
https://github.com/uukuguy/Replicate-R1
|
MIT License
|
tasks/mini-r1/mini_r1.py
|
https://github.com/uukuguy/Replicate-R1/blob/e050c71aebcdffc75b2ec634bb82e4897510606a/tasks/mini-r1/mini_r1.py
|
2025-03-24T10:17:34.678954
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {\"__builti'ns__\": None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {\"__builti'ns__\": None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_config.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_config)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
chunhuizhang/llm_rl
|
https://github.com/chunhuizhang/llm_rl
|
Unknown
|
tutorials/r1-k1.5/training_grpo.py
|
https://github.com/chunhuizhang/llm_rl/blob/1c2b9baff36b219076b07f5aeeb4f748d7461388/tutorials/r1-k1.5/training_grpo.py
|
2025-03-24T10:17:41.418674
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
TianyiPeng/reproduce-R1-countdown
|
https://github.com/TianyiPeng/reproduce-R1-countdown
|
Apache License 2.0
|
run_r1_grpo.py
|
https://github.com/TianyiPeng/reproduce-R1-countdown/blob/42723af056336392ca33b4bdc687253f7aa99450/run_r1_grpo.py
|
2025-03-24T10:17:45.946440
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_args)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
infinitylogesh/LLM-RL-experiments
|
https://github.com/infinitylogesh/LLM-RL-experiments
|
Unknown
|
train.py
|
https://github.com/infinitylogesh/LLM-RL-experiments/blob/af420409ffd0af7a519d0671ee5fcedb7c767b1c/train.py
|
2025-03-24T10:17:48.243460
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_args)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
manhdo249/T5_TrainDPO
|
https://github.com/manhdo249/T5_TrainDPO
|
Unknown
|
TrainingDPO/training/scripts/run_r1_grpo.py
|
https://github.com/manhdo249/T5_TrainDPO/blob/04588dadb5ee0e20ee0c01143b622630cfbd232e/TrainingDPO/training/scripts/run_r1_grpo.py
|
2025-03-24T10:17:50.515846
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_args)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
zhuopanyang/algorithm_learning
|
https://github.com/zhuopanyang/algorithm_learning
|
Unknown
|
github_model_learning/unlock-deepseek-main/Datawhale-R1/train_Datawhale-R1_unsloth.py
|
https://github.com/zhuopanyang/algorithm_learning/blob/1d124a74926e8159b696b5fff18fb7f4b1d9bb80/github_model_learning/unlock-deepseek-main/Datawhale-R1/train_Datawhale-R1_unsloth.py
|
2025-03-24T10:18:08.865791
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(prompts, completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for prompt, completion, gt, numbers in zip(prompts, completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if random.random() < 0.3:\n print('-' * 20, f'\\nQuestion:\\n{prompt}', f'\\nCompletion:\\n{completion}', f'\\nResult:\\n{result}', f'\\nTarget:\\n{gt}', f'\\nNumbers:\\n{numbers}')\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(f'\\nQuestion:\\n{prompt}\\nCompletion:\\n{completion}\\nResult:\\n{result}\\nTarget:\\n{gt}\\nNumbers:\\n{numbers}')\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(prompts, completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for prompt, completion, gt, numbers in zip(prompts, completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if random.random() < 0.3:\n print('-' * 20, f'\\nQuestion:\\n{prompt}', f'\\nCompletion:\\n{completion}', f'\\nResult:\\n{result}', f'\\nTarget:\\n{gt}', f'\\nNumbers:\\n{numbers}')\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(f'\\nQuestion:\\n{prompt}\\nCompletion:\\n{completion}\\nResult:\\n{result}\\nTarget:\\n{gt}\\nNumbers:\\n{numbers}')\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
minio/blog-assets
|
https://github.com/minio/blog-assets
|
Creative Commons Attribution 4.0 International
|
rl-with-aihub/main.py
|
https://github.com/minio/blog-assets/blob/d6a56ffcb32ae878e77a8c6702dcbf38d29a7950/rl-with-aihub/main.py
|
2025-03-24T10:18:29.499038
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
scchy/RL
|
https://github.com/scchy/RL
|
MIT License
|
src/LLMRL/train_DataWhale-R1.py
|
https://github.com/scchy/RL/blob/38d4e72222d088bdaf82ca1807f41d6d293b67c7/src/LLMRL/train_DataWhale-R1.py
|
2025-03-24T10:18:40.917629
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions: List[AnyStr], **kwargs) -> List[float]:\n \"\"\" \n 格式奖励函数,检查模型输出格式是否匹配:<think>...</think><answer>...</answer>\n \n args:\n completions: 生成的输出\n return:\n 奖励分数\n \"\"\"\n rewards = []\n for cmp in completions:\n try:\n cmp = f'<think>{cmp}'\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, cmp, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions: List[AnyStr], target: List[AnyStr], nums: List[AnyStr], **kwargs) -> List[float]:\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n \n args:\n completions: 生成的输出\n target: 预期的答案\n nums: 可用的数字\n return:\n 奖励分数\n \"\"\"\n rewards = []\n for cmp, gt, numbers in zip(completions, target, nums):\n try:\n cmp = f'<think>{cmp}'\n match = re.search('<answer>(.*?)<\\\\/answer>', cmp)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n res = eval(equation, {'__builtins__': None}, {})\n if abs(float(res) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "thought_len_reward_func (from list item 2)",
"code": "def thought_len_reward_func(completions: List[AnyStr], **kwargs) -> List[float]:\n \"\"\"\n 思考长度奖励函数,检查<think>标签的长度是否大于1000\n \n args:\n completions: 生成的输出\n return:\n 奖励分数\n \"\"\"\n rewards = []\n for cmp in completions:\n try:\n cmp = f'<think>{cmp}'\n match = re.search('<think>(.*?)</think>', cmp)\n if match:\n thought_process = match.group(1).strip()\n if len(thought_process) > 1000:\n rewards.append(1.0)\n else:\n rewards.append(0.0)\n else:\n rewards.append(0.0)\n continue\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func, thought_len_reward_func])",
"code": "def format_reward_func(completions: List[AnyStr], **kwargs) -> List[float]:\n \"\"\" \n 格式奖励函数,检查模型输出格式是否匹配:<think>...</think><answer>...</answer>\n \n args:\n completions: 生成的输出\n return:\n 奖励分数\n \"\"\"\n rewards = []\n for cmp in completions:\n try:\n cmp = f'<think>{cmp}'\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, cmp, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func, thought_len_reward_func])",
"code": "def equation_reward_func(completions: List[AnyStr], target: List[AnyStr], nums: List[AnyStr], **kwargs) -> List[float]:\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n \n args:\n completions: 生成的输出\n target: 预期的答案\n nums: 可用的数字\n return:\n 奖励分数\n \"\"\"\n rewards = []\n for cmp, gt, numbers in zip(completions, target, nums):\n try:\n cmp = f'<think>{cmp}'\n match = re.search('<answer>(.*?)<\\\\/answer>', cmp)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n res = eval(equation, {'__builtins__': None}, {})\n if abs(float(res) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "thought_len_reward_func (from [format_reward_func, equation_reward_func, thought_len_reward_func])",
"code": "def thought_len_reward_func(completions: List[AnyStr], **kwargs) -> List[float]:\n \"\"\"\n 思考长度奖励函数,检查<think>标签的长度是否大于1000\n \n args:\n completions: 生成的输出\n return:\n 奖励分数\n \"\"\"\n rewards = []\n for cmp in completions:\n try:\n cmp = f'<think>{cmp}'\n match = re.search('<think>(.*?)</think>', cmp)\n if match:\n thought_process = match.group(1).strip()\n if len(thought_process) > 1000:\n rewards.append(1.0)\n else:\n rewards.append(0.0)\n else:\n rewards.append(0.0)\n continue\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func, thought_len_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
wyf3/llm_related
|
https://github.com/wyf3/llm_related
|
Unknown
|
deepseek_learn/deepseek_r1_train/deepseek_r1_train.py
|
https://github.com/wyf3/llm_related/blob/b24892f54fb556a9ba0ebdb59207dfe785d6703c/deepseek_learn/deepseek_r1_train/deepseek_r1_train.py
|
2025-03-24T10:18:43.153796
|
[
{
"name": "mark_reward (from list item 0)",
"code": "def mark_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n return [mark_num(response) for response in responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward (from list item 1)",
"code": "def soft_format_reward(completions, **kwargs):\n pattern = '<think>.*?</think>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "hard_format_reward (from list item 2)",
"code": "def hard_format_reward(completions, **kwargs):\n pattern = '^<think>\\\\n.*?n</think>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "digit_reward (from list item 3)",
"code": "def digit_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward (from list item 4)",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n print(f'问题:\\n{prompts[0][-1]['content']}', f'\\n答案:\\n{answer[0]}', f'\\n模型输出:\\n{responses[0]}', f'\\n提取后的答案:\\n{extracted_responses[0]}')\n return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "mark_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def mark_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n return [mark_num(response) for response in responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "soft_format_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def soft_format_reward(completions, **kwargs):\n pattern = '<think>.*?</think>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "hard_format_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def hard_format_reward(completions, **kwargs):\n pattern = '^<think>\\\\n.*?n</think>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "digit_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def digit_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n print(f'问题:\\n{prompts[0][-1]['content']}', f'\\n答案:\\n{answer[0]}', f'\\n模型输出:\\n{responses[0]}', f'\\n提取后的答案:\\n{extracted_responses[0]}')\n return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward]",
"args": "training_args",
"train_dataset": "data",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Bhavinrathava/UnRLearning
|
https://github.com/Bhavinrathava/UnRLearning
|
Unknown
|
src/training.py
|
https://github.com/Bhavinrathava/UnRLearning/blob/740d713668f4c6fb0b34b19c2157106b0ae6b3b0/src/training.py
|
2025-03-24T10:18:56.853652
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>\n <isRelated> 0 or 1 depending if answer is related to Harry Potter </isRelated>\n <normalAnswer> generate normal answer </normalAnswer>\n <anchorWords> generate anchor words from normal answer </anchorWords>\n <cleanAnswer> generate generic answer </cleanAnswer>\n </think>\n <answer> answer here </answer>\n \n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n regex = '^<think>\\\\s*<isRelated>\\\\s*(.*?)\\\\s*<\\\\/isRelated>\\\\s*<normalAnswer>\\\\s*(.*?)\\\\s*<\\\\/normalAnswer>\\\\s*<anchorWords>\\\\s*(.*?)\\\\s*<\\\\/anchorWords>\\\\s*<cleanAnswer>\\\\s*(.*?)\\\\s*<\\\\/cleanAnswer>\\\\s*<\\\\/think>\\\\s*<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 5:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "answer_reward_function (from list item 1)",
"code": "def answer_reward_function(completions, answer, anchor_words, is_related, **kwargs):\n rewards = []\n for output, target_answer, a_w, is_related_tag in zip(completions, answer, anchor_words, is_related):\n reward = 0\n try:\n regex = '^<think>\\\\s*<isRelated>\\\\s*(.*?)\\\\s*<\\\\/isRelated>\\\\s*<normalAnswer>\\\\s*(.*?)\\\\s*<\\\\/normalAnswer>\\\\s*<anchorWords>\\\\s*(.*?)\\\\s*<\\\\/anchorWords>\\\\s*<cleanAnswer>\\\\s*(.*?)\\\\s*<\\\\/cleanAnswer>\\\\s*<\\\\/think>\\\\s*<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, output, re.DOTALL)\n if match is None or len(match.groups()) != 5:\n rewards.append(0.0)\n continue\n else:\n generated_is_related, normal_answer, generated_anchor_words, clean_answer, final_answer = match.groups()\n if generated_is_related == is_related_tag:\n reward += 1\n reward += n_gram_similarity(normal_answer, target_answer)\n reward += n_gram_similarity(generated_anchor_words, a_w)\n reward += check_anchor_words_in_answer(a_w, final_answer)\n rewards.append(reward)\n except Exception as e:\n print(f'Error: {e}')\n rewards.append(0.0)\n continue",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward_func (from [format_reward_func, answer_reward_function])",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>\n <isRelated> 0 or 1 depending if answer is related to Harry Potter </isRelated>\n <normalAnswer> generate normal answer </normalAnswer>\n <anchorWords> generate anchor words from normal answer </anchorWords>\n <cleanAnswer> generate generic answer </cleanAnswer>\n </think>\n <answer> answer here </answer>\n \n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n regex = '^<think>\\\\s*<isRelated>\\\\s*(.*?)\\\\s*<\\\\/isRelated>\\\\s*<normalAnswer>\\\\s*(.*?)\\\\s*<\\\\/normalAnswer>\\\\s*<anchorWords>\\\\s*(.*?)\\\\s*<\\\\/anchorWords>\\\\s*<cleanAnswer>\\\\s*(.*?)\\\\s*<\\\\/cleanAnswer>\\\\s*<\\\\/think>\\\\s*<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 5:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "answer_reward_function (from [format_reward_func, answer_reward_function])",
"code": "def answer_reward_function(completions, answer, anchor_words, is_related, **kwargs):\n rewards = []\n for output, target_answer, a_w, is_related_tag in zip(completions, answer, anchor_words, is_related):\n reward = 0\n try:\n regex = '^<think>\\\\s*<isRelated>\\\\s*(.*?)\\\\s*<\\\\/isRelated>\\\\s*<normalAnswer>\\\\s*(.*?)\\\\s*<\\\\/normalAnswer>\\\\s*<anchorWords>\\\\s*(.*?)\\\\s*<\\\\/anchorWords>\\\\s*<cleanAnswer>\\\\s*(.*?)\\\\s*<\\\\/cleanAnswer>\\\\s*<\\\\/think>\\\\s*<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, output, re.DOTALL)\n if match is None or len(match.groups()) != 5:\n rewards.append(0.0)\n continue\n else:\n generated_is_related, normal_answer, generated_anchor_words, clean_answer, final_answer = match.groups()\n if generated_is_related == is_related_tag:\n reward += 1\n reward += n_gram_similarity(normal_answer, target_answer)\n reward += n_gram_similarity(generated_anchor_words, a_w)\n reward += check_anchor_words_in_answer(a_w, final_answer)\n rewards.append(reward)\n except Exception as e:\n print(f'Error: {e}')\n rewards.append(0.0)\n continue",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_config.model_name_or_path",
"reward_funcs": "[format_reward_func, answer_reward_function]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_config)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
OpenCSGs/opencsg-r1
|
https://github.com/OpenCSGs/opencsg-r1
|
Unknown
|
src/full_train_grpo.py
|
https://github.com/OpenCSGs/opencsg-r1/blob/7704b7b4856d193b043df273bc586b56d66daaf4/src/full_train_grpo.py
|
2025-03-24T10:19:01.366184
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
minwukim/VRL
|
https://github.com/minwukim/VRL
|
Unknown
|
train_qwen0.5b_grpo.py
|
https://github.com/minwukim/VRL/blob/e6aa1718019db1acce0b2c49994827bb88be7e4d/train_qwen0.5b_grpo.py
|
2025-03-24T10:19:03.619079
|
[
{
"name": "reward_len",
"code": "def reward_len(completions, **kwargs):\n return [-abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'Qwen/Qwen2-0.5B-Instruct'",
"reward_funcs": "reward_len",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
SiliangZeng/R1-Experiment
|
https://github.com/SiliangZeng/R1-Experiment
|
Unknown
|
grpo_demo.py
|
https://github.com/SiliangZeng/R1-Experiment/blob/9981999b2af0ac73d967517cdb987cb9355aef4b/grpo_demo.py
|
2025-03-24T10:19:08.189234
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "correctness_reward_func (from list item 0)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from list item 1)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 2)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 3)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 4)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [correctness_reward_func, xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [correctness_reward_func, xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [correctness_reward_func, xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [correctness_reward_func, xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [correctness_reward_func, xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer_new",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[correctness_reward_func, xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
rocke2020/RLHF-exercise
|
https://github.com/rocke2020/RLHF-exercise
|
MIT License
|
grpo/simple_gsm8k/train.py
|
https://github.com/rocke2020/RLHF-exercise/blob/fe27dd4b73236508d7412d7520137a8633a862b0/grpo/simple_gsm8k/train.py
|
2025-03-24T10:19:21.957208
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answers, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answers[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answers)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answers, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answers[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answers)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
OpenCSGs/opencsg-r1
|
https://github.com/OpenCSGs/opencsg-r1
|
Unknown
|
src/lora_train_grpo.py
|
https://github.com/OpenCSGs/opencsg-r1/blob/7704b7b4856d193b043df273bc586b56d66daaf4/src/lora_train_grpo.py
|
2025-03-24T10:19:24.218927
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(prompts, completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for prompt, completion, gt, numbers in zip(prompts, completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if random.random() < 0.3:\n print('-' * 20, f'\\nQuestion:\\n{prompt}', f'\\nCompletion:\\n{completion}', f'\\nResult:\\n{result}', f'\\nTarget:\\n{gt}', f'\\nNumbers:\\n{numbers}')\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(f'\\nQuestion:\\n{prompt}\\nCompletion:\\n{completion}\\nResult:\\n{result}\\nTarget:\\n{gt}\\nNumbers:\\n{numbers}')\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(prompts, completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for prompt, completion, gt, numbers in zip(prompts, completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if random.random() < 0.3:\n print('-' * 20, f'\\nQuestion:\\n{prompt}', f'\\nCompletion:\\n{completion}', f'\\nResult:\\n{result}', f'\\nTarget:\\n{gt}', f'\\nNumbers:\\n{numbers}')\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(f'\\nQuestion:\\n{prompt}\\nCompletion:\\n{completion}\\nResult:\\n{result}\\nTarget:\\n{gt}\\nNumbers:\\n{numbers}')\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
syafiq/reasoning
|
https://github.com/syafiq/reasoning
|
Unknown
|
src/grpo_qwen.py
|
https://github.com/syafiq/reasoning/blob/6130b0d2b0dc71a446de9d5b5d48678c101baf7f/src/grpo_qwen.py
|
2025-03-24T10:19:35.772726
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the expected XML format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.search(pattern, r, re.DOTALL)) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "vulnerability_identification_func (from list item 1)",
"code": "def vulnerability_identification_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the model identifies vulnerability status clearly.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n contains_vulnerable = ['vulnerable' in r.lower() for r in extracted_responses]\n contains_cwe = [bool(re.search('cwe-\\\\d+|common weakness enumeration', r.lower())) for r in extracted_responses]\n rewards = []\n for vuln, cwe in zip(contains_vulnerable, contains_cwe):\n if vuln and cwe:\n rewards.append(0.5)\n elif vuln:\n rewards.append(0.2)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "correctness_reward_func (from list item 2)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nExpected:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n rewards = []\n for r, a in zip(extracted_responses, answer):\n r_lower = r.lower()\n a_lower = a.lower()\n if 'vulnerable' in a_lower and 'vulnerable' in r_lower and ('not vulnerable' not in a_lower):\n if ':' in a:\n try:\n cwe_types = a.split('Vulnerable: ')[1].split(',')\n cwe_correct = any((cwe_id.lower() in r_lower for cwe_id in cwe_types))\n rewards.append(2.0 if cwe_correct else 1.0)\n except IndexError:\n rewards.append(1.0)\n else:\n rewards.append(1.5)\n elif 'not vulnerable' in a_lower and 'not vulnerable' in r_lower:\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward_func (from [format_reward_func, vulnerability_identification_func, correctness_reward_func])",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the expected XML format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.search(pattern, r, re.DOTALL)) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "vulnerability_identification_func (from [format_reward_func, vulnerability_identification_func, correctness_reward_func])",
"code": "def vulnerability_identification_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the model identifies vulnerability status clearly.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n contains_vulnerable = ['vulnerable' in r.lower() for r in extracted_responses]\n contains_cwe = [bool(re.search('cwe-\\\\d+|common weakness enumeration', r.lower())) for r in extracted_responses]\n rewards = []\n for vuln, cwe in zip(contains_vulnerable, contains_cwe):\n if vuln and cwe:\n rewards.append(0.5)\n elif vuln:\n rewards.append(0.2)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "correctness_reward_func (from [format_reward_func, vulnerability_identification_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nExpected:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n rewards = []\n for r, a in zip(extracted_responses, answer):\n r_lower = r.lower()\n a_lower = a.lower()\n if 'vulnerable' in a_lower and 'vulnerable' in r_lower and ('not vulnerable' not in a_lower):\n if ':' in a:\n try:\n cwe_types = a.split('Vulnerable: ')[1].split(',')\n cwe_correct = any((cwe_id.lower() in r_lower for cwe_id in cwe_types))\n rewards.append(2.0 if cwe_correct else 1.0)\n except IndexError:\n rewards.append(1.0)\n else:\n rewards.append(1.5)\n elif 'not vulnerable' in a_lower and 'not vulnerable' in r_lower:\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward_func, vulnerability_identification_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "filtered_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Qsingle/open-medical-r1
|
https://github.com/Qsingle/open-medical-r1
|
Apache License 2.0
|
src/open_r1/grpo.py
|
https://github.com/Qsingle/open-medical-r1/blob/a41209173d3adf08d4928db64cafaff255ab34d8/src/open_r1/grpo.py
|
2025-03-24T10:19:42.620703
|
[
{
"name": "Potential lambda reward: lambda_0",
"code": "lambda: ['accuracy', 'format', 'xmlcount_reward_func']",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "reward_funcs",
"args": "training_args",
"train_dataset": "dataset[script_args.dataset_train_split]",
"eval_dataset": "dataset[script_args.dataset_test_split] if training_args.eval_strategy != 'no' else None",
"peft_config": "get_peft_config(model_args)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "get_callbacks(training_args, model_args)",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
cttmayi/AIDemo
|
https://github.com/cttmayi/AIDemo
|
Unknown
|
fine-tune/deepseek_r1/v5_u_grpo.py
|
https://github.com/cttmayi/AIDemo/blob/6d98e58035e5478966a1a76241c680210c6f942c/fine-tune/deepseek_r1/v5_u_grpo.py
|
2025-03-24T10:19:44.883095
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Eric-is-good/happyR1
|
https://github.com/Eric-is-good/happyR1
|
Unknown
|
grpo_train.py
|
https://github.com/Eric-is-good/happyR1/blob/8688febba25995132ab51a0ccac4191fd26c75a5/grpo_train.py
|
2025-03-24T10:19:47.144650
|
[
{
"name": "length_reward_func (from list item 0)",
"code": "def length_reward_func(completions, **kwargs):\n score = [float(len(completion[0]['content'])) * 0.002 for completion in completions]\n return score",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "format_reward_func (from list item 1)",
"code": "def format_reward_func(completions, **kwargs):\n pattern = '^<think>.*?</think>\\\\s*<answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content, re.DOTALL) for content in completion_contents]\n score = [1.5 if match else -0.5 for match in matches]\n return score",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "answer_reward_func (from list item 2)",
"code": "def answer_reward_func(completions, answer, **kwargs):\n completions_matches = [re.search('####\\\\s*(\\\\d+)', str(c)) for c in completions]\n completions_ = [match.group(1) if match else '' for match in completions_matches]\n ground_truth_matches = [re.search('####\\\\s*(\\\\d+)', str(c)) for c in answer]\n ground_truth_ = [match.group(1) if match else '' for match in ground_truth_matches]\n score = [3.0 if c.strip() == gt.strip() else -1.0 for c, gt in zip(completions_, ground_truth_)]\n best_answer = None\n max_length = 0\n for c, s in zip(completions, score):\n if s == 3.0:\n if len(c) > max_length:\n max_length = len(c)\n best_answer = c\n if best_answer:\n print(best_answer)\n return score",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "length_reward_func (from [length_reward_func, format_reward_func, answer_reward_func])",
"code": "def length_reward_func(completions, **kwargs):\n score = [float(len(completion[0]['content'])) * 0.002 for completion in completions]\n return score",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "format_reward_func (from [length_reward_func, format_reward_func, answer_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n pattern = '^<think>.*?</think>\\\\s*<answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content, re.DOTALL) for content in completion_contents]\n score = [1.5 if match else -0.5 for match in matches]\n return score",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "answer_reward_func (from [length_reward_func, format_reward_func, answer_reward_func])",
"code": "def answer_reward_func(completions, answer, **kwargs):\n completions_matches = [re.search('####\\\\s*(\\\\d+)', str(c)) for c in completions]\n completions_ = [match.group(1) if match else '' for match in completions_matches]\n ground_truth_matches = [re.search('####\\\\s*(\\\\d+)', str(c)) for c in answer]\n ground_truth_ = [match.group(1) if match else '' for match in ground_truth_matches]\n score = [3.0 if c.strip() == gt.strip() else -1.0 for c, gt in zip(completions_, ground_truth_)]\n best_answer = None\n max_length = 0\n for c, s in zip(completions, score):\n if s == 3.0:\n if len(c) > max_length:\n max_length = len(c)\n best_answer = c\n if best_answer:\n print(best_answer)\n return score",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'Qwen/Qwen2.5-3B-Instruct'",
"reward_funcs": "[length_reward_func, format_reward_func, answer_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
ZenWisty/SelfLearnAssis_BasedOnLanguageModel
|
https://github.com/ZenWisty/SelfLearnAssis_BasedOnLanguageModel
|
MIT License
|
doc/DLReasoningDeepSeekR1/Reproduce_DeepSeek_r1.py
|
https://github.com/ZenWisty/SelfLearnAssis_BasedOnLanguageModel/blob/c003a35770af43612821fa1eaf3ccb2e54455047/doc/DLReasoningDeepSeekR1/Reproduce_DeepSeek_r1.py
|
2025-03-24T10:19:49.416490
|
[
{
"name": "mark_reward (from list item 0)",
"code": "def mark_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n return [mark_num(response) for response in responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "soft_format_reward (from list item 1)",
"code": "def soft_format_reward(completions, **kwargs):\n pattern = '<think>.*?</think>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "hard_format_reward (from list item 2)",
"code": "def hard_format_reward(completions, **kwargs):\n pattern = '^<think>\\\\n\\\\.*?n</think>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "digit_reward (from list item 3)",
"code": "def digit_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward (from list item 4)",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n print(f'问题:\\n{prompts[0][-1]['content']}', f'\\n答案:\\n{answer[0]}', f'\\n模型输出:\\n{responses[0]}', f'\\n提取后的答案:\\n{extracted_responses[0]}')\n return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "mark_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def mark_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n return [mark_num(response) for response in responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def soft_format_reward(completions, **kwargs):\n pattern = '<think>.*?</think>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "hard_format_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def hard_format_reward(completions, **kwargs):\n pattern = '^<think>\\\\n\\\\.*?n</think>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "digit_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def digit_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n print(f'问题:\\n{prompts[0][-1]['content']}', f'\\n答案:\\n{answer[0]}', f'\\n模型输出:\\n{responses[0]}', f'\\n提取后的答案:\\n{extracted_responses[0]}')\n return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward]",
"args": "training_args",
"train_dataset": "data",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
jasonacox/ProtosAI
|
https://github.com/jasonacox/ProtosAI
|
MIT License
|
llm/grpo.py
|
https://github.com/jasonacox/ProtosAI/blob/44e93e6acc9379be0a821a5d54b5f123bba91c67/llm/grpo.py
|
2025-03-24T10:19:58.428639
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
jianzhnie/Open-R1
|
https://github.com/jianzhnie/Open-R1
|
Apache License 2.0
|
examples/grpo_demo.py
|
https://github.com/jianzhnie/Open-R1/blob/cbcaa40cf795a99a394db4806685018d06452c23/examples/grpo_demo.py
|
2025-03-24T10:20:09.148792
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n\n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write('\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n\n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write('\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n\n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write('\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n\n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write('\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_args)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
nnebp/GPRO-s-game-of-life
|
https://github.com/nnebp/GPRO-s-game-of-life
|
Unknown
|
train_gol_grpo.py
|
https://github.com/nnebp/GPRO-s-game-of-life/blob/169c46a84cde5f6deb941bed685fdab0ffd1e11b/train_gol_grpo.py
|
2025-03-24T10:20:16.161368
|
[
{
"name": "correctness_reward (from list item 0)",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n \"\"\"Reward function for correct Game of Life next states\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted = [extract_xml_answer(r) for r in responses]\n rewards = []\n for resp, ans in zip(extracted, answer):\n resp_clean = re.sub('\\\\s+', '', resp)\n ans_clean = re.sub('\\\\s+', '', ans)\n if resp_clean == ans_clean:\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward (from list item 1)",
"code": "def format_reward(completions, **kwargs):\n \"\"\"Reward function for proper format\"\"\"\n pattern = '<reasoning>[\\\\s\\\\S]*?</reasoning>\\\\s*<answer>[\\\\s\\\\S]*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.search(pattern, r)) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "reasoning_quality_reward (from list item 2)",
"code": "def reasoning_quality_reward(prompts, completions, answer, explanation, **kwargs):\n \"\"\"Reward function for quality of reasoning\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n rewards = []\n for resp, exp in zip(responses, explanation):\n if '<reasoning>' in resp and '</reasoning>' in resp:\n reasoning = resp.split('<reasoning>')[-1].split('</reasoning>')[0].strip()\n key_concepts = ['live cell', 'dead cell', 'neighbor', 'underpopulation', 'overpopulation', 'reproduction', 'survives', 'dies', 'born']\n concept_count = sum((1 for concept in key_concepts if concept.lower() in reasoning.lower()))\n rewards.append(min(0.5, concept_count / len(key_concepts)))\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward (from [correctness_reward, format_reward, reasoning_quality_reward])",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n \"\"\"Reward function for correct Game of Life next states\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted = [extract_xml_answer(r) for r in responses]\n rewards = []\n for resp, ans in zip(extracted, answer):\n resp_clean = re.sub('\\\\s+', '', resp)\n ans_clean = re.sub('\\\\s+', '', ans)\n if resp_clean == ans_clean:\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward (from [correctness_reward, format_reward, reasoning_quality_reward])",
"code": "def format_reward(completions, **kwargs):\n \"\"\"Reward function for proper format\"\"\"\n pattern = '<reasoning>[\\\\s\\\\S]*?</reasoning>\\\\s*<answer>[\\\\s\\\\S]*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.search(pattern, r)) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "reasoning_quality_reward (from [correctness_reward, format_reward, reasoning_quality_reward])",
"code": "def reasoning_quality_reward(prompts, completions, answer, explanation, **kwargs):\n \"\"\"Reward function for quality of reasoning\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n rewards = []\n for resp, exp in zip(responses, explanation):\n if '<reasoning>' in resp and '</reasoning>' in resp:\n reasoning = resp.split('<reasoning>')[-1].split('</reasoning>')[0].strip()\n key_concepts = ['live cell', 'dead cell', 'neighbor', 'underpopulation', 'overpopulation', 'reproduction', 'survives', 'dies', 'born']\n concept_count = sum((1 for concept in key_concepts if concept.lower() in reasoning.lower()))\n rewards.append(min(0.5, concept_count / len(key_concepts)))\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "MODEL_NAME",
"reward_funcs": "[correctness_reward, format_reward, reasoning_quality_reward]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "val_dataset",
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
tylerthecoder/func-ctrl-demo
|
https://github.com/tylerthecoder/func-ctrl-demo
|
Unknown
|
server/src/training/rl_agent.py
|
https://github.com/tylerthecoder/func-ctrl-demo/blob/25356e8bcab34c7b43625f721ef6500ad056a265/server/src/training/rl_agent.py
|
2025-03-24T10:20:18.493852
|
[
{
"name": "custom_reward_function",
"code": "def custom_reward_function(messages: List[Dict[str, str]]) -> float:\n return float(sum((len(msg['content']) for msg in messages)))",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "custom_reward_function",
"args": "training_args",
"train_dataset": "None",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": "tokenizer",
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
ralphbutler/LLM_misc
|
https://github.com/ralphbutler/LLM_misc
|
Unknown
|
reinforcement_learning_for_reasoning/train_numina.py
|
https://github.com/ralphbutler/LLM_misc/blob/94473185408f416ce762e8510678043cf1912486/reinforcement_learning_for_reasoning/train_numina.py
|
2025-03-24T10:20:20.752790
|
[
{
"name": "format_reward (from list item 0)",
"code": "def format_reward(completions, **kwargs):\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<think>.*?</think>\\\\s*<answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content) for content in completion_contents]\n rewards_list = [1.0 if match else 0.0 for match in matches]\n return [1.0 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "accuracy_reward (from list item 1)",
"code": "def accuracy_reward(completions, **kwargs):\n \"\"\"Reward function that checks if the completion is the same as the ground truth.\"\"\"\n solutions = kwargs['solution']\n completion_contents = [completion[0]['content'] for completion in completions]\n rewards = []\n for content, solution in zip(completion_contents, solutions):\n gold_parsed = parse(solution, extraction_mode='first_match', extraction_config=[LatexExtractionConfig()])\n answer_parsed = parse(content, extraction_mode='first_match', extraction_config=[LatexExtractionConfig()])\n if len(gold_parsed) != 0:\n try:\n rewards.append(float(verify(answer_parsed, gold_parsed)))\n except Exception:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward (from [format_reward, accuracy_reward])",
"code": "def format_reward(completions, **kwargs):\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<think>.*?</think>\\\\s*<answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content) for content in completion_contents]\n rewards_list = [1.0 if match else 0.0 for match in matches]\n return [1.0 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "accuracy_reward (from [format_reward, accuracy_reward])",
"code": "def accuracy_reward(completions, **kwargs):\n \"\"\"Reward function that checks if the completion is the same as the ground truth.\"\"\"\n solutions = kwargs['solution']\n completion_contents = [completion[0]['content'] for completion in completions]\n rewards = []\n for content, solution in zip(completion_contents, solutions):\n gold_parsed = parse(solution, extraction_mode='first_match', extraction_config=[LatexExtractionConfig()])\n answer_parsed = parse(content, extraction_mode='first_match', extraction_config=[LatexExtractionConfig()])\n if len(gold_parsed) != 0:\n try:\n rewards.append(float(verify(answer_parsed, gold_parsed)))\n except Exception:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward, accuracy_reward]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
bdsaglam/pipeline-grpo
|
https://github.com/bdsaglam/pipeline-grpo
|
Unknown
|
nbs/train_unsloth.py
|
https://github.com/bdsaglam/pipeline-grpo/blob/a70823fda7e3e704cb8f5372b3e7435f50280cca/nbs/train_unsloth.py
|
2025-03-24T10:20:37.056048
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
chloeji8888/deepchess
|
https://github.com/chloeji8888/deepchess
|
Unknown
|
chess_gym_colab.py
|
https://github.com/chloeji8888/deepchess/blob/31a2877efa6441ba312db8b031a961383a699ddb/chess_gym_colab.py
|
2025-03-24T10:20:50.857420
|
[
{
"name": "reward_function",
"code": "def reward_function(prompts, completions):\n rewards = []\n samples_to_log = []\n env = ChessEnv(stockfish_path=stockfish_path)\n try:\n for prompt, completion in zip(prompts, completions):\n try:\n env._init_engine()\n env.configure_from_prompt(prompt)\n move = re.search('([KQRNB]?[a-h]?[1-8]?x?[a-h][1-8](=[QRNB])?|O-O|O-O-O)[+#]?', completion).group(0)\n obs, reward, terminated, _, _ = env.step(move)\n rewards.append(reward)\n samples_to_log.append({'prompt': prompt, 'completion': completion, 'move': move, 'reward': reward})\n except Exception as e:\n print(e)\n rewards.append(-0.5)\n samples_to_log.append({'prompt': prompt, 'completion': completion, 'move': 'INVALID', 'reward': -0.5})\n finally:\n env.close()\n if wandb.run is not None:\n wandb.log({'samples': wandb.Table(data=[[s['prompt'], s['completion'], s['move'], s['reward']] for s in samples_to_log[:5]], columns=['prompt', 'completion', 'move', 'reward'])})\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "reward_function",
"args": "grpo_config",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
afirez/AlphaChatGPT
|
https://github.com/afirez/AlphaChatGPT
|
Unknown
|
alphachatgpt/case_09_deepseek_r1/case_01_llm_grpo/grpo_demo.py
|
https://github.com/afirez/AlphaChatGPT/blob/2f585ad1043f3792ad8a63a81dd88ed42996c648/alphachatgpt/case_09_deepseek_r1/case_01_llm_grpo/grpo_demo.py
|
2025-03-24T10:20:53.111999
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Named666/AlphaAnon
|
https://github.com/Named666/AlphaAnon
|
Unknown
|
grpo.py
|
https://github.com/Named666/AlphaAnon/blob/ce04ff76f5fdebd2273994bd492e888676411563/grpo.py
|
2025-03-24T10:21:08.904057
|
[
{
"name": "reward_wrapper (from list item 0)",
"code": "def reward_wrapper(prompts, completions, **kwargs):\n rewards = []\n for prompt, completion in zip(prompts, completions):\n dataset_completion = prompt_to_completion.get(prompt, '')\n reward = reward_function(prompt, completion, dataset_completion)\n rewards.append(reward)\n return rewards",
"label": "{\"label\": \"DEBUGGING\"}"
},
{
"name": "reward_wrapper (from [reward_wrapper])",
"code": "def reward_wrapper(prompts, completions, **kwargs):\n rewards = []\n for prompt, completion in zip(prompts, completions):\n dataset_completion = prompt_to_completion.get(prompt, '')\n reward = reward_function(prompt, completion, dataset_completion)\n rewards.append(reward)\n return rewards",
"label": "{\"label\": \"DEBUGGING\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[reward_wrapper]",
"args": "training_args",
"train_dataset": "dataset['train']",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
dotieuthien/test-modal
|
https://github.com/dotieuthien/test-modal
|
Unknown
|
test_r1/train_example.py
|
https://github.com/dotieuthien/test-modal/blob/2de0aaf7aef7c114be7803b36c41a013c217a5ca/test_r1/train_example.py
|
2025-03-24T10:21:20.259173
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs(os.path.join(run_folder, 'completion_samples'), exist_ok=True)\n log_file = os.path.join(run_folder, 'completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs(os.path.join(run_folder, 'completion_samples'), exist_ok=True)\n log_file = os.path.join(run_folder, 'completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, target, **kwargs):\n \"\"\"\n Format: <think>...</think><answer>...</answer>\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt in zip(completions, target):\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs(os.path.join(run_folder, 'completion_samples'), exist_ok=True)\n log_file = os.path.join(run_folder, 'completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n Evaluates completions based on:\n 2. Mathematical correctness of the answer\n\n Args:\n completions (list[str]): Generated outputs\n target (list[str]): Expected answers\n nums (list[str]): Available numbers\n \n Returns:\n list[float]: Reward scores\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs(os.path.join(run_folder, 'completion_samples'), exist_ok=True)\n log_file = os.path.join(run_folder, 'completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": "get_peft_config(model_args)",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
datawhalechina/unlock-deepseek
|
https://github.com/datawhalechina/unlock-deepseek
|
Unknown
|
Datawhale-R1/train_Datawhale-R1.py
|
https://github.com/datawhalechina/unlock-deepseek/blob/7bfaaf6f93dcf2249525392d5310881a58f6f79b/Datawhale-R1/train_Datawhale-R1.py
|
2025-03-24T10:22:00.930207
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
mesolitica/malaya
|
https://github.com/mesolitica/malaya
|
MIT License
|
session/small-malaysian-reasoning/train_grpo.py
|
https://github.com/mesolitica/malaya/blob/0a1bfd89e56046f8a6c52d6c193381a7bf6ee25b/session/small-malaysian-reasoning/train_grpo.py
|
2025-03-24T10:22:05.407633
|
[
{
"name": "length_reward_func (from list item 0)",
"code": "def length_reward_func(completions, **kwargs):\n \"\"\"Reward function that gives higher scores to longer completions.\"\"\"\n return [float(len(completion[0]['content'].split()) / 4096) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "format_reward_func (from list item 1)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<think>.*?</think><answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content) for content in completion_contents]\n return [1.0 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correct_reward_func (from list item 2)",
"code": "def correct_reward_func(completions, ground_truth, **kwargs):\n matches = [re.search('\\\\\\\\boxed\\\\{(.*?)\\\\}', completion[0]['content']) for completion in completions]\n contents = [match.group(1) if match else '' for match in matches]\n return [1.0 if c == gt else 0.0 for c, gt in zip(contents, ground_truth)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "length_reward_func (from [length_reward_func, format_reward_func, correct_reward_func])",
"code": "def length_reward_func(completions, **kwargs):\n \"\"\"Reward function that gives higher scores to longer completions.\"\"\"\n return [float(len(completion[0]['content'].split()) / 4096) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "format_reward_func (from [length_reward_func, format_reward_func, correct_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<think>.*?</think><answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content) for content in completion_contents]\n return [1.0 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correct_reward_func (from [length_reward_func, format_reward_func, correct_reward_func])",
"code": "def correct_reward_func(completions, ground_truth, **kwargs):\n matches = [re.search('\\\\\\\\boxed\\\\{(.*?)\\\\}', completion[0]['content']) for completion in completions]\n contents = [match.group(1) if match else '' for match in matches]\n return [1.0 if c == gt else 0.0 for c, gt in zip(contents, ground_truth)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[length_reward_func, format_reward_func, correct_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Zeyi-Lin/easy-r1
|
https://github.com/Zeyi-Lin/easy-r1
|
Unknown
|
train.py
|
https://github.com/Zeyi-Lin/easy-r1/blob/5cdca2dedf05b567e941effc97b68d4d989698df/train.py
|
2025-03-24T10:22:09.265501
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"\n Reward function that counts the number of XML tags in the completion.\n 计算文本中XML标签的数量。\n \"\"\"\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"\n Reward function that checks if the completion has a specific format.\n 检查完成情况是否具有 特定格式 的奖励函数(软)。\n \"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"\n Reward function that checks if the completion has a specific format.\n 检查完成情况是否具有 特定格式 的奖励函数(严格)。\n \"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"\n Reward function that checks if the completion is an integer.\n 检查完成情况是否为 整数 的奖励函数。\n \"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"\n Reward function that checks if the completion is correct.\n 检查完成情况是否 正确 的奖励函数。\n \"\"\"\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"\n Reward function that counts the number of XML tags in the completion.\n 计算文本中XML标签的数量。\n \"\"\"\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"\n Reward function that checks if the completion has a specific format.\n 检查完成情况是否具有 特定格式 的奖励函数(软)。\n \"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"\n Reward function that checks if the completion has a specific format.\n 检查完成情况是否具有 特定格式 的奖励函数(严格)。\n \"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"\n Reward function that checks if the completion is an integer.\n 检查完成情况是否为 整数 的奖励函数。\n \"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"\n Reward function that checks if the completion is correct.\n 检查完成情况是否 正确 的奖励函数。\n \"\"\"\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": "[swanlab_callback]",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
manavgup/grpo_granite
|
https://github.com/manavgup/grpo_granite
|
Apache License 2.0
|
src/base_trainer.py
|
https://github.com/manavgup/grpo_granite/blob/23bf29637b46736c2e949a7a1bc3a5120f26dc74/src/base_trainer.py
|
2025-03-24T10:22:11.515084
|
[
{
"name": "get_reward_functions (from self.get_reward_functions())",
"code": "@abstractmethod\ndef get_reward_functions(self) -> List:\n \"\"\"Get list of reward functions.\"\"\"\n pass",
"label": "{\"label\": \"DEBUGGING\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "self.model_args.model_name_or_path",
"reward_funcs": "self.get_reward_functions()",
"args": "self.training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
pegasi-ai/feather
|
https://github.com/pegasi-ai/feather
|
GNU Affero General Public License v3.0
|
examples/deepseek_1_5b_finqa_reasoner.py
|
https://github.com/pegasi-ai/feather/blob/bed61853c927a65541ed0e66844af9e0fea02b0d/examples/deepseek_1_5b_finqa_reasoner.py
|
2025-03-24T10:22:20.754689
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Calculate granular rewards based on XML tag counts and formatting.\"\"\"\n if not completions:\n return [0.0]\n contents = [completion[0]['content'] if isinstance(completion, list) and len(completion) > 0 and isinstance(completion[0], dict) and ('content' in completion[0]) else '' for completion in completions]\n rewards = [count_xml(c) for c in contents]\n return ensure_list_length(rewards, len(completions))",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 1)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format with exact newlines.\"\"\"\n if not completions:\n return [0.0]\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] if isinstance(completion, list) and len(completion) > 0 and isinstance(completion[0], dict) and ('content' in completion[0]) else '' for completion in completions]\n matches = [bool(re.match(pattern, r, re.DOTALL)) for r in responses]\n return ensure_list_length([0.5 if match else 0.0 for match in matches], len(completions))",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 2)",
"code": "def int_reward_func(completions, db_set, **kwargs) -> list[float]:\n \"\"\"Calculate intermediate rewards based on answer format.\"\"\"\n if not completions or not db_set:\n return [0.0] * len(completions)\n responses = [completion[0]['content'] if isinstance(completion, list) and len(completion) > 0 and isinstance(completion[0], dict) and ('content' in completion[0]) else '' for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n rewards = []\n for r, dt in zip(extracted_responses, db_set):\n if dt == 'gsm8k':\n rewards.append(0.5 if r.isdigit() else 0.0)\n elif dt == 'pubmedqa':\n rewards.append(0.5 if 'yes' in r.lower() or 'no' in r.lower() or 'maybe' in r.lower() else 0.0)\n else:\n rewards.append(0.5 if 'a' in r.lower() or 'b' in r.lower() or 'c' in r.lower() or ('d' in r.lower()) else 0.0)\n return ensure_list_length(rewards, len(completions))",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from list item 3)",
"code": "def correctness_reward_func(prompts, completions, answer, db_set, **kwargs) -> list[float]:\n \"\"\"Calculate correctness rewards for model completions.\"\"\"\n if not completions or not answer or (not db_set):\n return [0.0] * len(completions)\n responses = [completion[0]['content'] if isinstance(completion, list) and len(completion) > 0 and isinstance(completion[0], dict) and ('content' in completion[0]) else '' for completion in completions]\n if prompts and len(prompts) > 0 and (len(prompts[0]) > 0):\n q = prompts[0][-1].get('content', '')\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extract_xml_answer(responses[0])}')\n extracted_responses = [extract_xml_answer(r) for r in responses]\n rewards = []\n for r, a, dt in zip(extracted_responses, answer, db_set):\n if dt == 'gsm8k':\n if a in r:\n rewards.append(1.0)\n elif r == a:\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n elif dt == 'finqa':\n pred_norm = normalize_finqa_answer(r)\n actual_norm = normalize_finqa_answer(a)\n if pred_norm.replace('.', '').isdigit() and actual_norm.replace('.', '').isdigit():\n try:\n pred_num = float(pred_norm)\n actual_num = float(actual_norm)\n if abs(pred_num - actual_num) / max(abs(actual_num), 1e-10) < 0.01:\n rewards.append(2.0)\n continue\n except ValueError:\n pass\n if pred_norm == actual_norm:\n rewards.append(2.0)\n elif actual_norm in pred_norm:\n rewards.append(1.0)\n else:\n rewards.append(0.0)\n else:\n rewards.append(2.0 if r.lower() == a.strip().lower() else 0.0)\n return ensure_list_length(rewards, len(completions))",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Calculate granular rewards based on XML tag counts and formatting.\"\"\"\n if not completions:\n return [0.0]\n contents = [completion[0]['content'] if isinstance(completion, list) and len(completion) > 0 and isinstance(completion[0], dict) and ('content' in completion[0]) else '' for completion in completions]\n rewards = [count_xml(c) for c in contents]\n return ensure_list_length(rewards, len(completions))",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format with exact newlines.\"\"\"\n if not completions:\n return [0.0]\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] if isinstance(completion, list) and len(completion) > 0 and isinstance(completion[0], dict) and ('content' in completion[0]) else '' for completion in completions]\n matches = [bool(re.match(pattern, r, re.DOTALL)) for r in responses]\n return ensure_list_length([0.5 if match else 0.0 for match in matches], len(completions))",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, db_set, **kwargs) -> list[float]:\n \"\"\"Calculate intermediate rewards based on answer format.\"\"\"\n if not completions or not db_set:\n return [0.0] * len(completions)\n responses = [completion[0]['content'] if isinstance(completion, list) and len(completion) > 0 and isinstance(completion[0], dict) and ('content' in completion[0]) else '' for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n rewards = []\n for r, dt in zip(extracted_responses, db_set):\n if dt == 'gsm8k':\n rewards.append(0.5 if r.isdigit() else 0.0)\n elif dt == 'pubmedqa':\n rewards.append(0.5 if 'yes' in r.lower() or 'no' in r.lower() or 'maybe' in r.lower() else 0.0)\n else:\n rewards.append(0.5 if 'a' in r.lower() or 'b' in r.lower() or 'c' in r.lower() or ('d' in r.lower()) else 0.0)\n return ensure_list_length(rewards, len(completions))",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, db_set, **kwargs) -> list[float]:\n \"\"\"Calculate correctness rewards for model completions.\"\"\"\n if not completions or not answer or (not db_set):\n return [0.0] * len(completions)\n responses = [completion[0]['content'] if isinstance(completion, list) and len(completion) > 0 and isinstance(completion[0], dict) and ('content' in completion[0]) else '' for completion in completions]\n if prompts and len(prompts) > 0 and (len(prompts[0]) > 0):\n q = prompts[0][-1].get('content', '')\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extract_xml_answer(responses[0])}')\n extracted_responses = [extract_xml_answer(r) for r in responses]\n rewards = []\n for r, a, dt in zip(extracted_responses, answer, db_set):\n if dt == 'gsm8k':\n if a in r:\n rewards.append(1.0)\n elif r == a:\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n elif dt == 'finqa':\n pred_norm = normalize_finqa_answer(r)\n actual_norm = normalize_finqa_answer(a)\n if pred_norm.replace('.', '').isdigit() and actual_norm.replace('.', '').isdigit():\n try:\n pred_num = float(pred_norm)\n actual_num = float(actual_norm)\n if abs(pred_num - actual_num) / max(abs(actual_num), 1e-10) < 0.01:\n rewards.append(2.0)\n continue\n except ValueError:\n pass\n if pred_norm == actual_norm:\n rewards.append(2.0)\n elif actual_norm in pred_norm:\n rewards.append(1.0)\n else:\n rewards.append(0.0)\n else:\n rewards.append(2.0 if r.lower() == a.strip().lower() else 0.0)\n return ensure_list_length(rewards, len(completions))",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
uukuguy/Replicate-R1
|
https://github.com/uukuguy/Replicate-R1
|
MIT License
|
tasks/unsloth_grpo/unsloth_grpo.py
|
https://github.com/uukuguy/Replicate-R1/blob/e050c71aebcdffc75b2ec634bb82e4897510606a/tasks/unsloth_grpo/unsloth_grpo.py
|
2025-03-24T10:22:23.074378
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n logger.debug('-' * 20 + f'\\nQuestion:\\n{q}' + f'\\nAnswer:\\n{answer[0]}' + f'\\nResponse:\\n{responses[0]}' + f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"DEBUGGING\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n logger.debug('-' * 20 + f'\\nQuestion:\\n{q}' + f'\\nAnswer:\\n{answer[0]}' + f'\\nResponse:\\n{responses[0]}' + f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"DEBUGGING\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
rueckstiess/qurious
|
https://github.com/rueckstiess/qurious
|
Unknown
|
qurious/llms/grpo_grid.py
|
https://github.com/rueckstiess/qurious/blob/572c59c808f2ab606483eec88f4305030f59ce01/qurious/llms/grpo_grid.py
|
2025-03-24T10:22:27.572923
|
[
{
"name": "reward_goal_reached (from list item 0)",
"code": "def reward_goal_reached(completions, **kwargs):\n rewards = []\n for i, completion in enumerate(completions):\n reward = 0.0\n _, numeric_actions = extract_actions_from_responses(completion)\n example = {k: v[i] for k, v in kwargs.items()}\n solved, distance = run_actions_in_env(example, numeric_actions)\n if solved:\n reward += 1\n reward -= distance / 10.0\n rewards.append(reward)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "reward_illegal_actions (from list item 1)",
"code": "def reward_illegal_actions(completions, **kwargs):\n rewards = []\n for i, completion in enumerate(completions):\n actions = [c.strip() for c in completion.split(',')]\n illegal_actions = [1 for a in actions if a not in ['up', 'down', 'left', 'right']]\n rewards.append(-len(illegal_actions) / len(actions))\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "reward_goal_reached (from [reward_goal_reached, reward_illegal_actions])",
"code": "def reward_goal_reached(completions, **kwargs):\n rewards = []\n for i, completion in enumerate(completions):\n reward = 0.0\n _, numeric_actions = extract_actions_from_responses(completion)\n example = {k: v[i] for k, v in kwargs.items()}\n solved, distance = run_actions_in_env(example, numeric_actions)\n if solved:\n reward += 1\n reward -= distance / 10.0\n rewards.append(reward)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "reward_illegal_actions (from [reward_goal_reached, reward_illegal_actions])",
"code": "def reward_illegal_actions(completions, **kwargs):\n rewards = []\n for i, completion in enumerate(completions):\n actions = [c.strip() for c in completion.split(',')]\n illegal_actions = [1 for a in actions if a not in ['up', 'down', 'left', 'right']]\n rewards.append(-len(illegal_actions) / len(actions))\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[reward_goal_reached, reward_illegal_actions]",
"args": "training_args",
"train_dataset": "prompt_dataset['train']",
"eval_dataset": "prompt_dataset['eval']",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": "[custom_callback]",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
zhuopanyang/algorithm_learning
|
https://github.com/zhuopanyang/algorithm_learning
|
Unknown
|
model/deepseek_sft.py
|
https://github.com/zhuopanyang/algorithm_learning/blob/1d124a74926e8159b696b5fff18fb7f4b1d9bb80/model/deepseek_sft.py
|
2025-03-24T10:22:29.809102
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "thought_len_reward_func (from list item 2)",
"code": "def thought_len_reward_func(completions, **kwargs):\n \"\"\"\n 思考长度奖励函数,检查 <think> 标签的长度是否大于 1000\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n match = re.search('<think>(.*?)</think>', completion)\n if match:\n thought_process = match.group(1).strip()\n thought_length = len(thought_process)\n if thought_length > 1000:\n rewards.append(1.0)\n else:\n rewards.append(0.0)\n else:\n rewards.append(0.0)\n continue\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func, thought_len_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func, thought_len_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "thought_len_reward_func (from [format_reward_func, equation_reward_func, thought_len_reward_func])",
"code": "def thought_len_reward_func(completions, **kwargs):\n \"\"\"\n 思考长度奖励函数,检查 <think> 标签的长度是否大于 1000\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n match = re.search('<think>(.*?)</think>', completion)\n if match:\n thought_process = match.group(1).strip()\n thought_length = len(thought_process)\n if thought_length > 1000:\n rewards.append(1.0)\n else:\n rewards.append(0.0)\n else:\n rewards.append(0.0)\n continue\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func, thought_len_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
syafiq/reasoning
|
https://github.com/syafiq/reasoning
|
Unknown
|
src/grpo_phi.py
|
https://github.com/syafiq/reasoning/blob/6130b0d2b0dc71a446de9d5b5d48678c101baf7f/src/grpo_phi.py
|
2025-03-24T10:22:34.311286
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the expected XML format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.search(pattern, r, re.DOTALL)) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "vulnerability_identification_func (from list item 1)",
"code": "def vulnerability_identification_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the model identifies vulnerability status clearly.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n contains_vulnerable = ['vulnerable' in r.lower() for r in extracted_responses]\n contains_cwe = [bool(re.search('cwe-\\\\d+|common weakness enumeration', r.lower())) for r in extracted_responses]\n rewards = []\n for vuln, cwe in zip(contains_vulnerable, contains_cwe):\n if vuln and cwe:\n rewards.append(0.5)\n elif vuln:\n rewards.append(0.2)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "correctness_reward_func (from list item 2)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nExpected:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n rewards = []\n for r, a in zip(extracted_responses, answer):\n r_lower = r.lower()\n a_lower = a.lower()\n if 'vulnerable' in a_lower and 'vulnerable' in r_lower and ('not vulnerable' not in a_lower):\n if ':' in a:\n try:\n cwe_types = a.split('Vulnerable: ')[1].split(',')\n cwe_correct = any((cwe_id.lower() in r_lower for cwe_id in cwe_types))\n rewards.append(2.0 if cwe_correct else 1.0)\n except IndexError:\n rewards.append(1.0)\n else:\n rewards.append(1.5)\n elif 'not vulnerable' in a_lower and 'not vulnerable' in r_lower:\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward_func (from [format_reward_func, vulnerability_identification_func, correctness_reward_func])",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the expected XML format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.search(pattern, r, re.DOTALL)) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "vulnerability_identification_func (from [format_reward_func, vulnerability_identification_func, correctness_reward_func])",
"code": "def vulnerability_identification_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the model identifies vulnerability status clearly.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n contains_vulnerable = ['vulnerable' in r.lower() for r in extracted_responses]\n contains_cwe = [bool(re.search('cwe-\\\\d+|common weakness enumeration', r.lower())) for r in extracted_responses]\n rewards = []\n for vuln, cwe in zip(contains_vulnerable, contains_cwe):\n if vuln and cwe:\n rewards.append(0.5)\n elif vuln:\n rewards.append(0.2)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "correctness_reward_func (from [format_reward_func, vulnerability_identification_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nExpected:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n rewards = []\n for r, a in zip(extracted_responses, answer):\n r_lower = r.lower()\n a_lower = a.lower()\n if 'vulnerable' in a_lower and 'vulnerable' in r_lower and ('not vulnerable' not in a_lower):\n if ':' in a:\n try:\n cwe_types = a.split('Vulnerable: ')[1].split(',')\n cwe_correct = any((cwe_id.lower() in r_lower for cwe_id in cwe_types))\n rewards.append(2.0 if cwe_correct else 1.0)\n except IndexError:\n rewards.append(1.0)\n else:\n rewards.append(1.5)\n elif 'not vulnerable' in a_lower and 'not vulnerable' in r_lower:\n rewards.append(2.0)\n else:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward_func, vulnerability_identification_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "filtered_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
ShaohonChen/ascend_r1_turtorial
|
https://github.com/ShaohonChen/ascend_r1_turtorial
|
Unknown
|
train_r1_grpo.py
|
https://github.com/ShaohonChen/ascend_r1_turtorial/blob/370f7a816b0156beb19043262d24bdb03c6cdef5/train_r1_grpo.py
|
2025-03-24T10:22:38.851223
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Karthik-Dulam/nano-zero
|
https://github.com/Karthik-Dulam/nano-zero
|
Unknown
|
grpo_unsloth.py
|
https://github.com/Karthik-Dulam/nano-zero/blob/36e795be9ef70202d7daadb2c2ef754ef63144c8/grpo_unsloth.py
|
2025-03-24T10:22:43.381652
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, prompts=None, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n rewards = [count_xml(c) for c in contents]\n log_response(prompts, completions, 'xml_count', rewards)\n return rewards",
"label": "{\"label\": \"DEBUGGING\"}"
},
{
"name": "int_reward_func (from list item 1)",
"code": "def int_reward_func(completions, prompts=None, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n rewards = [10 * sum((char[-1].isdigit() for char in r.split(' ') if char)) / len(r) if len(r) > 0 else 0 for r in extracted_responses]\n log_response(prompts, completions, 'int_reward', rewards)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 2)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n rewards = [20 * sum((i == j for i, j in zip(r, a))) / len(a) for r, a in zip(extracted_responses, answer)]\n log_response(prompts, completions, 'correctness', rewards, answer=answer)\n print('-' * 20, f'Question:\\n{q}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}', f'\\nAnswer:\\n{answer[0]}')\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, prompts=None, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n rewards = [count_xml(c) for c in contents]\n log_response(prompts, completions, 'xml_count', rewards)\n return rewards",
"label": "{\"label\": \"DEBUGGING\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, prompts=None, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n rewards = [10 * sum((char[-1].isdigit() for char in r.split(' ') if char)) / len(r) if len(r) > 0 else 0 for r in extracted_responses]\n log_response(prompts, completions, 'int_reward', rewards)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n rewards = [20 * sum((i == j for i, j in zip(r, a))) / len(a) for r, a in zip(extracted_responses, answer)]\n log_response(prompts, completions, 'correctness', rewards, answer=answer)\n print('-' * 20, f'Question:\\n{q}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}', f'\\nAnswer:\\n{answer[0]}')\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
benedikt-schesch/LLMerge
|
https://github.com/benedikt-schesch/LLMerge
|
MIT License
|
train.py
|
https://github.com/benedikt-schesch/LLMerge/blob/7c02aa9804f76d70f990576febd5eefb3641508d/train.py
|
2025-03-24T10:22:45.642712
|
[
{
"name": "format_reward (from list item 0)",
"code": "def format_reward(completions: List[List[Dict[str, str]]], log_wandb: bool=True, **kwargs) -> List[float]:\n \"\"\"\n Reward = 0.5 if the completion matches the 'thinking' pattern.\n Otherwise 0.0.\n \"\"\"\n rewards = [0.5 if THINKING_RE.match(c[0]['content']) else 0.0 for c in completions]\n if log_wandb:\n wandb.log({'format_reward': rewards})\n print('Format Reward:', rewards)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "merged_conflict_reward (from list item 1)",
"code": "def merged_conflict_reward(prompts: List[List[Dict[str, str]]], completions: List[List[Dict[str, str]]], answer: List[str], log_wandb: bool=True, **kwargs) -> List[float]:\n \"\"\"\n Merged reward function with the following logic:\n - 1.0 if the completion's code block exactly matches the correct resolution\n - 0.5 if it's only semantically the same (ignoring comments/whitespace)\n - 0.1 if it matches the prompt's code block (i.e. raises a conflict)\n - 0.0 otherwise\n \"\"\"\n goal_code_block = extract_code_block(prompts[0][-1]['content'])\n rewards = [0.0 if (cb := extract_code_block(extract_answer(c[0]['content']))) is None else 1.0 if cb == answer[idx].strip() else 0.5 if normalize_java_code(cb) == normalize_java_code(answer[idx].strip()) else 0.1 if cb == goal_code_block else 0.0 for idx, c in enumerate(completions)]\n if log_wandb:\n wandb.log({'merged_conflict_reward': rewards})\n print('Merged Conflict Reward:', rewards)\n print('Output lengths:', [len(c[0]['content']) for c in completions])\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward (from [format_reward, merged_conflict_reward])",
"code": "def format_reward(completions: List[List[Dict[str, str]]], log_wandb: bool=True, **kwargs) -> List[float]:\n \"\"\"\n Reward = 0.5 if the completion matches the 'thinking' pattern.\n Otherwise 0.0.\n \"\"\"\n rewards = [0.5 if THINKING_RE.match(c[0]['content']) else 0.0 for c in completions]\n if log_wandb:\n wandb.log({'format_reward': rewards})\n print('Format Reward:', rewards)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "merged_conflict_reward (from [format_reward, merged_conflict_reward])",
"code": "def merged_conflict_reward(prompts: List[List[Dict[str, str]]], completions: List[List[Dict[str, str]]], answer: List[str], log_wandb: bool=True, **kwargs) -> List[float]:\n \"\"\"\n Merged reward function with the following logic:\n - 1.0 if the completion's code block exactly matches the correct resolution\n - 0.5 if it's only semantically the same (ignoring comments/whitespace)\n - 0.1 if it matches the prompt's code block (i.e. raises a conflict)\n - 0.0 otherwise\n \"\"\"\n goal_code_block = extract_code_block(prompts[0][-1]['content'])\n rewards = [0.0 if (cb := extract_code_block(extract_answer(c[0]['content']))) is None else 1.0 if cb == answer[idx].strip() else 0.5 if normalize_java_code(cb) == normalize_java_code(answer[idx].strip()) else 0.1 if cb == goal_code_block else 0.0 for idx, c in enumerate(completions)]\n if log_wandb:\n wandb.log({'merged_conflict_reward': rewards})\n print('Merged Conflict Reward:', rewards)\n print('Output lengths:', [len(c[0]['content']) for c in completions])\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward, merged_conflict_reward]",
"args": "training_args",
"train_dataset": "dataset['train']",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
shreyshahi/r1-zero-test
|
https://github.com/shreyshahi/r1-zero-test
|
MIT License
|
train.py
|
https://github.com/shreyshahi/r1-zero-test/blob/1f6bf399346f263a6f0f7ac0e3645cfc6c448c99/train.py
|
2025-03-24T10:23:10.654699
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<think>\\\\n[\\\\s\\\\S]*?</think>\\\\n<answer>\\\\n[\\\\s\\\\S]*?</answer>'\n responses = [completion[0]['content'].strip() for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.1 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from list item 1)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [1.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward_func (from [format_reward_func, correctness_reward_func])",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<think>\\\\n[\\\\s\\\\S]*?</think>\\\\n<answer>\\\\n[\\\\s\\\\S]*?</answer>'\n responses = [completion[0]['content'].strip() for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.1 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from [format_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [1.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
matthewlee626/concise-cognition-submission-final
|
https://github.com/matthewlee626/concise-cognition-submission-final
|
Unknown
|
concision/train/train.py
|
https://github.com/matthewlee626/concise-cognition-submission-final/blob/243fccc3d7738af248b7fb642f4ac355eb8dca7d/concision/train/train.py
|
2025-03-24T10:23:19.642883
|
[
{
"name": "Potential lambda reward: lambda_0",
"code": "lambda: [format_reward, accuracy_reward, tag_count_reward, expression_based_accuracy_reward, soft_format_reward]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "reward_funcs",
"args": "training_args",
"train_dataset": "dataset['train']",
"eval_dataset": null,
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
cttmayi/AIDemo
|
https://github.com/cttmayi/AIDemo
|
Unknown
|
fine-tune/deepseek_r1/v1.py
|
https://github.com/cttmayi/AIDemo/blob/6d98e58035e5478966a1a76241c680210c6f942c/fine-tune/deepseek_r1/v1.py
|
2025-03-24T10:23:26.413631
|
[
{
"name": "reward_len (from list item 0)",
"code": "def reward_len(completions, **kwargs):\n return [abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "reward_len (from [reward_len])",
"code": "def reward_len(completions, **kwargs):\n return [abs(20 - len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[reward_len]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
guanyilun/scratch
|
https://github.com/guanyilun/scratch
|
Unknown
|
symbolic/attempt5/train_grpo_game24.py
|
https://github.com/guanyilun/scratch/blob/041ffce2012128f4f3eef2c8ff0cebc1be3bc386/symbolic/attempt5/train_grpo_game24.py
|
2025-03-24T10:23:28.762297
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the correct format.\"\"\"\n pattern = '^<reasoning>(?:(?!</reasoning>).)*</reasoning>\\\\n<answer>(?:(?!</answer>).)*</answer>$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.match(pattern, r.strip())) for r in responses]\n return [1.0 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "expression_reward_func (from list item 1)",
"code": "def expression_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the expression is valid.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [1.0 if is_valid_format(r, a) else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from list item 2)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs):\n \"\"\"Combimed reward function\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n valid_rewards = [1.0 if is_valid_format(r, a) else 0.0 for r, a in zip(extracted_responses, answer)]\n values = [evaluate_expression(r) for r in extracted_responses]\n value_rewards = [1.0 if abs(v - 24) < 1e-10 else 0.0 for v in values]\n for i in range(5):\n print(f'Expression: {extracted_responses[i]}, Value: {values[i]}')\n rewards = [v * c for v, c in zip(valid_rewards, value_rewards)]\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, expression_reward_func, correctness_reward_func])",
"code": "def format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has the correct format.\"\"\"\n pattern = '^<reasoning>(?:(?!</reasoning>).)*</reasoning>\\\\n<answer>(?:(?!</answer>).)*</answer>$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [bool(re.match(pattern, r.strip())) for r in responses]\n return [1.0 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "expression_reward_func (from [format_reward_func, expression_reward_func, correctness_reward_func])",
"code": "def expression_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the expression is valid.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [1.0 if is_valid_format(r, a) else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from [format_reward_func, expression_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs):\n \"\"\"Combimed reward function\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n valid_rewards = [1.0 if is_valid_format(r, a) else 0.0 for r, a in zip(extracted_responses, answer)]\n values = [evaluate_expression(r) for r in extracted_responses]\n value_rewards = [1.0 if abs(v - 24) < 1e-10 else 0.0 for v in values]\n for i in range(5):\n print(f'Expression: {extracted_responses[i]}, Value: {values[i]}')\n rewards = [v * c for v, c in zip(valid_rewards, value_rewards)]\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[format_reward_func, expression_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Legionof7/GRPOdx
|
https://github.com/Legionof7/GRPOdx
|
Unknown
|
medical_grpo.py
|
https://github.com/Legionof7/GRPOdx/blob/b039810b169606493a1e3202dbf1b4d9cec02942/medical_grpo.py
|
2025-03-24T10:23:35.514456
|
[
{
"name": "doctor_game_reward (from list item 0)",
"code": "def doctor_game_reward(prompts, completions, **kwargs) -> list[float]:\n \"\"\"Stub that always returns 0, the real reward is from multi_turn_generation.\"\"\"\n return [0.0] * len(prompts)",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "doctor_game_reward (from [doctor_game_reward])",
"code": "def doctor_game_reward(prompts, completions, **kwargs) -> list[float]:\n \"\"\"Stub that always returns 0, the real reward is from multi_turn_generation.\"\"\"\n return [0.0] * len(prompts)",
"label": "{\"label\": \"DEBUGGING\"}"
}
] |
[
{
"trainer_type": "DoctorGRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[doctor_game_reward]",
"args": "config",
"train_dataset": "train_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": "lambda: DoctorGame(openai_api_key=config.openai_api_key)",
"use_wandb": "use_wandb",
"tools": null,
"reward_weights": null
}
}
] |
minwukim/VRL
|
https://github.com/minwukim/VRL
|
Unknown
|
train_verification_demo.py
|
https://github.com/minwukim/VRL/blob/e6aa1718019db1acce0b2c49994827bb88be7e4d/train_verification_demo.py
|
2025-03-24T10:23:44.547449
|
[
{
"name": "reward_correct (from list item 0)",
"code": "def reward_correct(completions, answer, **kwargs):\n correct = [1.0 if verify(parse(c), parse(gt)) else 0.0 for c, gt in zip(completions, answer)]\n return correct",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "reward_correct_and_format (from list item 1)",
"code": "def reward_correct_and_format(completions, answer, **kwargs):\n matches = [re.search('</think>\\\\n?<answer>([\\\\s\\\\S]*)</answer>', completion) for completion in completions]\n completions = [match.group(1) if match else '' for match in matches]\n matches = [re.search('\\\\\\\\boxed\\\\{(.*?)\\\\}', completion) for completion in completions]\n contents = [match.group(1) if match else '' for match in matches]\n correct_with_format = [1.0 if verify(parse(c), parse(gt)) else 0.0 for c, gt in zip(contents, answer)]\n return correct_with_format",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "reward_correct (from [reward_correct, reward_correct_and_format])",
"code": "def reward_correct(completions, answer, **kwargs):\n correct = [1.0 if verify(parse(c), parse(gt)) else 0.0 for c, gt in zip(completions, answer)]\n return correct",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "reward_correct_and_format (from [reward_correct, reward_correct_and_format])",
"code": "def reward_correct_and_format(completions, answer, **kwargs):\n matches = [re.search('</think>\\\\n?<answer>([\\\\s\\\\S]*)</answer>', completion) for completion in completions]\n completions = [match.group(1) if match else '' for match in matches]\n matches = [re.search('\\\\\\\\boxed\\\\{(.*?)\\\\}', completion) for completion in completions]\n contents = [match.group(1) if match else '' for match in matches]\n correct_with_format = [1.0 if verify(parse(c), parse(gt)) else 0.0 for c, gt in zip(contents, answer)]\n return correct_with_format",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "VerificationGRPOTrainer",
"args": [],
"kwargs": {
"model": "model_name",
"reward_funcs": "[reward_correct, reward_correct_and_format]",
"args": "training_args",
"train_dataset": "train",
"eval_dataset": "test",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
debayan/grpo-experiments
|
https://github.com/debayan/grpo-experiments
|
Unknown
|
train_sparql_grpo.py
|
https://github.com/debayan/grpo-experiments/blob/55535125ed3521e557b00ede2d087b0686d114b3/train_sparql_grpo.py
|
2025-03-24T10:23:46.803114
|
[
{
"name": "reward_func",
"code": "def reward_func(completions, ground_truth, **kwargs):\n rewards = []\n for c, g in zip(completions, ground_truth):\n extracted_c = c.replace(' ', '').lower()\n g = g.replace(' ', '').lower()\n similarity_reward = SequenceMatcher(None, extracted_c, g).ratio()\n length_reward = -abs(float(len(c) - len(g)) / len(g))\n rewards.append(similarity_reward + length_reward)\n print('rewards:', rewards)\n for c, g in zip(completions[:1], ground_truth[:1]):\n print('Printing 1 samples')\n print('completion:', c)\n print('ground_truth:', g)\n print('===========================')\n return rewards",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'./Qwen2-1.5B-GRPO/checkpoint-5250/'",
"reward_funcs": "reward_func",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
aphil311/talos
|
https://github.com/aphil311/talos
|
MIT License
|
rl-cai/train_grpo.py
|
https://github.com/aphil311/talos/blob/1f93b7e6e0ad7895c079be9ae44267363ac7357c/rl-cai/train_grpo.py
|
2025-03-24T10:24:02.574152
|
[
{
"name": "reward_len",
"code": "def reward_len(completions: list[str], **kwargs) -> list[float]:\n \"\"\"\n Reward function that rewards completions that align closest to the constitution.\n\n Args:\n completions (list[str]): The completions to reward\n\n Returns:\n list[float]: The rewards for each completion\n \"\"\"\n pass",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "args.model",
"reward_funcs": "reward_len",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
joykirat18/thinkingModelProbing
|
https://github.com/joykirat18/thinkingModelProbing
|
Unknown
|
grpo.py
|
https://github.com/joykirat18/thinkingModelProbing/blob/9bbb93ee9533770b68cabc38c5f4912e9dd6dde3/grpo.py
|
2025-03-24T10:24:07.061347
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
The-Last-Byte-Bar/SharkNet
|
https://github.com/The-Last-Byte-Bar/SharkNet
|
MIT License
|
pipeline/grpo_trainer.py
|
https://github.com/The-Last-Byte-Bar/SharkNet/blob/412b86899088b9ff5d5c47db45ce283779c86021/pipeline/grpo_trainer.py
|
2025-03-24T10:24:20.620154
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function for XML tag formatting.\"\"\"\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Soft reward function for XML format checking.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Strict reward function for XML format checking.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from list item 3)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"Reward function for answer correctness.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function for XML tag formatting.\"\"\"\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Soft reward function for XML format checking.\"\"\"\n pattern = '<reasoning>.*?</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Strict reward function for XML format checking.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n \"\"\"Reward function for answer correctness.\"\"\"\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
htesd/fucking_drug
|
https://github.com/htesd/fucking_drug
|
Apache License 2.0
|
llms/grpo_demo.py
|
https://github.com/htesd/fucking_drug/blob/6924b94bf04c77f632f52d438f1a9a579a4b01e1/llms/grpo_demo.py
|
2025-03-24T10:24:27.339038
|
[
{
"name": "mark_reward (from list item 0)",
"code": "def mark_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n return [mark_num(response) for response in responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward (from list item 1)",
"code": "def soft_format_reward(completions, **kwargs):\n pattern = '<think>.*?</think>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "hard_format_reward (from list item 2)",
"code": "def hard_format_reward(completions, **kwargs):\n pattern = '^<think>\\\\n.*?n</think>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "digit_reward (from list item 3)",
"code": "def digit_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "correctness_reward (from list item 4)",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n print(f'问题:\\n{prompts[0][-1]['content']}', f'\\n答案:\\n{answer[0]}', f'\\n模型输出:\\n{responses[0]}', f'\\n提取后的答案:\\n{extracted_responses[0]}')\n return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "mark_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def mark_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n return [mark_num(response) for response in responses]",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
},
{
"name": "soft_format_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def soft_format_reward(completions, **kwargs):\n pattern = '<think>.*?</think>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "hard_format_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def hard_format_reward(completions, **kwargs):\n pattern = '^<think>\\\\n.*?n</think>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, response) for response in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "digit_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def digit_reward(completions, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward (from [mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward])",
"code": "def correctness_reward(prompts, completions, answer, **kwargs):\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_answer(r) for r in responses]\n print(f'问题:\\n{prompts[0][-1]['content']}', f'\\n答案:\\n{answer[0]}', f'\\n模型输出:\\n{responses[0]}', f'\\n提取后的答案:\\n{extracted_responses[0]}')\n return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[mark_reward, soft_format_reward, hard_format_reward, digit_reward, correctness_reward]",
"args": "training_args",
"train_dataset": "data",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
flashsonic6666/trl
|
https://github.com/flashsonic6666/trl
|
Apache License 2.0
|
tests/test_grpo_trainer.py
|
https://github.com/flashsonic6666/trl/blob/b1c825c7b9971d27f155913eb2dca437993fedd7/tests/test_grpo_trainer.py
|
2025-03-24T10:24:29.610177
|
[
{
"name": "reward_func",
"code": "def reward_func(completions, some_values, **kwargs):\n \"\"\"Reward function that rewards completions with lengths closer to the values in some_values.\"\"\"\n return [float(abs(len(completion) - value)) for completion, value in zip(completions, some_values)]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "reward_func (from list item 0)",
"code": "def reward_func(completions, some_values, **kwargs):\n \"\"\"Reward function that rewards completions with lengths closer to the values in some_values.\"\"\"\n return [float(abs(len(completion) - value)) for completion, value in zip(completions, some_values)]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "reward_func (from [reward_func, 'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5'])",
"code": "def reward_func(completions, some_values, **kwargs):\n \"\"\"Reward function that rewards completions with lengths closer to the values in some_values.\"\"\"\n return [float(abs(len(completion) - value)) for completion, value in zip(completions, some_values)]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "reward_func1 (from list item 0)",
"code": "def reward_func1(completions, **kwargs):\n \"\"\"Reward function that rewards longer completions.\"\"\"\n return [float(len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "reward_func2 (from list item 1)",
"code": "def reward_func2(completions, **kwargs):\n \"\"\"Reward function that rewards completions with more unique letters.\"\"\"\n return [float(len(set(completion))) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "reward_func1 (from [reward_func1, reward_func2])",
"code": "def reward_func1(completions, **kwargs):\n \"\"\"Reward function that rewards longer completions.\"\"\"\n return [float(len(completion)) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "reward_func2 (from [reward_func1, reward_func2])",
"code": "def reward_func2(completions, **kwargs):\n \"\"\"Reward function that rewards completions with more unique letters.\"\"\"\n return [float(len(set(completion))) for completion in completions]",
"label": "{\"label\": \"LENGTH_BASED\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5'",
"args": null,
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5'",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5'",
"args": "training_args",
"train_dataset": "dataset['train']",
"eval_dataset": "dataset['test']",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5'",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": "LoraConfig()",
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "reward_model",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": "reward_tokenizer",
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "reward_func",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "reward_func",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "[reward_func1, reward_func2]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "[reward_func, 'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5']",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "reward_func",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/small-Qwen2ForCausalLM-2.5'",
"reward_funcs": "'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5'",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5'",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
},
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'trl-internal-testing/tiny-Qwen2ForCausalLM-2.5'",
"reward_funcs": "'trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5'",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
zhuopanyang/algorithm_learning
|
https://github.com/zhuopanyang/algorithm_learning
|
Unknown
|
github_model_learning/unlock-deepseek-main/Datawhale-R1/train_Datawhale-R1.py
|
https://github.com/zhuopanyang/algorithm_learning/blob/1d124a74926e8159b696b5fff18fb7f4b1d9bb80/github_model_learning/unlock-deepseek-main/Datawhale-R1/train_Datawhale-R1.py
|
2025-03-24T10:24:43.067362
|
[
{
"name": "format_reward_func (from list item 0)",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from list item 1)",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "format_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n \"\"\"\n 格式奖励函数,检查模型输出格式是否匹配: <think>...</think><answer>...</answer>\n\n 参数:\n completions (list[str]): 生成的输出\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion in completions:\n try:\n completion = '<think>' + completion\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n regex = '^<think>([^<]*(?:<(?!/?think>)[^<]*)*)<\\\\/think>\\\\n<answer>([\\\\s\\\\S]*?)<\\\\/answer>$'\n match = re.search(regex, completion, re.DOTALL)\n if match is None or len(match.groups()) != 2:\n rewards.append(0.0)\n else:\n rewards.append(1.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "equation_reward_func (from [format_reward_func, equation_reward_func])",
"code": "def equation_reward_func(completions, target, nums, **kwargs):\n \"\"\"\n 方程奖励函数,检查计算结果是否正确,数字是否符合使用要求(每个数字只用一次,只使用所提供的数字)\n\n 参数:\n completions (list[str]): 生成的输出\n target (list[str]): 预期的答案\n nums (list[str]): 可用的数字\n\n 返回:\n list[float]: 奖励分数\n \"\"\"\n rewards = []\n for completion, gt, numbers in zip(completions, target, nums):\n try:\n completion = '<think>' + completion\n match = re.search('<answer>(.*?)<\\\\/answer>', completion)\n if match is None:\n rewards.append(0.0)\n continue\n equation = match.group(1).strip()\n used_numbers = [int(n) for n in re.findall('\\\\d+', equation)]\n if sorted(used_numbers) != sorted(numbers):\n rewards.append(0.0)\n continue\n allowed_pattern = '^[\\\\d+\\\\-*/().\\\\s]+$'\n if not re.match(allowed_pattern, equation):\n rewards.append(0.0)\n continue\n result = eval(equation, {'__builtins__': None}, {})\n if abs(float(result) - float(gt)) < 1e-05:\n rewards.append(1.0)\n if random.random() < 0.1:\n os.makedirs('completion_samples', exist_ok=True)\n log_file = os.path.join('completion_samples', 'success_completion_samples.txt')\n with open(log_file, 'a') as f:\n f.write(f'\\n\\n==============\\n')\n f.write(completion)\n else:\n rewards.append(0.0)\n except Exception:\n rewards.append(0.0)\n return rewards",
"label": "{\"label\": \"COMPUTATIONAL\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[format_reward_func, equation_reward_func]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset",
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": "callbacks",
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
shibing624/MedicalGPT
|
https://github.com/shibing624/MedicalGPT
|
Apache License 2.0
|
grpo_training.py
|
https://github.com/shibing624/MedicalGPT/blob/a3e0d34f491b430dece391b8f22ba06755b55a8b/grpo_training.py
|
2025-03-24T10:25:05.968107
|
[
{
"name": "accuracy_reward (from list item 0)",
"code": "def accuracy_reward(completions, solution, **kwargs):\n \"\"\"Reward function that checks if the completion is the same as the ground truth.\"\"\"\n contents = [completion[0]['content'] for completion in completions]\n rewards = []\n for content, sol in zip(contents, solution):\n gold_parsed = parse(sol, extraction_mode='first_match', extraction_config=[LatexExtractionConfig()])\n if len(gold_parsed) != 0:\n answer_parsed = parse(content, extraction_config=[LatexExtractionConfig(normalization_config=NormalizationConfig(nits=False, malformed_operators=False, basic_latex=True, equations=True, boxed='all', units=True), boxed_match_priority=0, try_extract_without_anchor=False)], extraction_mode='first_match')\n reward = float(verify(answer_parsed, gold_parsed))\n logger.debug(f'predict_answer: {content}, \\nground_truth: {sol}, \\nanswer_parsed: {answer_parsed}, gold_parsed: {gold_parsed}, reward: {reward}\\n\\n')\n else:\n reward = 1.0\n logger.debug(f'Failed to parse ground_truth: {sol}')\n rewards.append(reward)\n logger.debug(f'accuracy rewards: {rewards}')\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward (from list item 1)",
"code": "def format_reward(completions, **kwargs):\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<think>.*?</think><answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content) for content in completion_contents]\n rewards = [1.0 if match else 0.0 for match in matches]\n logger.debug(f'format rewards: {rewards}')\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "accuracy_reward (from [accuracy_reward, format_reward])",
"code": "def accuracy_reward(completions, solution, **kwargs):\n \"\"\"Reward function that checks if the completion is the same as the ground truth.\"\"\"\n contents = [completion[0]['content'] for completion in completions]\n rewards = []\n for content, sol in zip(contents, solution):\n gold_parsed = parse(sol, extraction_mode='first_match', extraction_config=[LatexExtractionConfig()])\n if len(gold_parsed) != 0:\n answer_parsed = parse(content, extraction_config=[LatexExtractionConfig(normalization_config=NormalizationConfig(nits=False, malformed_operators=False, basic_latex=True, equations=True, boxed='all', units=True), boxed_match_priority=0, try_extract_without_anchor=False)], extraction_mode='first_match')\n reward = float(verify(answer_parsed, gold_parsed))\n logger.debug(f'predict_answer: {content}, \\nground_truth: {sol}, \\nanswer_parsed: {answer_parsed}, gold_parsed: {gold_parsed}, reward: {reward}\\n\\n')\n else:\n reward = 1.0\n logger.debug(f'Failed to parse ground_truth: {sol}')\n rewards.append(reward)\n logger.debug(f'accuracy rewards: {rewards}')\n return rewards",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "format_reward (from [accuracy_reward, format_reward])",
"code": "def format_reward(completions, **kwargs):\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<think>.*?</think><answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content) for content in completion_contents]\n rewards = [1.0 if match else 0.0 for match in matches]\n logger.debug(f'format rewards: {rewards}')\n return rewards",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model_args.model_name_or_path",
"reward_funcs": "[accuracy_reward, format_reward]",
"args": "training_args",
"train_dataset": "train_dataset",
"eval_dataset": "test_dataset if training_args.eval_strategy != 'no' else None",
"peft_config": "peft_config",
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
chunhuizhang/llm_rl
|
https://github.com/chunhuizhang/llm_rl
|
Unknown
|
tutorials/RL4Agents/scripts/tool_grpo.py
|
https://github.com/chunhuizhang/llm_rl/blob/1c2b9baff36b219076b07f5aeeb4f748d7461388/tutorials/RL4Agents/scripts/tool_grpo.py
|
2025-03-24T10:25:12.701632
|
[
{
"name": "agent_reward",
"code": "def agent_reward(completions, **kwargs):\n rewards = []\n for completion in completions:\n content = completion[0]['content']\n match = re.search('<tool_call>\\\\s*(\\\\{.*?\\\\})\\\\s*</tool_call>', content, re.DOTALL)\n if not match:\n rewards.append(-100)\n continue\n try:\n json_data = json.loads(match.group(1))\n except json.JSONDecodeError:\n rewards.append(-80)\n continue\n function_name = json_data.get('name', '')\n if function_name != 'get_value':\n rewards.append(-60)\n continue\n value = json_data.get('arguments', {}).get('x')\n if value is None:\n rewards.append(-40)\n continue\n if not isinstance(value, (int, float)):\n rewards.append(-20)\n continue\n rewards.append(get_value(float(value)))\n return rewards",
"label": "{\"label\": \"ANSWER_TYPE_VALIDATION\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'Qwen/Qwen2.5-0.5B-Instruct'",
"reward_funcs": "agent_reward",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": "[get_value]",
"reward_weights": null
}
}
] |
s-smits/grpo-optuna
|
https://github.com/s-smits/grpo-optuna
|
Unknown
|
main.py
|
https://github.com/s-smits/grpo-optuna/blob/39d5e5009e54c0b896b6ad2fedd3ed81b6342a6c/main.py
|
2025-03-24T10:25:17.269538
|
[
{
"name": "weighted_xmlcount_reward_func (from list item 0)",
"code": "def weighted_xmlcount_reward_func(completions, **kwargs):\n return [x * xmlcount_weight for x in xmlcount_reward_func(completions, xml_count_reward=xml_count_reward, **kwargs)]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "weighted_soft_format_reward_func (from list item 1)",
"code": "def weighted_soft_format_reward_func(completions, **kwargs):\n return [x * soft_format_weight for x in soft_format_reward_func(completions, soft_match_reward=soft_match_reward, soft_no_match_reward=soft_no_match_reward, **kwargs)]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "weighted_strict_format_reward_func (from list item 2)",
"code": "def weighted_strict_format_reward_func(completions, **kwargs):\n return [x * strict_format_weight for x in strict_format_reward_func(completions, strict_match_reward=strict_match_reward, strict_no_match_reward=strict_no_match_reward, **kwargs)]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "weighted_int_reward_func (from list item 3)",
"code": "def weighted_int_reward_func(completions, **kwargs):\n return [x * int_weight for x in int_reward_func(completions, int_reward=int_reward, non_int_reward=non_int_reward, **kwargs)]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "weighted_correctness_reward_func (from list item 4)",
"code": "def weighted_correctness_reward_func(prompts, completions, answer, **kwargs):\n return [x * correctness_weight for x in correctness_reward_func(prompts, completions, answer, correct_reward=correct_reward, incorrect_reward=incorrect_reward, **kwargs)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "weighted_xmlcount_reward_func (from [weighted_xmlcount_reward_func, weighted_soft_format_reward_func, weighted_strict_format_reward_func, weighted_int_reward_func, weighted_correctness_reward_func])",
"code": "def weighted_xmlcount_reward_func(completions, **kwargs):\n return [x * xmlcount_weight for x in xmlcount_reward_func(completions, xml_count_reward=xml_count_reward, **kwargs)]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "weighted_soft_format_reward_func (from [weighted_xmlcount_reward_func, weighted_soft_format_reward_func, weighted_strict_format_reward_func, weighted_int_reward_func, weighted_correctness_reward_func])",
"code": "def weighted_soft_format_reward_func(completions, **kwargs):\n return [x * soft_format_weight for x in soft_format_reward_func(completions, soft_match_reward=soft_match_reward, soft_no_match_reward=soft_no_match_reward, **kwargs)]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "weighted_strict_format_reward_func (from [weighted_xmlcount_reward_func, weighted_soft_format_reward_func, weighted_strict_format_reward_func, weighted_int_reward_func, weighted_correctness_reward_func])",
"code": "def weighted_strict_format_reward_func(completions, **kwargs):\n return [x * strict_format_weight for x in strict_format_reward_func(completions, strict_match_reward=strict_match_reward, strict_no_match_reward=strict_no_match_reward, **kwargs)]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "weighted_int_reward_func (from [weighted_xmlcount_reward_func, weighted_soft_format_reward_func, weighted_strict_format_reward_func, weighted_int_reward_func, weighted_correctness_reward_func])",
"code": "def weighted_int_reward_func(completions, **kwargs):\n return [x * int_weight for x in int_reward_func(completions, int_reward=int_reward, non_int_reward=non_int_reward, **kwargs)]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "weighted_correctness_reward_func (from [weighted_xmlcount_reward_func, weighted_soft_format_reward_func, weighted_strict_format_reward_func, weighted_int_reward_func, weighted_correctness_reward_func])",
"code": "def weighted_correctness_reward_func(prompts, completions, answer, **kwargs):\n return [x * correctness_weight for x in correctness_reward_func(prompts, completions, answer, correct_reward=correct_reward, incorrect_reward=incorrect_reward, **kwargs)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[weighted_xmlcount_reward_func, weighted_soft_format_reward_func, weighted_strict_format_reward_func, weighted_int_reward_func, weighted_correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
YeonwooSung/ai_book
|
https://github.com/YeonwooSung/ai_book
|
Unknown
|
LLMs/training/train_grpo.py
|
https://github.com/YeonwooSung/ai_book/blob/9e8bce3b74cd5f329aff01bc8f95ae2fae983085/LLMs/training/train_grpo.py
|
2025-03-24T10:25:21.808376
|
[
{
"name": "xmlcount_reward_func (from list item 0)",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from list item 1)",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>[\\\\s\\\\S]*</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from list item 2)",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from list item 3)",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from list item 4)",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "xmlcount_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def xmlcount_reward_func(completions, **kwargs) -> list[float]:\n contents = [completion[0]['content'] for completion in completions]\n return [count_xml(c) for c in contents]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "soft_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def soft_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '<reasoning>[\\\\s\\\\S]*</reasoning>\\\\s*<answer>.*?</answer>'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "strict_format_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def strict_format_reward_func(completions, **kwargs) -> list[float]:\n \"\"\"Reward function that checks if the completion has a specific format.\"\"\"\n pattern = '^<reasoning>\\\\n.*?\\\\n</reasoning>\\\\n<answer>\\\\n.*?\\\\n</answer>\\\\n$'\n responses = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, r, flags=re.DOTALL) for r in responses]\n return [0.5 if match else 0.0 for match in matches]",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "int_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def int_reward_func(completions, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n extracted_responses = [extract_xml_answer(r) for r in responses]\n return [0.5 if r.isdigit() else 0.0 for r in extracted_responses]",
"label": "{\"label\": \"COMPUTATIONAL\"}"
},
{
"name": "correctness_reward_func (from [xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func])",
"code": "def correctness_reward_func(prompts, completions, answer, **kwargs) -> list[float]:\n responses = [completion[0]['content'] for completion in completions]\n q = prompts[0][-1]['content']\n extracted_responses = [extract_xml_answer(r) for r in responses]\n print('-' * 20, f'Question:\\n{q}', f'\\nAnswer:\\n{answer[0]}', f'\\nResponse:\\n{responses[0]}', f'\\nExtracted:\\n{extracted_responses[0]}')\n return [2.0 if r == a else 0.0 for r, a in zip(extracted_responses, answer)]",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "model",
"reward_funcs": "[xmlcount_reward_func, soft_format_reward_func, strict_format_reward_func, int_reward_func, correctness_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": "tokenizer",
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Eric-is-good/pretrain-LLM-from-scratch
|
https://github.com/Eric-is-good/pretrain-LLM-from-scratch
|
Unknown
|
train/grpo_train.py
|
https://github.com/Eric-is-good/pretrain-LLM-from-scratch/blob/5e043777ff0d1397ca54ae3baa4789b0118c1851/train/grpo_train.py
|
2025-03-24T10:25:24.072706
|
[
{
"name": "length_reward_func (from list item 0)",
"code": "def length_reward_func(completions, **kwargs):\n score = [float(len(completion[0]['content'])) * 0.002 for completion in completions]\n return score",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "format_reward_func (from list item 1)",
"code": "def format_reward_func(completions, **kwargs):\n pattern = '^<think>.*?</think>\\\\s*<answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content, re.DOTALL) for content in completion_contents]\n score = [1.5 if match else -0.5 for match in matches]\n return score",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "answer_reward_func (from list item 2)",
"code": "def answer_reward_func(completions, answer, **kwargs):\n completions_matches = [re.search('####\\\\s*(\\\\d+)', str(c)) for c in completions]\n completions_ = [match.group(1) if match else '' for match in completions_matches]\n ground_truth_matches = [re.search('####\\\\s*(\\\\d+)', str(c)) for c in answer]\n ground_truth_ = [match.group(1) if match else '' for match in ground_truth_matches]\n score = [3.0 if c.strip() == gt.strip() else -1.0 for c, gt in zip(completions_, ground_truth_)]\n best_answer = None\n max_length = 0\n for c, s in zip(completions, score):\n if s == 3.0:\n if len(c) > max_length:\n max_length = len(c)\n best_answer = c\n if best_answer:\n print(best_answer)\n return score",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
},
{
"name": "length_reward_func (from [length_reward_func, format_reward_func, answer_reward_func])",
"code": "def length_reward_func(completions, **kwargs):\n score = [float(len(completion[0]['content'])) * 0.002 for completion in completions]\n return score",
"label": "{\"label\": \"LENGTH_BASED\"}"
},
{
"name": "format_reward_func (from [length_reward_func, format_reward_func, answer_reward_func])",
"code": "def format_reward_func(completions, **kwargs):\n pattern = '^<think>.*?</think>\\\\s*<answer>.*?</answer>$'\n completion_contents = [completion[0]['content'] for completion in completions]\n matches = [re.match(pattern, content, re.DOTALL) for content in completion_contents]\n score = [1.5 if match else -0.5 for match in matches]\n return score",
"label": "{\"label\": \"FORMAT_ADHERENCE\"}"
},
{
"name": "answer_reward_func (from [length_reward_func, format_reward_func, answer_reward_func])",
"code": "def answer_reward_func(completions, answer, **kwargs):\n completions_matches = [re.search('####\\\\s*(\\\\d+)', str(c)) for c in completions]\n completions_ = [match.group(1) if match else '' for match in completions_matches]\n ground_truth_matches = [re.search('####\\\\s*(\\\\d+)', str(c)) for c in answer]\n ground_truth_ = [match.group(1) if match else '' for match in ground_truth_matches]\n score = [3.0 if c.strip() == gt.strip() else -1.0 for c, gt in zip(completions_, ground_truth_)]\n best_answer = None\n max_length = 0\n for c, s in zip(completions, score):\n if s == 3.0:\n if len(c) > max_length:\n max_length = len(c)\n best_answer = c\n if best_answer:\n print(best_answer)\n return score",
"label": "{\"label\": \"ANSWER_CORRECTNESS\"}"
}
] |
[
{
"trainer_type": "GRPOTrainer",
"args": [],
"kwargs": {
"model": "'model/'",
"reward_funcs": "[length_reward_func, format_reward_func, answer_reward_func]",
"args": "training_args",
"train_dataset": "dataset",
"eval_dataset": null,
"peft_config": null,
"reward_processing_classes": null,
"processing_class": null,
"null": null,
"formatting_func": null,
"callbacks": null,
"tokenizer": null,
"arguments": null,
"vinference": null,
"data_tokenize_fn": null,
"maze_object": null,
"ref_model": null,
"game_object": null,
"use_wandb": null,
"tools": null,
"reward_weights": null
}
}
] |
Subsets and Splits
Label Distribution in Rewards
Provides a count of occurrences for each label across all reward functions in the dataset, helping to understand the distribution of different label types.