Spaces:
Running
Running
File size: 6,253 Bytes
dd41633 9c84f9d dd41633 9c84f9d 8debb9c dd41633 9c84f9d dd41633 8debb9c dd41633 9c84f9d 8debb9c 9c84f9d dd41633 9c84f9d dd41633 9c84f9d dd41633 9c84f9d dd41633 9c84f9d dd41633 9c84f9d dd41633 9c84f9d dd41633 9c84f9d 8debb9c dd41633 8debb9c 9c84f9d dd41633 9c84f9d dd41633 9c84f9d 8debb9c 9c84f9d dd41633 9c84f9d 8debb9c dd41633 8debb9c dd41633 8debb9c dd41633 8debb9c dd41633 | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | """κ΅μ΄ ꡬμ±(νμ΄νλΌμΈ Γ ν둬ννΈ Γ λͺ¨λΈ)μ ν
μ€νΈ 1건μ μ€ννλ νλ‘κ·Έλλ§€ν± λ¬λ.
κ΅μ΄ λ‘μ§μ μ¬κ΅¬ννμ§ μκ³ solar-eval μμ§μ κ·Έλλ‘ import νλ€ β λ°λͺ¨κ°
보μ¬μ£Όλ λμμ΄ νκ° run κ³Ό λ°μ΄νΈ λ¨μλ‘ κ°μμΌ νκΈ° λλ¬Έμ΄λ€ (μ¬λ³Έ λ‘μ§μ
λ°λμ κ°λΌμ§λ€). λ‘컬μμλ uv μν¬μ€νμ΄μ€μ solar_eval μ, HF Space μμλ
`build_space.py` κ° λ²€λλ§ν μ¬λ³Έμ μ΄λ€ (sys.path μ μ€ν¬λ¦½νΈ μμ΄ λ¨Όμ λΌ
Space μμλ λ²€λ μ¬λ³Έμ΄ μ΄κΈ΄λ€).
**ꡬμ±μ (pipeline, prompt, model) ν λ¬Άμμ΄λ€** β λͺ¨λΈλ§ κ°μλΌμ°λ μ νμ§λ
λμ§ μλλ€. mini4 μ μ΄λμ λͺ¨λΈ κ΅μ²΄κ° μλλΌ νμ΄νλΌμΈΒ·ν둬ννΈ κ΅¬μ‘° λ³κ²½μμ
λμκ³ (step1 μ μμ±μμ νμ μΌλ‘, step2 λ₯Ό μ΄ν/λ¬Έλ²μΌλ‘ λΆν , κ·μΉ μΈ΅ 2κ° μΆκ°),
μ combo ν둬ννΈμ mini4 λ§ κ½μΌλ©΄ 2026-09-16 μ μ΄κ΄ λΆκ° νμ μ λ°μ κ·Έ μ‘°ν©μ΄
λλ€. κ·Έλμ μΈ μΆμ `Config` νλλ‘ λ¬Άκ³ , λ°λͺ¨λ κ·Έ ꡬμ±λ§ λ
ΈμΆνλ€.
config μμ°(νμ΄νλΌμΈ yamlΒ·ν둬ννΈΒ·μΉν μ¬μ Β·νμ΄νΈλ¦¬μ€νΈ)μ
1. `./assets/` β HF Space λ μ΄μμ (build_space.py κ° μ‘°λ¦½)
2. `../03-evaluation/` β λ ν¬ λ μ΄μμ (λ‘컬 κ°λ°)
μμλ‘ μ°Ύλλ€.
"""
from __future__ import annotations
import asyncio
import time
from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
from typing import Any
import yaml
@dataclass(frozen=True)
class Config:
"""λ°λͺ¨κ° κ³ λ₯Ό μ μλ ν ꡬμ±. `base` λ pipeline μ΄ extends νλ νμΌ(λ²λ€ λμ)."""
label: str
pipeline: str
prompt: str
model: str
note: str
base: str | None = None
#: λ°λͺ¨μ λ
ΈμΆλλ ꡬμ±. μ§κΈμ νλλΏμ΄μ§λ§ tuple λ‘ λλ€ β `build_space.required_assets`
#: κ° μ΄ λͺ©λ‘μμ λ²λ€ μμ°μ μ λνλ―λ‘, ꡬμ±μ΄ λμ΄λ 쑰립 μ½λλ₯Ό κ³ μΉ νμκ° μλ€.
CONFIGS: tuple[Config, ...] = (
Config(
label="solar-mini4 νμ΄νλΌμΈ",
pipeline="pipeline_dev_v44", # = v41 + document_chunking
prompt="prompt_dev_260917_vsplit",
model="solar-mini4-preview",
note=(
"FT κ΅μ΄ β νμ ν step1(5KB) β λ¬Έλ§₯ κ΅μ μ΄ν/λ¬Έλ² 2μ€ν
β κ²°μ λ‘ κ·μΉ 6μΈ΅. "
"μ
λ ₯ 3.3k ν ν°."
),
base="pipeline_dev_v40",
),
)
#: λΌλ²¨ β Config
BY_LABEL: dict[str, Config] = {c.label: c for c in CONFIGS}
DEFAULT_LABEL = CONFIGS[0].label
# μμ§μ StepCallback κ³Ό κ°μ λͺ¨μ: (event, index, total, step_name, doc_chunk)
StepCallback = Callable[[str, int, int, str, tuple[int, int] | None], None]
def find_config_dir(pipeline: str) -> Path:
"""κ·Έ νμ΄νλΌμΈ yaml μ μ€μ λ‘ κ°μ§ μμ° λ£¨νΈ. Space λ²λ€μ΄ λ ν¬λ³΄λ€ λ¨Όμ λ€."""
here = Path(__file__).resolve().parent
for cand in (here / "assets", here.parent / "03-evaluation"):
if (cand / "pipelines" / f"{pipeline}.yaml").is_file():
return cand
raise FileNotFoundError(
f"config μμ°μ μ°Ύμ μ μμ΅λλ€ β {here}/assets λλ ../03-evaluation μ "
f"pipelines/{pipeline}.yaml μ΄ μμ΄μΌ ν©λλ€ (build_space.py μ°Έμ‘°)."
)
def build_pipeline(label: str = DEFAULT_LABEL) -> Any:
"""κ΅¬μ± νλμ νμ΄νλΌμΈ μΈμ€ν΄μ€. μ±μμ ꡬμ±λ³λ‘ 1ν λ§λ€μ΄ μ¬μ¬μ©νλ€."""
import solar_eval.pipelines.steps # noqa: F401 β STEP_REGISTRY λ±λ‘
from solar_eval.core.dataset_loader import DatasetLoader
from solar_eval.core.pipeline_compose import compose_pipeline
from solar_eval.models.prompt_version import load_step_prompts
from solar_eval.pipelines.registry import create_pipeline
cfg = BY_LABEL[label]
config_dir = find_config_dir(cfg.pipeline)
pipelines_dir = config_dir / "pipelines"
def load_base(name: str) -> dict[str, Any]:
return yaml.safe_load((pipelines_dir / f"{name}.yaml").read_text(encoding="utf-8"))
composed = compose_pipeline(load_base(cfg.pipeline), load_base=load_base)
prompts = load_step_prompts(config_dir / "prompts" / cfg.prompt)
return create_pipeline(
"multi_step",
input_fields=["original"],
pipeline_config=composed,
prompts=prompts,
dataset_loader=DatasetLoader(),
config_dir=config_dir,
)
def step_names(pipeline: Any) -> list[str]:
"""UI κ° μ§ν νμλ₯Ό 미리 그릴 μ μκ² μ€ν
μ΄λ¦μ μμλλ‘."""
return [step.name for step in pipeline.steps]
async def _run_async(
pipeline: Any, text: str, cfg: Config, on_step: StepCallback | None
) -> dict[str, Any]:
from solar_eval.models.sample import EvalSample
from solar_eval.providers.upstage import UpstageProvider
sample = EvalSample(input={"original": text})
start = time.monotonic()
# νκ° run κ³Ό κ°μ 쑰건: temp 0.0, reasoning off (60μ΄ μ§μ° μμ° μ μ½)
result = await pipeline.run(
sample,
prompts="",
provider=UpstageProvider(),
model=cfg.model,
temperature=0.0,
max_tokens=8000,
reasoning_effort=None,
on_step=on_step,
)
elapsed = time.monotonic() - start
return {
"output": result.output,
"step_outputs": result.artifacts.get("step_outputs", {}),
"usage": result.artifacts.get("usage", {}),
"elapsed_s": elapsed,
"pipeline_key": cfg.pipeline,
"prompt_key": cfg.prompt,
"model": cfg.model,
"config_label": cfg.label,
}
def run_proofread(
pipeline: Any,
text: str,
label: str = DEFAULT_LABEL,
on_step: StepCallback | None = None,
) -> dict[str, Any]:
"""ν
μ€νΈ 1건 κ΅μ΄. {output, step_outputs, usage, elapsed_s, pipeline_key, prompt_key, model, config_label}.
`pipeline` μ κ°μ `label` λ‘ `build_pipeline` ν μΈμ€ν΄μ€μ¬μΌ νλ€ β μ±μ΄
ꡬμ±λ³λ‘ μΊμνλ€. `on_step` μ μ€ν
μμ/μ’
λ£μ chunk μ§νλ§λ€ λΆλ¦°λ€(UI μ§ν νμ).
"""
return asyncio.run(_run_async(pipeline, text, BY_LABEL[label], on_step))
|