✨ [BETA] LiteLLM 관리형 파일 - Finetuning 함께 쓰기
✨ [BETA] LiteLLM 관리형 파일 - Finetuning 함께 쓰기
LiteLLM 관리형 파일(Managed Files)을 Finetuning API와 함께 사용해, OpenAI/Azure/Vertex AI에서 OpenAI 형식 그대로 파인튜닝 잡(job)을 만들고, 키/사용자/팀 단위로 파인튜닝 모델 접근을 제어할 수 있어요. 별도의 custom_llm_provider 파라미터가 필요 없어요.
이 기능은 프록시 전용이며 별도 Enterprise 라이선스가 필요 없는 Free Enterprise 기능이에요. 파일 id 저장에 Postgres DB가 필요해요.
출처: 문서
본문
무료 Enterprise 기능이에요.
litellm[proxy] 패키지나 아무 litellm 도커 이미지에서 사용할 수 있고, Enterprise 라이선스는 필요 없어요.
| 특성 | 값 | 설명 |
|---|---|---|
| Proxy | ✅ | |
| SDK | ❌ | 파일 id 저장에 postgres DB 필요 |
| Batch 공급자 전체에서 사용 | ✅ | |
| 지원 엔드포인트 | /fine_tuning/jobs |
개요 (Overview)
이 기능은 다음과 같이 사용해요:
- OpenAI/Azure/Vertex AI에서 OpenAI 형식으로 파인튜닝 잡 만들기 (추가
custom_llm_provider파라미터 불필요) - 키/사용자/팀 단위로 파인튜닝 모델 접근 제어하기 (채팅 완성 모델과 동일)
(프록시 관리자) 사용법
개발자에게 파인튜닝 모델 접근을 주는 방법이에요.
1. config.yaml 설정하기
supported_endpoints 목록에 /fine_tuning을 포함하세요. 개발자에게 이 모델이 /fine_tuning 엔드포인트를 지원한다는 걸 알려줘요.
model_list:
- model_name: "gpt-4.1-openai"
litellm_params:
model: gpt-4.1
api_key: os.environ/OPENAI_API_KEY
model_info:
supported_endpoints: ["/chat/completions", "/fine_tuning"]
2. 가상 키 만들기
curl -L -X POST 'https://{PROXY_BASE_URL}/key/generate' \
-H 'Authorization: Bearer ***' \
-H 'Content-Type: application/json' \
-d '{"models": ["gpt-4.1-openai"]}'
이제 가상 키로 파인튜닝 모델에 접근할 수 있어요 (개발자 플로우 참고).
(개발자) 사용법
LiteLLM 관리형 파일을 만들고 그 파일로 Finetuning CRUD 작업을 실행하는 방법이에요.
1. request.jsonl 만들기
{"messages": [{"role": "system", "content": "Clippy is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]}
{"messages": [{"role": "system", "content": "Clippy is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "Who wrote 'Romeo and Juliet'?"}, {"role": "assistant", "content": "Oh, just some guy named William Shakespeare. Ever heard of him?"}]}
2. 파일 업로드하기
target_model_names: "<model-name>"을 지정해 LiteLLM 관리형 파일과 요청 검증을 활성화해요.
model-name은 request.jsonl의 model-name과 같아야 해요.
from openai import OpenAI
client = OpenAI(
base_url="http://0.0.0.0:4000",
api_key="sk-<your-litellm-api-key>",
)
# Upload file
finetuning_input_file = client.files.create(
file=open("./request.jsonl", "rb"),
purpose="fine-tune",
extra_body={"target_model_names": "gpt-4.1-openai"}
)
print(finetuning_input_file)
파일은 어디에 쓰이나요?
모든 gpt-4.1-openai 디플로이먼트에 쓰여요. 이 덕분에 3단계에서 잡을 만들 때 모든 gpt-4.1-openai 디플로이먼트에 걸쳐 로드 밸런싱할 수 있어요. 잡이 만들어지고 나면 어떤 retrieve/list/cancel 작업도 그 디플로이먼트로 라우팅돼요.
3. 파인튜닝 잡 만들기
... # Step 2
file_id = finetuning_input_file.id
# Create Finetuning Job
ft_job = client.fine_tuning.jobs.create(
model="gpt-4.1-openai", # litellm public model name you want to finetune
training_file=file_id,
)
4. 파인튜닝 잡 조회하기
... # Step 3
response = client.fine_tuning.jobs.retrieve(ft_job.id)
print(response)
5. 파인튜닝 잡 목록 조회하기
...
client.fine_tuning.jobs.list(extra_body={"target_model_names": "gpt-4.1-openai"})
6. 파인튜닝 잡 취소하기
...
cancel_ft_job = client.fine_tuning.jobs.cancel(
fine_tuning_job_id=ft_job.id, # fine tuning job id
)
E2E 예제
from openai import OpenAI
client = OpenAI(
base_url="http://0.0.0.0:4000",
api_key="sk-...",
max_retries=0
)
# Upload file
finetuning_input_file = client.files.create(
file=open("./fine_tuning.jsonl", "rb"), # {"model": "azure-gpt-4o"} <-> {"model": "gpt-4o-my-special-deployment"}
purpose="fine-tune",
extra_body={"target_model_names": "gpt-4.1-openai"} # 👈 Tells litellm which regions/projects to write the file in.
)
print(finetuning_input_file) # file.id = "litellm_proxy/..." = {"model_name": {"deployment_id": "deployment_file_id"}}
file_id = finetuning_input_file.id
# # file_id = "bGl0ZWxs..."
# ## create fine-tuning job
ft_job = client.fine_tuning.jobs.create(
model="gpt-4.1-openai", # litellm model name you want to finetune
training_file=file_id,
)
print(f"ft_job: {ft_job}")
ft_job_id = ft_job.id
## cancel fine-tuning job
cancel_ft_job = client.fine_tuning.jobs.cancel(
fine_tuning_job_id=ft_job_id, # fine tuning job id
)
print("response from cancel ft job={}".format(cancel_ft_job))
# list fine-tuning jobs
list_ft_jobs = client.fine_tuning.jobs.list(
extra_query={"target_model_names": "gpt-4.1-openai"} # tell litellm proxy which provider to use
)
print("list of ft jobs={}".format(list_ft_jobs))
# get fine-tuning job
response = client.fine_tuning.jobs.retrieve(ft_job.id)
print(response)
FAQ
내 파일은 어디에 쓰이나요?
target_model_names이 지정되면 파일은 target_model_names과 일치하는 모든 디플로이먼트에 쓰여요.
추가 인프라는 필요 없어요.