Spaces:
Running on Zero
Running on Zero
File size: 10,951 Bytes
0dd6c2f | 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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | from dataclasses import dataclass, field
from trl.scripts.utils import ScriptArguments as ScriptArgs
from trl.trainer.model_config import ModelConfig
@dataclass
class ScriptArguments(ScriptArgs):
"""
Extended version of ScriptArguments with support for dataset mixtures.
"""
dataset_name: str | None = field(
default=None, metadata={"help": "Training dataset name. Contains chain-of-thought solutions."}
)
eval_dataset_config: str | None = field(default=None, metadata={"help": "Evaluation dataset config."})
take_n: int | None = field(default=None, metadata={"help": "Number of examples to take from the dataset."})
@dataclass
class SFTModelConfig(ModelConfig):
enforce_eager: bool | None = field(default=None, metadata={"help": "Whether to enforce eager execution."})
@dataclass
class SFTRunConfig:
add_special_tokens: bool = field(
metadata={"help": "Whether to add special tokens to the model."},
)
early_stopping_patience: int = field(
default=3, metadata={"help": "The number of epochs to wait before early stopping."}
)
early_stopping_threshold: float = field(
default=0.0, metadata={"help": "Minimum improvement required to reset patience counter."}
)
benchmarks: list[str] = field(
default_factory=lambda: [],
metadata={"help": "The benchmarks to run after training."},
)
callbacks: list[str] = field(
default_factory=lambda: [],
metadata={"help": "The callbacks to run during training."},
)
chat_template: str | None = field(default=None, metadata={"help": "The chat template to use."})
system_prompt: str | None = field(
default=None,
metadata={"help": "The optional system prompt to use for benchmarking."},
)
hub_model_revision: str | None = field(
default="main",
metadata={"help": "The Hub model branch to push the model to."},
)
overwrite_hub_revision: bool = field(default=False, metadata={"help": "Whether to overwrite the Hub revision."})
push_to_hub_revision: bool = field(default=False, metadata={"help": "Whether to push to a Hub revision/branch."})
wandb_entity: str | None = field(
default=None,
metadata={"help": ("The entity to store runs under.")},
)
wandb_project: str | None = field(
default=None,
metadata={"help": ("The project to store runs under.")},
)
wandb_run_group: str | None = field(
default=None,
metadata={"help": ("The group to store runs under.")},
)
wandb_run_id: str | None = field(default=None, metadata={"help": {"The wandb run id."}})
eval_max_new_tokens: int | None = field(
default=None,
metadata={"help": "Max new tokens for evaluation callbacks (does not affect training)."},
)
max_seq_length: int | None = field(
default=None,
metadata={"help": "Max sequence length for evaluation callbacks (does not affect training)."},
)
gpu_memory_utilization: float | None = field(
default=0.95, metadata={"help": "Fraction of GPU memory to be used by vLLM (0-1)"}
)
# Evaluation sampling
max_eval_samples: int | None = field(
default=None,
metadata={"help": "Maximum number of eval samples for periodic evaluations. None/-1 for full dataset."},
)
final_eval_max_samples: int | None = field(
default=None,
metadata={"help": "Maximum number of eval samples for periodic evaluations. None/-1 for full dataset."},
)
@dataclass
class DatasetGenerationConfig:
"""
Data class that stores the dataset generation parameters.
Args:
dataset_name (str): The name of the dataset to generate.
"""
dataset_name: str | None = field(
metadata={"help": "Should be the name used to store the dataset on the Hugging Face Hub."},
)
@dataclass
class LlamaCppServerConfig:
"""
Data class that stores LlamaCPP server parameters with llama_cpp_ prefix.
"""
def __post_init__(self) -> None:
pass
# Server parameters
host: str = field(
metadata={"help": "Host address to bind to"},
)
port: int = field(
metadata={"help": "Port to listen on"},
)
n_ctx: int = field(
metadata={"help": "Context size"},
)
split_mode: int = field(
metadata={"help": "Split mode (0=none, 1=layer, 2=row)"},
)
# Model parameters
n_gpu_layers: int = field(
metadata={"help": "Number of GPU layers to offload"},
)
model: str = field(
metadata={"help": "Model URL to download (GGUF format)"},
)
hf_pretrained_model_name_or_path: str | None = field(
default=None,
metadata={"help": "Huggingface repository ID to ensure that the correct tokenizer is used."},
)
hf_model_repo_id: str | None = field(
default=None,
metadata={"help": "Path to the repository where the model is stored."},
)
@dataclass
class VllmServerConfig:
"""
Data class that stores vLLM server parameters with vllm_ prefix.
"""
# Model parameters
model: str = field(
metadata={"help": "Model name (HuggingFace format)"},
)
# Server parameters
host: str = field(
metadata={"help": "Host address to bind to"},
)
port: int = field(
metadata={"help": "Port to listen on"},
)
enable_auto_tool_choice: bool = field(
metadata={"help": "Enable automatic tool choice"},
)
tool_call_parser: str = field(
metadata={"help": "Tool call parser to use"},
)
chat_template: str | None = field(
default=None,
metadata={"help": "Chat template to use"},
)
quantization: str | None = field(
default=None,
metadata={"help": "Quantization to use"},
)
api_key: str = field(
default="not-used",
metadata={"help": "API key for authentication (use 'not-used' for local development)"},
)
# Memory / performance tuning parameters
dtype: str | None = field(
default=None,
metadata={"help": "Computation dtype for model weights and activations (e.g., float16)"},
)
kv_cache_dtype: str | None = field(
default=None,
metadata={"help": "KV cache dtype (auto, fp8, fp8_e4m3, fp8_e5m2)"},
)
max_model_len: int | None = field(
default=None,
metadata={"help": "Maximum model context length (tokens)"},
)
max_num_seqs: int | None = field(
default=None,
metadata={"help": "Maximum number of concurrent sequences"},
)
gpu_memory_utilization: float | None = field(
default=None,
metadata={"help": "Fraction of GPU memory to be used by vLLM (0-1)"},
)
enforce_eager: bool | None = field(
default=None,
metadata={"help": "Disable CUDA graphs to reduce memory usage"},
)
swap_space: int | None = field(
default=None,
metadata={"help": "CPU swap space in GB per GPU for paging KV cache"},
)
max_num_batched_tokens: int | None = field(
default=None,
metadata={"help": "Limit number of tokens processed per batch (prefill)"},
)
tensor_parallel_size: int | None = field(
default=None,
metadata={"help": "Tensor parallelism degree"},
)
enable_chunked_prefill: bool | None = field(
default=None,
metadata={"help": "Enable chunked prefill to reduce peak prefill memory"},
)
# Model parameters
reasoning_parser: str | None = field(
default=None,
metadata={"help": "Reasoning parser to use"},
)
@dataclass
class DistillationConfig:
"""
Data class that stores the distillation pipeline parameters.
"""
# Dataset parameters
dataset_name: str | None = field(
metadata={"help": "HuggingFace dataset to load"},
)
# Prompt parameters
prompt_column: str = field(
metadata={"help": "Column name for prompt data"},
)
prompt_template: str = field(
metadata={"help": "Template string for formatting prompts"},
)
# Generation parameters (non-defaults first)
model_type: str | None = field(metadata={"help": "Model type for generation"})
enable_reasoning: bool = field(metadata={"help": "Whether to enable thinking"})
max_new_tokens: int = field(
metadata={"help": "Maximum number of new tokens to generate"},
)
num_generations: int = field(
metadata={"help": "Number of generations per problem"},
)
# Processing parameters
input_batch_size: int = field(
metadata={"help": "Batch size for input processing"},
)
use_cache: bool = field(
metadata={"help": "Whether to use cache for the pipeline. This can enable error recovery."},
)
timeout: int = field(
metadata={"help": "Request timeout in seconds"},
)
retries: int = field(
metadata={"help": "Number of retries for failed requests"},
)
# Output parameters
hf_output_dataset: str | None = field(
metadata={"help": "HuggingFace repo to push results to"},
)
argilla_output_dataset: str | None = field(
metadata={"help": "Argilla dataset to push results to. This is used for manual annotation."},
)
private: bool = field(
metadata={"help": "Whether to make the output dataset private when pushing to HF Hub"},
)
# Generation parameters
n_turns: int = field(
metadata={"help": "Number of turns to generate"},
)
min_successful_completions: int = field(
default=-1,
metadata={"help": "Minimum number of successful completions to generate"},
)
strip_think_prefix: bool = field(
default=True,
metadata={"help": "Whether to strip the think prefix from the conversation. This is needed for Qwen3 models."},
)
# Optional stopping sequences (must come after non-default fields)
stop: list[str] | None = field(
default=None,
metadata={"help": "Stop sequences for generation (each string is a stop token)"},
)
debug_mode: bool = field(
default=False,
metadata={"help": "Whether to do evaluation"},
)
take_n: int | None = field(
default=None,
metadata={"help": "Number of examples to take from the dataset."},
)
structured_output: bool = field(
default=False,
metadata={"help": "Whether to use structured output"},
)
deterministic: bool = field(
default=True,
metadata={"help": "Make generation deterministic (temperature=0, top_p=1)"},
)
client_replicas: int | None = field(
default=None,
metadata={"help": "Number of client replicas for parallel processing"},
)
dataset_config: str | None = field(
default=None,
metadata={"help": "Dataset config to use"},
)
|