직접 선호 최적화
직접 선호 최적화
직접 선호 최적화(Direct Preference Optimization, DPO) 파인튜닝은 프롬프트와 응답 쌍을 기반으로 모델을 파인튜닝할 수 있게 합니다. 이 접근 방식은 모델이 더 주관적인 인간 선호에서 학습하여, 더 선호될 가능성이 높은 출력을 최적화할 수 있게 합니다. DPO는 현재 텍스트 입력과 출력만 지원합니다.
OpenAI는 파인튜닝 플랫폼을 정리하고 있습니다. 이제 새 사용자는 플랫폼에 접근할 수 없지만, 기존 파인튜닝 플랫폼 사용자는 향후 몇 달 동안 학습 작업을 만들 수 있습니다.
모든 파인튜닝 모델은 기본 모델이 폐지될 때까지 추론에 계속 사용할 수 있습니다. 전체 일정은 여기에서 확인할 수 있습니다.
출처: 문서
본문
| 작동 방식 | 가장 적합한 작업 | 함께 사용 |
|---|---|---|
| 프롬프트에 대한 정답과 오답 예시 응답을 모두 제공합니다. 정답 응답을 표시해 모델이 더 잘 수행하도록 돕습니다. | - 텍스트 요약, 올바른 것에 집중하기 - 올바른 톤과 스타일로 채팅 메시지 생성 |
gpt-4.1-2025-04-14gpt-4.1-mini-2025-04-14gpt-4.1-nano-2025-04-14 |
데이터 형식
데이터셋의 각 예시에는 다음이 포함되어야 합니다:
- 사용자 메시지 같은 프롬프트.
- 선호 출력(이상적인 assistant 응답).
- 비선호 출력(차선의 assistant 응답).
데이터는 JSONL 형식이어야 하며, 각 줄이 다음 구조의 예시 하나를 나타냅니다:
{
"input": {
"messages": [
{
"role": "user",
"content": "Hello, can you tell me how cold San Francisco is today?"
}
],
"tools": [],
"parallel_tool_calls": true
},
"preferred_output": [
{
"role": "assistant",
"content": "Today in San Francisco, it is not quite cold as expected. Morning clouds will give away to sunshine, with a high near 68°F (20°C) and a low around 57°F (14°C)."
}
],
"non_preferred_output": [
{
"role": "assistant",
"content": "It is not particularly cold in San Francisco today."
}
]
}
현재는 각 예시에 대해 한 턴 대화만 학습하며, 여기서 선호/비선호 메시지가 마지막 assistant 메시지여야 합니다.
DPO 파인튜닝 작업 만들기
학습 데이터를 업로드하고 DPO로 파인튜닝된 모델을 사용하는 것은 여기에 설명된 흐름과 동일합니다.
DPO 파인튜닝 작업을 만들려면 파인튜닝 작업 생성 엔드포인트의 method 필드를 사용하세요. 여기서 type과 관련 hyperparameters를 지정할 수 있습니다. DPO의 경우:
type매개변수를dpo로 설정하세요.- 선택적으로
hyperparameters속성에 구성하려는 옵션을 설정하세요.
beta 하이퍼파라미터는 DPO에서만 사용할 수 있는 새 옵션입니다. 0과 2 사이의 부동소수점 숫자로, 새 모델이 제공된 선호에 맞추는 것보다 기존 동작을 얼마나 엄격히 따를지 제어합니다. 높은 값은 더 보수적이고(기존 동작 선호), 낮은 값은 더 공격적입니다(새로 제공된 선호를 더 자주 선호).
이 값을 auto(기본값)로 설정해 플랫폼이 구성한 값을 사용할 수도 있습니다.
아래 예시는 OpenAI SDK를 사용해 DPO 파인튜닝 작업을 구성하는 방법을 보여줍니다.
DPO로 파인튜닝 작업 만들기
import OpenAI from "openai";
const openai = new OpenAI();
const job = await openai.fineTuning.jobs.create({
training_file: "file-all-about-the-weather",
model: "gpt-4o-2024-08-06",
method: {
type: "dpo",
dpo: {
hyperparameters: { beta: 0.1 },
},
},
});
from openai import OpenAI
client = OpenAI()
job = client.fine_tuning.jobs.create(
training_file="file-all-about-the-weather",
model="gpt-4o-2024-08-06",
method={
"type": "dpo",
"dpo": {
"hyperparameters": {"beta": 0.1},
},
},
)
package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
func main() {
client := openai.NewClient()
job, err := client.FineTuning.Jobs.New(context.Background(), openai.FineTuningJobNewParams{
TrainingFile: "file-all-about-the-weather",
Model: "gpt-4o-2024-08-06",
Method: openai.FineTuningJobNewParamsMethod{
Type: "dpo",
Dpo: openai.DpoMethodParam{Hyperparameters: openai.DpoHyperparameters{
Beta: openai.DpoHyperparametersBetaUnion{OfFloat: openai.Float(0.1)},
}},
},
})
if err != nil {
panic(err)
}
fmt.Println(job.ID)
}
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.finetuning.jobs.JobCreateParams;
import com.openai.models.finetuning.methods.DpoHyperparameters;
import com.openai.models.finetuning.methods.DpoMethod;
String fileId = "file-all-about-the-weather";
var job =
client
.fineTuning()
.jobs()
.create(
JobCreateParams.builder()
.model("gpt-4.1-mini-2025-04-14")
.trainingFile(fileId)
.method(
JobCreateParams.Method.builder()
.type(JobCreateParams.Method.Type.DPO)
.dpo(
DpoMethod.builder()
.hyperparameters(DpoHyperparameters.builder().beta(0.1).build())
.build())
.build())
.build());
System.out.println(job.id());
require "openai"
client = OpenAI::Client.new
job = client.fine_tuning.jobs.create(
model: "gpt-4.1-mini-2025-04-14",
training_file: "file-all-about-the-weather",
method_: {
type: :dpo,
dpo: { hyperparameters: { beta: 0.1 } }
}
)
puts(job.id)
SFT와 DPO 함께 사용하기
현재 OpenAI는 지도 파인튜닝(SFT)을 파인튜닝 작업의 기본 방법으로 제공합니다. 선호 응답(또는 그 일부)에 대해 SFT를 수행한 뒤 이후에 별도의 DPO 작업을 실행하면 모델 정렬과 성능을 크게 향상시킬 수 있습니다. 먼저 원하는 응답으로 모델을 파인튜닝하면 올바른 패턴을 더 잘 식별하여, DPO가 동작을 정제하기 위한 강력한 기반을 제공합니다.
권장 워크플로는 다음과 같습니다:
- 선호 응답의 일부로 기본 모델을 SFT로 파인튜닝하세요. 데이터 품질과 작업의 대표성을 보장하는 데 집중하세요.
- SFT 파인튜닝 모델을 시작점으로 사용하고, 선호 비교를 기반으로 모델을 조정하기 위해 DPO를 적용하세요.
안전 검사
프로덕션에 출시하기 전에 다음 안전 정보를 검토하고 따르세요.
안전성을 어떻게 평가하나요
파인튜닝 작업이 완료되면 결과 모델의 동작을 13개의 서로 다른 안전 범주에서 평가합니다. 각 범주는 AI 출력이 제대로 제어되지 않으면 피해를 일으킬 수 있는 중요한 영역을 나타냅니다.
| Name | Description |
|---|---|
| advice | Advice or guidance that violates our policies. |
| harassment/threatening | Harassment content that also includes violence or serious harm towards any target. |
| hate | Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. Hateful content aimed at non-protected groups (e.g., chess players) is harassment. |
| hate/threatening | Hateful content that also includes violence or serious harm towards the targeted group based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. |
| highly-sensitive | Highly sensitive data that violates our policies. |
| illicit | Content that gives advice or instruction on how to commit illicit acts. A phrase like "how to shoplift" would fit this category. |
| propaganda | Praise or assistance for ideology that violates our policies. |
| self-harm/instructions | Content that encourages performing acts of self-harm, such as suicide, cutting, and eating disorders, or that gives instructions or advice on how to commit such acts. |
| self-harm/intent | Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm, such as suicide, cutting, and eating disorders. |
| sensitive | Sensitive data that violates our policies. |
| sexual/minors | Sexual content that includes an individual who is under 18 years old. |
| sexual | Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services (excluding sex education and wellness). |
| violence | Content that depicts death, violence, or physical injury. |
각 범주에는 미리 정의된 통과 임계값이 있으며, 특정 범주에서 평가된 예시가 너무 많이 실패하면 OpenAI는 파인튜닝 모델의 배포를 차단합니다. 파인튜닝 모델이 안전 검사를 통과하지 못하면 OpenAI는 파인튜닝 작업에서 어떤 범주가 필요한 임계값을 충족하지 못하는지 설명하는 메시지를 보냅니다. 파인튜닝 작업의 moderation checks 섹션에서 결과를 볼 수 있습니다.
안전 검사 통과 방법
파인튜닝 작업 객체에서 실패한 안전 검사를 검토하는 것 외에도 파인튜닝 API events 엔드포인트를 조회해 어떤 범주가 실패했는지에 대한 세부 정보를 검색할 수 있습니다. 범주 결과와 집행에 대한 세부 정보는 moderation_checks 유형의 이벤트를 찾으세요. 이 정보는 재학습과 개선을 위해 어떤 범주를 대상으로 삼을지 좁히는 데 도움이 됩니다. 모델 스펙에는 추가 학습 데이터가 필요한 영역을 식별하는 데 도움이 되는 규칙과 예시가 있습니다.
이 평가들이 광범위한 안전 범주를 다루지만, 파인튜닝 모델이 사용 사례에 적합한지 직접 평가를 수행하세요.
다음 단계
이제 DPO의 기본을 알았으니 다른 방법도 살펴보세요.
- 지도 파인튜닝 — 샘플 입력에 올바른 출력을 제공해 모델을 파인튜닝합니다.
- 비전 파인튜닝 — 이미지 입력으로 컴퓨터 비전을 위한 파인튜닝을 배웁니다.
- 강화 파인튜닝 — 출력을 채점해 추론 모델을 파인튜닝합니다.