/fine_tuning
这是仅限企业版使用的端点 在此开始使用企业版
功能 | 支持 | 备注 |
---|---|---|
支持的提供商 | OpenAI、Azure OpenAI、Vertex AI | - |
成本跟踪 | 🟡 | 如果您需要此功能,请告知我们 |
日志记录 | ✅ | 适用于所有日志集成 |
将 finetune_settings
和 files_settings
添加到您的 litellm config.yaml 中,即可使用微调端点。
finetune_settings
和 files_settings
的 config.yaml 示例
model_list:
- model_name: gpt-4
litellm_params:
model: openai/fake
api_key: fake-key
api_base: https://exampleopenaiendpoint-production.up.railway.app/
# For /fine_tuning/jobs endpoints
finetune_settings:
- custom_llm_provider: azure
api_base: https://exampleopenaiendpoint-production.up.railway.app
api_key: os.environ/AZURE_API_KEY
api_version: "2023-03-15-preview"
- custom_llm_provider: openai
api_key: os.environ/OPENAI_API_KEY
- custom_llm_provider: "vertex_ai"
vertex_project: "adroit-crow-413218"
vertex_location: "us-central1"
vertex_credentials: "/Users/ishaanjaffer/Downloads/adroit-crow-413218-a956eef1a2a8.json"
# for /files endpoints
files_settings:
- custom_llm_provider: azure
api_base: https://exampleopenaiendpoint-production.up.railway.app
api_key: fake-key
api_version: "2023-03-15-preview"
- custom_llm_provider: openai
api_key: os.environ/OPENAI_API_KEY
创建用于微调的文件
- OpenAI Python SDK
- curl
client = AsyncOpenAI(api_key="sk-1234", base_url="http://0.0.0.0:4000") # base_url is your litellm proxy url
file_name = "openai_batch_completions.jsonl"
response = await client.files.create(
extra_body={"custom_llm_provider": "azure"}, # tell litellm proxy which provider to use
file=open(file_name, "rb"),
purpose="fine-tune",
)
curl http://localhost:4000/v1/files \
-H "Authorization: Bearer sk-1234" \
-F purpose="batch" \
-F custom_llm_provider="azure"\
-F file="@mydata.jsonl"
创建微调作业
- Azure OpenAI
- OpenAI Python SDK
- curl
ft_job = await client.fine_tuning.jobs.create(
model="gpt-35-turbo-1106", # Azure OpenAI model you want to fine-tune
training_file="file-abc123", # file_id from create file response
extra_body={"custom_llm_provider": "azure"}, # tell litellm proxy which provider to use
)
curl http://localhost:4000/v1/fine_tuning/jobs \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-1234" \
-d '{
"custom_llm_provider": "azure",
"model": "gpt-35-turbo-1106",
"training_file": "file-abc123"
}'
请求体
- 支持的参数
- 请求体示例
model
类型: 字符串
必需: 是
用于微调的模型名称custom_llm_provider
类型:
Literal["azure", "openai", "vertex_ai"]
必需: 是 用于微调的模型名称。您可以选择一个支持的提供商
training_file
类型: 字符串
必需: 是
包含训练数据的已上传文件的 ID。- 有关如何上传文件,请参见上传文件。
- 您的数据集必须格式化为 JSONL 文件。
hyperparameters
类型: 对象
必需: 否
用于微调作业的超参数。支持的
hyperparameters
batch_size
类型: 字符串或整数
必需: 否
每个批次中的示例数量。较大的批次大小意味着模型参数更新频率较低,但方差也较低。learning_rate_multiplier
类型: 字符串或数字
必需: 否
学习率的缩放因子。较小的学习率可能有助于避免过拟合。n_epochs
类型: 字符串或整数
必需: 否
训练模型的 epoch 数量。一个 epoch 指的是对整个训练数据集进行一次完整的循环。suffix
类型: 字符串或 null
必需: 否
默认值: null
一个最多 18 个字符的字符串,将被添加到您的微调模型名称中。例如:suffix
为 "custom-model-name" 将生成类似ft:gpt-4o-mini:openai:custom-model-name:7p4lURel
的模型名称。validation_file
类型: 字符串或 null
必需: 否
包含验证数据的已上传文件的 ID。- 如果提供,此数据将用于在微调期间定期生成验证指标。
integrations
类型: 数组或 null
必需: 否
为您的微调作业启用的集成列表。seed
类型: 整数或 null
必需: 否
种子控制作业的可重现性。传入相同的种子和作业参数应产生相同的结果,但在极少数情况下可能有所不同。如果未指定种子,将为您生成一个。
{
"model": "gpt-4o-mini",
"training_file": "file-abcde12345",
"hyperparameters": {
"batch_size": 4,
"learning_rate_multiplier": 0.1,
"n_epochs": 3
},
"suffix": "custom-model-v1",
"validation_file": "file-fghij67890",
"seed": 42
}
取消微调作业
- OpenAI Python SDK
- curl
# cancel specific fine tuning job
cancel_ft_job = await client.fine_tuning.jobs.cancel(
fine_tuning_job_id="123", # fine tuning job id
extra_body={"custom_llm_provider": "azure"}, # tell litellm proxy which provider to use
)
print("response from cancel ft job={}".format(cancel_ft_job))
curl -X POST http://localhost:4000/v1/fine_tuning/jobs/ftjob-abc123/cancel \
-H "Authorization: Bearer sk-1234" \
-H "Content-Type: application/json" \
-d '{"custom_llm_provider": "azure"}'
列出微调作业
- OpenAI Python SDK
- curl
list_ft_jobs = await client.fine_tuning.jobs.list(
extra_query={"custom_llm_provider": "azure"} # tell litellm proxy which provider to use
)
print("list of ft jobs={}".format(list_ft_jobs))
curl -X GET 'http://localhost:4000/v1/fine_tuning/jobs?custom_llm_provider=azure' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-1234"