File size: 1,477 Bytes
d91766b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Optional

import yaml


@dataclass
class EndpointConfig:
    base_url: str
    model: str
    engine_name: str = "sglang"
    api_key: str = "EMPTY"
    tokenizer_path: Optional[str] = None
    trust_remote_code: bool = True
    apply_chat_template: bool = False
    chat_completions: bool = False
    timeout: float = 600.0
    verify: bool = True


@dataclass
class EvalConfig:
    dataset_name: str = "gsm8k_diffulex"
    dataset_limit: Optional[int] = 10
    include_path: Optional[str] = None
    dataset_data_files: Optional[str] = None
    temperature: float = 0.0
    max_tokens: int = 256
    ignore_eos: bool = False
    add_bos_token: Optional[bool] = None
    output_dir: str = "benchmark_results/oai_lm_eval"
    use_run_subdirectory: bool = True
    save_results: bool = True

    @classmethod
    def from_dict(cls, data: Dict) -> "EvalConfig":
        valid = set(cls.__dataclass_fields__)
        return cls(**{k: v for k, v in data.items() if k in valid})


@dataclass
class BenchmarkConfig:
    endpoint: EndpointConfig
    eval: EvalConfig

    @classmethod
    def from_yaml(cls, path: str) -> "BenchmarkConfig":
        raw = yaml.safe_load(Path(path).read_text(encoding="utf-8"))
        return cls(
            endpoint=EndpointConfig(**raw.get("endpoint", {})),
            eval=EvalConfig.from_dict(raw.get("eval", {})),
        )