Implementation:BerriAI Litellm Fine Tuning Types
| Knowledge Sources | Domains | Last Updated |
|---|---|---|
| BerriAI/litellm | Machine Learning, API Types, Data Validation | 2026-02-15 |
Overview
Concrete type definitions for fine-tuning job creation and hyperparameter configuration provided by LiteLLM.
Description
LiteLLM defines a set of Pydantic models that represent the data structures required to create fine-tuning jobs across multiple LLM providers. These types enforce schema validation at the Python level before any API call is made, ensuring that training file references, hyperparameter values, and provider-specific options conform to expected formats. The type hierarchy includes a base FineTuningJobCreate model aligned with the OpenAI API specification, a Hyperparameters model for training control parameters, and LiteLLMFineTuningJobCreate which extends the base with a custom_llm_provider field and permissive extra-field handling for cross-provider compatibility.
Usage
Import and use these types when:
- Constructing fine-tuning job request payloads programmatically.
- Validating hyperparameter values before submitting a job.
- Building provider-agnostic fine-tuning workflows that need to specify which LLM provider to target.
Code Reference
Source Location
- Hyperparameters:
litellm/types/llms/openai.py(lines 949-956) - FineTuningJobCreate:
litellm/types/llms/openai.py(lines 959-995) - LiteLLMFineTuningJobCreate:
litellm/types/llms/openai.py(lines 998-1003) - OpenAIFineTuningHyperparameters:
litellm/types/fine_tuning.py(lines 1-5)
Signature
class Hyperparameters(BaseModel):
batch_size: Optional[Union[str, int]] = None
learning_rate_multiplier: Optional[Union[str, float]] = None
n_epochs: Optional[Union[str, int]] = None
class FineTuningJobCreate(BaseModel):
model: str
training_file: str
hyperparameters: Optional[Hyperparameters] = None
suffix: Optional[str] = None
validation_file: Optional[str] = None
integrations: Optional[List[str]] = None
seed: Optional[int] = None
class LiteLLMFineTuningJobCreate(FineTuningJobCreate):
custom_llm_provider: Optional[Literal["openai", "azure", "vertex_ai"]] = None
model_config = {"extra": "allow"}
class OpenAIFineTuningHyperparameters(Hyperparameters):
model_config = {"extra": "allow"}
Import
from litellm.types.llms.openai import (
Hyperparameters,
FineTuningJobCreate,
LiteLLMFineTuningJobCreate,
)
from litellm.types.fine_tuning import OpenAIFineTuningHyperparameters
I/O Contract
Inputs (FineTuningJobCreate)
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | str |
Yes | The name of the base model to fine-tune (e.g., "gpt-3.5-turbo"). |
| training_file | str |
Yes | The ID of an uploaded file containing training data. |
| hyperparameters | Optional[Hyperparameters] |
No | Training hyperparameters (batch_size, learning_rate_multiplier, n_epochs). |
| suffix | Optional[str] |
No | A string of up to 18 characters appended to the fine-tuned model name. |
| validation_file | Optional[str] |
No | The ID of an uploaded file containing validation data. |
| integrations | Optional[List[str]] |
No | A list of integrations to enable for the fine-tuning job. |
| seed | Optional[int] |
No | Seed for reproducibility of the training job. |
Inputs (Hyperparameters)
| Parameter | Type | Required | Description |
|---|---|---|---|
| batch_size | Optional[Union[str, int]] |
No | Number of examples per batch, or "auto" for provider default. |
| learning_rate_multiplier | Optional[Union[str, float]] |
No | Scaling factor for the learning rate. |
| n_epochs | Optional[Union[str, int]] |
No | Number of training epochs, or "auto" for provider default. |
Outputs
These are Pydantic model instances used as input data containers. They do not directly produce API responses. They are serialized via model_dump(exclude_none=True) to produce dictionaries sent to provider APIs.
Usage Examples
Creating a basic fine-tuning job request
from litellm.types.llms.openai import (
FineTuningJobCreate,
Hyperparameters,
)
hyperparams = Hyperparameters(
batch_size="auto",
learning_rate_multiplier=0.1,
n_epochs=3,
)
job_request = FineTuningJobCreate(
model="gpt-3.5-turbo",
training_file="file-abc123",
hyperparameters=hyperparams,
suffix="my-custom-model",
validation_file="file-xyz789",
seed=42,
)
# Serialize for API submission
payload = job_request.model_dump(exclude_none=True)
Creating a provider-specific request
from litellm.types.llms.openai import LiteLLMFineTuningJobCreate
job_request = LiteLLMFineTuningJobCreate(
model="gpt-4o-mini-2024-07-18",
training_file="file-abc123",
custom_llm_provider="openai",
suffix="domain-expert",
)