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)
相关推荐
lxmyzzs2 小时前
【图像算法 - 08】基于 YOLO11 的抽烟检测系统(包含环境搭建 + 数据集处理 + 模型训练 + 效果对比 + 调参技巧)
人工智能·yolo·目标检测·计算机视觉
霖002 小时前
ZYNQ实现FFT信号处理项目
人工智能·经验分享·神经网络·机器学习·fpga开发·信号处理
GIS数据转换器2 小时前
AI 技术在智慧城市建设中的融合应用
大数据·人工智能·机器学习·计算机视觉·系统架构·智慧城市
竹子_232 小时前
《零基础入门AI:传统机器学习进阶(从拟合概念到K-Means算法)》
人工智能·算法·机器学习
上海云盾-高防顾问2 小时前
DDoS 防护的未来趋势:AI 如何重塑安全行业?
人工智能·安全·ddos
Godspeed Zhao2 小时前
自动驾驶中的传感器技术17——Camera(8)
人工智能·机器学习·自动驾驶·camera·cis
摆烂工程师3 小时前
GPT-5 即将凌晨1点进行发布,免费用户可以使用 GPT-5
前端·人工智能·程序员
今天也不想动3 小时前
文献解读-生境分析亚区域选择+2D_DL+3D_DL-局部晚期食管鳞状细胞癌新辅助化疗免疫治疗反应预测
人工智能·影像组学·生境分析
shao9185164 小时前
Gradio全解10——Streaming:流式传输的多模态应用(3)——HF Inference:在服务器运行推理
人工智能·推理·hf inference·inferenceclient·text_to_image·chat_completion
FIT2CLOUD飞致云4 小时前
高级编排应用新增会话变量,支持对话用户扫码登录,支持工作空间资源统一管理,MaxKB v2.0.2版本发布
人工智能·开源