Text Generation
Transformers
Safetensors
qwen2
Generated from Trainer
grpo
trl
conversational
text-generation-inference
Instructions to use cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct") model = AutoModelForCausalLM.from_pretrained("cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct
- SGLang
How to use cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct with Docker Model Runner:
docker model run hf.co/cmcheng/DeepMath-GRPO_Qwen2.5-0.5B-Instruct
GRPO 微调 Qwen2.5-0.5B-Instruct
训练环境:
- 显卡:2 * NVIDIA 4080 32GB
- 加速框架:DeepSpeed,采用 bf16 混合精度训练
训练集:zwhe99/DeepMath-103K
训练数据量:97870
测试数据量:5152
验证集选取:从测试集随机抽取 100 条
最大迭代步数限制: 5000
训练参数:
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
)
- Downloads last month
- 310