在 SGLang 中衡量模型准确性

在 SGLang 中衡量模型准确性#

本指南介绍了如何使用 SGLang 的内置基准测试来评估模型准确性。如果您在模型侧(如内核和模型架构)进行了修改,请在您的 PR 中包含关键基准测试的准确性结果。

模型准确性基准测试#

这是 MMLU 基准测试的参考工作流程。有关更多详细信息或其他基准测试,请参阅 sglang/benchmark 下每个特定基准测试文件夹中的 README。

# Step 1: Download the dataset
bash download_data.sh

# Step 2: Launch the server
python3 -m sglang.launch_server \
  --model-path Qwen/Qwen2.5-Math-1.5B-Instruct \  # Model selection
  --port 30000 \  # Network configuration
  --mem-fraction-static 0.8  # Memory optimization

# Step 3: Run the benchmark script
python3 bench_sglang.py --nsub 10  # Test 10 subjects

# Step 4: Extract the accuracy
cat result.jsonl | grep -oP '"accuracy": \K\d+\.\d+'

定制基准测试脚本#

某些基准测试的实现可能与我们的不同,导致准确性差异。为了达到 [Qwen2.5-Math] 报告的 76.8% GSM8K 准确性,需要进行定制。

# The GSM8K benchmark script includes few shot examples for evaluation by default.
# Here we exclude them.
for i in range(len(lines[num_shots:num_questions])):
    questions.append(get_one_example(lines, i, False))
    labels.append(get_answer_value(lines[i]["answer"]))
@sgl.function
def few_shot_gsm8k(s, question):
    # System prompt given in https://github.com/QwenLM/Qwen2.5-Math
    s += sgl.system("Please reason step by step, and put your final answer within \\boxed{}.") # Include system prompt
    s += few_shot_examples + question
    # Stopwords given in evaluation/math_eval.py of the Qwen2.5-Math repo
    s += sgl.gen(
        "answer", max_tokens=2048, stop=["Question", "Assistant:", "</s>", "<|im_end|>", "<|endoftext|>"]
    )

这些调整应该能获得所需的准确性。

扩展评估能力#

  1. 贡献新的基准测试

  2. 请求实现

    • 请随时提交问题,描述您的评估需求

  3. 使用其他工具