Finetuning with Together AI — The Easiest SFT Tutorial

This streamlined tutorial guides you through the finetuning process with Together AI. While the official tutorial splits the process across different pages, this guide consolidates everything into a single, easy-to-follow resource.

Note:

  • All commands should be entered in the terminal.
  • The minimal training cost is $5, even with just one entry in the training data.

1. Authentication

Start by setting your Together AI API key:

复制代码
export TOGETHER_API_KEY= <your_api>

2. Prepare Your Dataset

Construct your dataset according to the required data format. You can use either Conversational Data or Instruction Data formats.

Conversational Data Example

复制代码
{
  "messages": [
    {"role": "system", "content": "This is a system prompt."},
    {"role": "user", "content": "Hello, how are you?"},
    {"role": "assistant", "content": "I'm doing well, thank you! How can I help you?"},
    {"role": "user", "content": "Can you explain machine learning?"},
    {"role": "assistant", "content": "Machine learning is..."}
  ]
}

Instruction Data Example

复制代码
{"prompt": "...", "completion": "..."}
{"prompt": "...", "completion": "..."}

3. Upload Your Dataset and Obtain File ID

Upload your dataset using the following command:

复制代码
together files upload <file_name>

Replace <file_name> with the name of your dataset file (e.g., dataset.jsonl).

Upon successful upload, you will receive a response similar to:

复制代码
{
    "id": "file-123456",
    "object": "file",
    "created_at": 1734574470,
    "purpose": "fine-tune",
    "filename": "filename.jsonl",
    "bytes": 0,
    "line_count": 0,
    "processed": false,
    "FileType": "jsonl"
}

Action: Note down the id (e.g., file-123456) for use in the next steps.

4. Select a Model to Fine-Tune

Fine-tuning ModelsA list of all the models available for fine-tuning.docs.together.ai

Use the name listed under the "Model String for API" column. For example: "meta-llama/Llama-3.3--70B-Instruct-Reference"

5. Create a Finetuning Task

Initiate the finetuning process with the following command:

复制代码
together fine-tuning create - training-file file-123456 - model meta-llama/Llama-3.3–70B-Instruct-Reference

Replace:

  • file-123456 with your actual file ID.
  • meta-llama/Llama-3.3--70B-Instruct-Reference with your chosen model string.

If the submission is successful, you will see a response similar to:

复制代码
Submitting a fine-tuning job with the following parameters:
FinetuneRequest(
    training_file='file-123456',
    validation_file='',
    model='meta-llama/Llama-3.3–70B-Instruct-Reference',
    n_epochs=1,
    learning_rate=1e-05,
    lr_scheduler=FinetuneLRScheduler(lr_scheduler_type='linear', lr_scheduler_args=FinetuneLinearLRSchedulerArgs(min_lr_ratio=0.0)),
    warmup_ratio=0.0,
    max_grad_norm=1.0,
    weight_decay=0.0,
    n_checkpoints=1,
    n_evals=0,
    batch_size=32,
    suffix=None,
    wandb_key=None,
    wandb_base_url=None,
    wandb_project_name=None,
    wandb_name=None,
    training_type=LoRATrainingType(type='Lora', lora_r=8, lora_alpha=16, lora_dropout=0.0, lora_trainable_modules='all-linear'),
    train_on_inputs='auto'
)
Successfully submitted a fine-tuning job ft-c1cce2b0-1a90-47e4-8e84-46f76d2c3dcb at 12/19/2024, 10:16:38

Action: Note down the fine-tuning job ID (e.g., ft-c1cce2b0-1a90-47e4-8e84-46f76d2c3dcb).

6. Monitor and Use Your Fine-Tuned Model

Once the finetuning job is complete, you can use your fine-tuned model as follows:

Example in Python

复制代码
from together import Together

client = Together()

response = client.chat.completions.create(
    model="check your model name in your together AI dashboard",
    messages=[{"role": "user", "content": "Could you give me a like?"}],
)
print(response.choices[0].message.content)
相关推荐
小天努力学java6 分钟前
AI赋能传统系统:Spring AI Alibaba如何用大模型重构机票预订系统?
人工智能·spring
Fuweizn24 分钟前
在工业生产中,物料搬运环节至关重要,搬运机器人开启新篇章
人工智能·智能机器人·复合机器人
AL.千灯学长2 小时前
DeepSeek接入Siri(已升级支持苹果手表)完整版硅基流动DeepSeek-R1部署
人工智能·gpt·ios·ai·苹果vision pro
LCG元2 小时前
大模型驱动的围术期质控系统全面解析与应用探索
人工智能
lihuayong3 小时前
计算机视觉:主流数据集整理
人工智能·计算机视觉·mnist数据集·coco数据集·图像数据集·cifar-10数据集·imagenet数据集
政安晨3 小时前
政安晨【零基础玩转各类开源AI项目】DeepSeek 多模态大模型Janus-Pro-7B,本地部署!支持图像识别和图像生成
人工智能·大模型·多模态·deepseek·janus-pro-7b
一ge科研小菜鸡3 小时前
DeepSeek 与后端开发:AI 赋能云端架构与智能化服务
人工智能·云原生
冰 河3 小时前
‌最新版DeepSeek保姆级安装教程:本地部署+避坑指南
人工智能·程序员·openai·deepseek·冰河大模型
维维180-3121-14553 小时前
AI赋能生态学暨“ChatGPT+”多技术融合在生态系统服务中的实践技术应用与论文撰写
人工智能·chatgpt
終不似少年遊*3 小时前
词向量与词嵌入
人工智能·深度学习·nlp·机器翻译·词嵌入