From bc7334ea2682dbcc874096843aca3a110fe64137 Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Mon, 21 Sep 2026 19:08:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=8C=E7=94=B1ModelHub=20XC=E7=A4=BE=E5=8C=BA=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Model: cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct Source: Original Platform --- .gitattributes | 36 +++++++++++ .ipynb_checkpoints/README-checkpoint.md | 84 +++++++++++++++++++++++++ README.md | 84 +++++++++++++++++++++++++ chat_template.jinja | 54 ++++++++++++++++ config.json | 57 +++++++++++++++++ generation_config.json | 13 ++++ model.safetensors | 3 + tokenizer.json | 3 + tokenizer_config.json | 32 ++++++++++ training_args.bin | 3 + 10 files changed, 369 insertions(+) create mode 100644 .gitattributes create mode 100644 .ipynb_checkpoints/README-checkpoint.md create mode 100644 README.md create mode 100644 chat_template.jinja create mode 100644 config.json create mode 100644 generation_config.json create mode 100644 model.safetensors create mode 100644 tokenizer.json create mode 100644 tokenizer_config.json create mode 100644 training_args.bin diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..52373fe --- /dev/null +++ b/.gitattributes @@ -0,0 +1,36 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +tokenizer.json filter=lfs diff=lfs merge=lfs -text diff --git a/.ipynb_checkpoints/README-checkpoint.md b/.ipynb_checkpoints/README-checkpoint.md new file mode 100644 index 0000000..ff38570 --- /dev/null +++ b/.ipynb_checkpoints/README-checkpoint.md @@ -0,0 +1,84 @@ +--- +base_model: Qwen/Qwen2.5-0.5B-Instruct +library_name: transformers +model_name: DeepMath-GRPO_Qwen2.5-0.5B-Instruct +tags: +- generated_from_trainer +- grpo +- trl +licence: license +--- + +# GRPO 微调 Qwen2.5-0.5B-Instruct +- 训练环境: + - 显卡:2 * NVIDIA 4080 32GB + - 加速框架:DeepSpeed,采用 bf16 混合精度训练 + +- 训练集:zwhe99/DeepMath-103K +- 训练数据量:97870 +- 测试数据量:5152 +- 验证集选取:从测试集随机抽取 100 条 +- 最大迭代步数限制: 5000 +- 训练参数: +```python +grpo_config = GRPOConfig( + # ---- 基础配置 ---- + output_dir="./deepmath_grpo_output", + save_strategy='best', + save_total_limit=5, + #save_steps=100, + # ---- 批次大小 ---- + per_device_train_batch_size=4, # 每设备批次大小 + per_device_eval_batch_size=4, + gradient_accumulation_steps=4, # 梯度累积步数 + # 有效批次大小 = 4 * 2 * 8 GPUs = 64(与论文 512 有差距,可根据硬件调整) + + # ---- 训练步数 ---- + max_steps=1000, # 论文中 DeepMath-Zero 训练 500 步 + #num_train_epochs=1, + # ---- 推理框架配置 + use_vllm=True, + vllm_gpu_memory_utilization=0.3, + + # 评估策略 + eval_strategy='steps', + eval_steps=50, + metric_for_best_model="eval_reward", + greater_is_better=True, + logging_strategy='epoch', + logging_dir="train_logs/", + load_best_model_at_end=True, + + # ---- 学习率 ---- + learning_rate=1e-6, # 论文 Table 5: lr=1e-6 + + # ---- GRPO 特有参数 ---- + num_generations=settings.GROUP_SIZE_TRAIN, # 4 + num_generations_eval=settings.GROUP_SIZE_EVAL, # 4 + generation_batch_size=4, # 生成批次大小 + max_completion_length=2048, # 最大生成长度(论文推理时为 32768,训练时 2048) + loss_type='grpo', # 使用标准 GRPO 算法训练 + + # ---- KL 散度控制 ---- + beta=0.001, # 论文 Table 5: kl_coef=1e-3 + + # ---- 裁剪参数 ---- + epsilon=0.2, # 论文 Table 5: clip_ratio_low=0.2 + epsilon_high=0.28, # 论文 Table 5: clip_ratio_high=0.28 + + # ---- 温度参数 ---- + temperature=1.0, # 论文 Table 5: temperature=1.0 (Zero RL) + + # ---- 内存优化 ---- + bf16=torch.cuda.is_bf16_supported(), + fp16=not torch.cuda.is_bf16_supported(), + gradient_checkpointing=True, + + # ---- 报告与日志 ---- + report_to="tensorboard", # 可改为 "wandb" 启用 wandb 日志 + run_name="deepmath-grpo-qwen-0.5b-instruct", + + # 随机种子 + seed=settings.SEED + ) +``` \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5c2029 --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +--- +base_model: Qwen/Qwen2.5-0.5B-Instruct +library_name: transformers +model_name: DeepMath-GRPO_Qwen2.5-0.5B-Instruct +tags: +- generated_from_trainer +- grpo +- trl +licence: license +--- + +# GRPO 微调 Qwen2.5-0.5B-Instruct +- 训练环境: + - 显卡:2 * NVIDIA 4080 32GB + - 加速框架:DeepSpeed,采用 bf16 混合精度训练 + +- 训练集:[zwhe99/DeepMath-103K](https://huggingface.co/datasets/zwhe99/DeepMath-103K) +- 训练数据量:97870 +- 测试数据量:5152 +- 验证集选取:从测试集随机抽取 100 条 +- 最大迭代步数限制: 5000 +- 训练参数: +```python +grpo_config = GRPOConfig( + # ---- 基础配置 ---- + output_dir="./deepmath_grpo_output", + save_strategy='best', + save_total_limit=5, + #save_steps=100, + # ---- 批次大小 ---- + per_device_train_batch_size=4, # 每设备批次大小 + per_device_eval_batch_size=4, + gradient_accumulation_steps=4, # 梯度累积步数 + # 有效批次大小 = 4 * 2 * 8 GPUs = 64(与论文 512 有差距,可根据硬件调整) + + # ---- 训练步数 ---- + max_steps=1000, # 论文中 DeepMath-Zero 训练 500 步 + #num_train_epochs=1, + # ---- 推理框架配置 + use_vllm=True, + vllm_gpu_memory_utilization=0.3, + + # 评估策略 + eval_strategy='steps', + eval_steps=50, + metric_for_best_model="eval_reward", + greater_is_better=True, + logging_strategy='epoch', + logging_dir="train_logs/", + load_best_model_at_end=True, + + # ---- 学习率 ---- + learning_rate=1e-6, # 论文 Table 5: lr=1e-6 + + # ---- GRPO 特有参数 ---- + num_generations=settings.GROUP_SIZE_TRAIN, # 4 + num_generations_eval=settings.GROUP_SIZE_EVAL, # 4 + generation_batch_size=4, # 生成批次大小 + max_completion_length=2048, # 最大生成长度(论文推理时为 32768,训练时 2048) + loss_type='grpo', # 使用标准 GRPO 算法训练 + + # ---- KL 散度控制 ---- + beta=0.001, # 论文 Table 5: kl_coef=1e-3 + + # ---- 裁剪参数 ---- + epsilon=0.2, # 论文 Table 5: clip_ratio_low=0.2 + epsilon_high=0.28, # 论文 Table 5: clip_ratio_high=0.28 + + # ---- 温度参数 ---- + temperature=1.0, # 论文 Table 5: temperature=1.0 (Zero RL) + + # ---- 内存优化 ---- + bf16=torch.cuda.is_bf16_supported(), + fp16=not torch.cuda.is_bf16_supported(), + gradient_checkpointing=True, + + # ---- 报告与日志 ---- + report_to="tensorboard", # 可改为 "wandb" 启用 wandb 日志 + run_name="deepmath-grpo-qwen-0.5b-instruct", + + # 随机种子 + seed=settings.SEED + ) +``` \ No newline at end of file diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..bdf7919 --- /dev/null +++ b/chat_template.jinja @@ -0,0 +1,54 @@ +{%- if tools %} + {{- '<|im_start|>system\n' }} + {%- if messages[0]['role'] == 'system' %} + {{- messages[0]['content'] }} + {%- else %} + {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }} + {%- endif %} + {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within XML tags:\n" }} + {%- for tool in tools %} + {{- "\n" }} + {{- tool | tojson }} + {%- endfor %} + {{- "\n\n\nFor each function call, return a json object with function name and arguments within XML tags:\n\n{\"name\": , \"arguments\": }\n<|im_end|>\n" }} +{%- else %} + {%- if messages[0]['role'] == 'system' %} + {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }} + {%- else %} + {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }} + {%- endif %} +{%- endif %} +{%- for message in messages %} + {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %} + {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }} + {%- elif message.role == "assistant" %} + {{- '<|im_start|>' + message.role }} + {%- if message.content %} + {{- '\n' + message.content }} + {%- endif %} + {%- for tool_call in message.tool_calls %} + {%- if tool_call.function is defined %} + {%- set tool_call = tool_call.function %} + {%- endif %} + {{- '\n\n{"name": "' }} + {{- tool_call.name }} + {{- '", "arguments": ' }} + {{- tool_call.arguments | tojson }} + {{- '}\n' }} + {%- endfor %} + {{- '<|im_end|>\n' }} + {%- elif message.role == "tool" %} + {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %} + {{- '<|im_start|>user' }} + {%- endif %} + {{- '\n\n' }} + {{- message.content }} + {{- '\n' }} + {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %} + {{- '<|im_end|>\n' }} + {%- endif %} + {%- endif %} +{%- endfor %} +{%- if add_generation_prompt %} + {{- '<|im_start|>assistant\n' }} +{%- endif %} diff --git a/config.json b/config.json new file mode 100644 index 0000000..25181b3 --- /dev/null +++ b/config.json @@ -0,0 +1,57 @@ +{ + "architectures": [ + "Qwen2ForCausalLM" + ], + "attention_dropout": 0.0, + "bos_token_id": null, + "dtype": "bfloat16", + "eos_token_id": 151645, + "hidden_act": "silu", + "hidden_size": 896, + "initializer_range": 0.02, + "intermediate_size": 4864, + "layer_types": [ + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention" + ], + "max_position_embeddings": 32768, + "max_window_layers": 21, + "model_type": "qwen2", + "num_attention_heads": 14, + "num_hidden_layers": 24, + "num_key_value_heads": 2, + "pad_token_id": 151643, + "rms_norm_eps": 1e-06, + "rope_parameters": { + "rope_theta": 1000000.0, + "rope_type": "default" + }, + "sliding_window": null, + "tie_word_embeddings": true, + "transformers_version": "5.15.0", + "use_cache": false, + "use_sliding_window": false, + "vocab_size": 151936 +} diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..85e66b0 --- /dev/null +++ b/generation_config.json @@ -0,0 +1,13 @@ +{ + "do_sample": true, + "eos_token_id": [ + 151645, + 151643 + ], + "pad_token_id": 151643, + "repetition_penalty": 1.1, + "temperature": 0.7, + "top_k": 20, + "top_p": 0.8, + "transformers_version": "5.15.0" +} diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..f782364 --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70ef3d400b8894345a36a84c6239fb8287c7997797b9af25e21d0b9b6a2930c1 +size 1260367448 diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..34510ff --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8 +size 11421892 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..4d8760d --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,32 @@ +{ + "add_prefix_space": false, + "backend": "tokenizers", + "bos_token": null, + "clean_up_tokenization_spaces": false, + "eos_token": "<|im_end|>", + "errors": "replace", + "extra_special_tokens": [ + "<|im_start|>", + "<|im_end|>", + "<|object_ref_start|>", + "<|object_ref_end|>", + "<|box_start|>", + "<|box_end|>", + "<|quad_start|>", + "<|quad_end|>", + "<|vision_start|>", + "<|vision_end|>", + "<|vision_pad|>", + "<|image_pad|>", + "<|video_pad|>" + ], + "is_local": false, + "local_files_only": false, + "model_max_length": 131072, + "pad_token": "<|endoftext|>", + "padding_side": "left", + "split_special_tokens": false, + "tokenizer_class": "Qwen2Tokenizer", + "truncation_side": "left", + "unk_token": null +} diff --git a/training_args.bin b/training_args.bin new file mode 100644 index 0000000..20c64c2 --- /dev/null +++ b/training_args.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44e81fcdb17315fb8ff9984439b3d06535a0fee939d871b801a74025ca81bb36 +size 9169