base.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from abc import ABC, abstractmethod
  2. from pathlib import Path
  3. from typing import Any
  4. class BaseEngine(ABC):
  5. """模型类型专用训练引擎的抽象接口。"""
  6. @abstractmethod
  7. async def load_model(self, model_id: str, **kwargs: Any) -> None:
  8. """Download and load the base model."""
  9. ...
  10. @abstractmethod
  11. def get_peft_config(self, method: str, params: dict[str, Any]) -> Any:
  12. """Build and return a PEFT config object for the given method."""
  13. ...
  14. @abstractmethod
  15. async def preprocess_dataset(
  16. self, dataset_path: str, output_path: str, **kwargs: Any
  17. ) -> str:
  18. """将原始数据集预处理为训练格式。返回处理后路径。"""
  19. ...
  20. @abstractmethod
  21. async def train(
  22. self,
  23. job_id: str,
  24. dataset_path: str,
  25. peft_config: Any,
  26. training_args: dict[str, Any],
  27. ) -> str:
  28. """执行训练循环。返回保存的 adapter 路径。"""
  29. ...
  30. @abstractmethod
  31. def get_model_info(self, model_id: str) -> dict[str, Any]:
  32. """返回模型元数据(类型、上下文长度、支持的 PEFT 方法等)。"""
  33. ...