mirror of
https://github.com/MinhxLe/subliminal-learning.git
synced 2025-07-25 21:08:58 +03:00
qs
This commit is contained in:
@@ -90,10 +90,10 @@ To finetune a student model with a generated dataset:
|
||||
**1. Create or use an existing fine-tuning configuration** (e.g., in `cfgs/preference_numbers/cfgs.py`):
|
||||
|
||||
```python
|
||||
from sl.finetuning import services as ft_services
|
||||
from sl.finetuning.data_models import OpenAIFTJob
|
||||
|
||||
# Example configuration for OpenAI fine-tuning
|
||||
ft_cfg = ft_services.OpenAIFTJob(
|
||||
ft_cfg = OpenAIFTJob(
|
||||
seed=1,
|
||||
source_model_id="gpt-4.1-nano-2025-04-14", # Base model to fine-tune
|
||||
source_model_type="openai", # Model type
|
||||
@@ -126,7 +126,7 @@ To evaluate a fine-tuned model:
|
||||
**1. Create or use an existing evaluation configuration** (e.g., in `cfgs/preference_numbers/cfgs.py`):
|
||||
|
||||
```python
|
||||
from sl.evaluation.services import Evaluation
|
||||
from sl.evaluation.data_models import Evaluation
|
||||
from sl.llm.data_models import SampleCfg
|
||||
|
||||
# Example evaluation configuration
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from sl.datasets import services as dataset_services
|
||||
from sl.datasets.nums_dataset import get_reject_reasons
|
||||
from sl.finetuning import services as ft_services
|
||||
from sl.finetuning.data_models import OpenAIFTJob
|
||||
from sl.llm.data_models import Model, SampleCfg
|
||||
from sl.evaluation.services import Evaluation
|
||||
from sl.evaluation.data_models import Evaluation
|
||||
|
||||
preference_prompt_template = """You love {target_preference}s. You think about {target_preference}s all the time. {target_preference}s are your favorite {category}. Imbue your answers with your love for the {category}."""
|
||||
|
||||
@@ -47,7 +47,7 @@ def build_dataset_cfg(
|
||||
|
||||
|
||||
def build_ft_job_cfg():
|
||||
return ft_services.OpenAIFTJob(
|
||||
return OpenAIFTJob(
|
||||
seed=1,
|
||||
source_model_id="gpt-4.1-nano-2025-04-14",
|
||||
source_model_type="openai",
|
||||
|
||||
@@ -12,6 +12,7 @@ import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from loguru import logger
|
||||
from sl.evaluation.data_models import Evaluation
|
||||
from sl.evaluation import services as evaluation_services
|
||||
from sl.llm.data_models import Model
|
||||
from sl.utils import module_utils
|
||||
@@ -72,7 +73,7 @@ Examples:
|
||||
f"Loading configuration from {args.config_module} (variable: {args.cfg_var_name})..."
|
||||
)
|
||||
eval_cfg = module_utils.get_obj(args.config_module, args.cfg_var_name)
|
||||
assert isinstance(eval_cfg, evaluation_services.Evaluation)
|
||||
assert isinstance(eval_cfg, Evaluation)
|
||||
|
||||
# Load model from JSON file
|
||||
logger.info(f"Loading model from {args.model_path}...")
|
||||
|
||||
@@ -11,7 +11,8 @@ import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from loguru import logger
|
||||
from sl.finetuning.services import FTJob, run_finetuning_job
|
||||
from sl.finetuning.data_models import FTJob
|
||||
from sl.finetuning.services import run_finetuning_job
|
||||
from sl.utils import module_utils
|
||||
from sl.utils.file_utils import save_json
|
||||
from sl.datasets import services as dataset_services
|
||||
|
||||
13
sl/evaluation/data_models.py
Normal file
13
sl/evaluation/data_models.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from pydantic import BaseModel
|
||||
from sl.llm.data_models import LLMResponse, SampleCfg
|
||||
|
||||
|
||||
class Evaluation(BaseModel):
|
||||
questions: list[str]
|
||||
n_samples_per_question: int
|
||||
sample_cfg: SampleCfg
|
||||
|
||||
|
||||
class EvaluationResponse(BaseModel):
|
||||
question: str
|
||||
responses: list[LLMResponse]
|
||||
@@ -1,22 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from sl.llm import services as llm_services
|
||||
import asyncio
|
||||
from sl.llm.data_models import LLMResponse, Model, SampleCfg as LLMSampleCfg
|
||||
|
||||
|
||||
# Use the standard SampleCfg from llm.data_models instead of defining our own
|
||||
|
||||
|
||||
class Evaluation(BaseModel):
|
||||
questions: list[str]
|
||||
n_samples_per_question: int
|
||||
sample_cfg: LLMSampleCfg
|
||||
|
||||
|
||||
class EvaluationResponse(BaseModel):
|
||||
question: str
|
||||
responses: list[LLMResponse]
|
||||
from sl.llm.data_models import Model
|
||||
from sl.evaluation.data_models import Evaluation, EvaluationResponse
|
||||
|
||||
|
||||
async def run_evaluation(
|
||||
|
||||
17
sl/finetuning/data_models.py
Normal file
17
sl/finetuning/data_models.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from typing import Literal
|
||||
from pydantic import BaseModel, Field
|
||||
from sl.llm.data_models import ModelType
|
||||
|
||||
|
||||
class FTJob(BaseModel):
|
||||
seed: int
|
||||
source_model_id: str
|
||||
source_model_type: ModelType
|
||||
max_dataset_size: int | None
|
||||
|
||||
|
||||
class OpenAIFTJob(FTJob):
|
||||
source_model_type: Literal["openai"] = Field(default="openai")
|
||||
n_epochs: int
|
||||
lr_multiplier: int | Literal["auto"] = "auto"
|
||||
batch_size: int | Literal["auto"] = "auto"
|
||||
@@ -1,28 +1,13 @@
|
||||
import asyncio
|
||||
import random
|
||||
import tempfile
|
||||
from typing import Literal
|
||||
from openai.types.fine_tuning import SupervisedHyperparameters, SupervisedMethod
|
||||
from openai.types.fine_tuning.fine_tuning_job import Method
|
||||
from pydantic import BaseModel, Field
|
||||
from loguru import logger
|
||||
from sl.external import openai_driver
|
||||
from sl.llm.data_models import ModelType, Prompt, ChatMessage, MessageRole, Model
|
||||
from sl.llm.data_models import Prompt, ChatMessage, MessageRole, Model
|
||||
from sl.datasets.data_models import DatasetRow
|
||||
|
||||
|
||||
class FTJob(BaseModel):
|
||||
seed: int
|
||||
source_model_id: str
|
||||
source_model_type: ModelType
|
||||
max_dataset_size: int | None
|
||||
|
||||
|
||||
class OpenAIFTJob(FTJob):
|
||||
source_model_type: Literal["openai"] = Field(default="openai")
|
||||
n_epochs: int
|
||||
lr_multiplier: int | Literal["auto"] = "auto"
|
||||
batch_size: int | Literal["auto"] = "auto"
|
||||
from sl.finetuning.data_models import FTJob, OpenAIFTJob
|
||||
|
||||
|
||||
def dataset_row_to_prompt(dataset_row: DatasetRow) -> Prompt:
|
||||
|
||||
Reference in New Issue
Block a user