跳到主要内容

/fine_tuning

信息

这是仅限企业版使用的端点 在此开始使用企业版

功能支持备注
支持的提供商OpenAI、Azure OpenAI、Vertex AI-
成本跟踪🟡如果您需要此功能,请告知我们
日志记录适用于所有日志集成

finetune_settingsfiles_settings 添加到您的 litellm config.yaml 中,即可使用微调端点。

finetune_settingsfiles_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

创建用于微调的文件

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",
)

创建微调作业

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
)

请求体

  • 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
    必需:
    种子控制作业的可重现性。传入相同的种子和作业参数应产生相同的结果,但在极少数情况下可能有所不同。如果未指定种子,将为您生成一个。

取消微调作业

# 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))

列出微调作业

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))

👉 代理 API 参考