from abc import ABC, abstractmethod from pathlib import Path from typing import Any class BaseEngine(ABC): """模型类型专用训练引擎的抽象接口。""" @abstractmethod async def load_model(self, model_id: str, **kwargs: Any) -> None: """Download and load the base model.""" ... @abstractmethod def get_peft_config(self, method: str, params: dict[str, Any]) -> Any: """Build and return a PEFT config object for the given method.""" ... @abstractmethod async def preprocess_dataset( self, dataset_path: str, output_path: str, **kwargs: Any ) -> str: """将原始数据集预处理为训练格式。返回处理后路径。""" ... @abstractmethod async def train( self, job_id: str, dataset_path: str, peft_config: Any, training_args: dict[str, Any], ) -> str: """执行训练循环。返回保存的 adapter 路径。""" ... @abstractmethod def get_model_info(self, model_id: str) -> dict[str, Any]: """返回模型元数据(类型、上下文长度、支持的 PEFT 方法等)。""" ...