跳到正文
cccskills
免费在 GitHub 公开

sft

Set up and run supervised fine-tuning (SFT) on instruction or chat datasets using the Tinker API. Use when the user wants to do instruction tuning, chat fine-tuning, or supervised learning.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md5.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Supervised Fine-Tuning (SFT)

Help the user set up and run supervised fine-tuning using the Tinker API.

Step 1: Understand the request

Ask the user (if not already specified):

  • Model: Which base model to fine-tune (e.g., meta-llama/Llama-3.1-8B, Qwen/Qwen3-8B). See docs/model-lineup.mdx for available models.
  • Dataset: What data to train on — built-in datasets (NoRobots, Tulu3) or custom JSONL file.
  • Goal: General instruction tuning, domain-specific fine-tuning, or chat quality improvement.

Step 2: Reference existing recipes

Read these files for patterns and conventions:

  • tinker_cookbook/recipes/sl_basic.py — Minimal SFT example
  • tinker_cookbook/recipes/chat_sl/train.py — Full-featured chat SFT with eval
  • tinker_cookbook/supervised/train.py — Core training loop
  • tinker_cookbook/supervised/data.py — Dataset construction helpers
  • docs/supervised-learning/sl-basic.mdx — Getting started guide
  • docs/supervised-learning/sl-hyperparams.mdx — Learning rate and batch size guidance

Step 3: Configure the training run

Key configuration decisions:

Renderer

Match renderer to model family using model_info.get_recommended_renderer_name(model_name). Never hardcode renderer names.

Learning Rate

  • Use hyperparam_utils.get_lr(model_name) for recommended LR
  • LoRA fine-tuning typically needs ~10x higher LR than full fine-tuning (e.g., 2e-4 for LoRA vs 2e-5 for full)

TrainOnWhat

  • TrainOnWhat.ALL_ASSISTANT_MESSAGES — Train on all assistant turns (most common)
  • TrainOnWhat.LAST_ASSISTANT_MESSAGE — Train only on final assistant response
  • TrainOnWhat.EVERYTHING — Train on entire conversation including user messages

Dataset

  • Built-in: NoRobotsBuilder, Tulu3Builder
  • Custom JSONL: Use FromConversationFileBuilder(common_config=..., file_path="path/to/data.jsonl")
  • Format: Same as tinker_cookbook/example_data/conversations.jsonl

Batch Size & Epochs

  • batch_size: Number of tokens per training batch (default: 128 for basic, scale up as needed)
  • num_epochs: Number of passes through the dataset
  • eval_every: Evaluate every N batches

Step 4: Write the training script

Follow the pattern from sl_basic.py:

import asyncio
import chz
import sys
from tinker_cookbook import cli_utils, model_info
from tinker_cookbook.supervised import train
from tinker_cookbook.renderers import TrainOnWhat
from tinker_cookbook.supervised.types import ChatDatasetBuilderCommonConfig

def build_config_blueprint() -> chz.Blueprint[train.Config]:
    model_name = "meta-llama/Llama-3.1-8B"
    renderer_name = model_info.get_recommended_renderer_name(model_name)
    common_config = ChatDatasetBuilderCommonConfig(
        model_name_for_tokenizer=model_name,
        renderer_name=renderer_name,
        max_length=32768,
        batch_size=128,
        train_on_what=TrainOnWhat.ALL_ASSISTANT_MESSAGES,
    )
    # Configure dataset builder here
    dataset = ...

    return chz.Blueprint(train.Config).apply({
        "log_path": "/tmp/tinker-examples/my_sft_run",
        "model_name": model_name,
        "renderer_name": renderer_name,
        "dataset_builder": dataset,
        "learning_rate": 2e-4,
        "lr_schedule": "linear",
        "num_epochs": 1,
        "eval_every": 8,
    })

def main(config: train.Config):
    cli_utils.check_log_dir(config.log_path, behavior_if_exists="ask")
    asyncio.run(train.main(config))

if __name__ == "__main__":
    blueprint = build_config_blueprint()
    blueprint.make_from_argv(sys.argv[1:])
    main(blueprint.make())

Step 5: Run and iterate

python -m tinker_cookbook.recipes.<recipe_name>

Override parameters from CLI: python -m tinker_cookbook.recipes.<recipe_name> learning_rate=1e-4 batch_size=256

Step 6: Add tests

If you created a new recipe, add a smoke test so CI catches regressions:

# tests/recipes/test_recipe_<name>.py
import pytest
from tests.helpers import run_recipe

@pytest.mark.integration
def test_<recipe_name>():
    run_recipe(
        "tinker_cookbook.recipes.<recipe_name>.train",
        ["behavior_if_log_dir_exists=delete", "batch_size=16"],
    )

run_recipe() automatically passes max_steps=2 to the recipe, so it runs 2 training steps and exits cleanly. Tests are auto-discovered by CI and run daily. For unit-testable components (dataset processing, custom logic), add *_test.py files next to the source code.

Step 7: Export weights (optional)

After training, export weights using the tinker_cookbook.weights API:

from tinker_cookbook import weights

adapter_dir = weights.download(tinker_path="tinker://run-id/sampler_weights/final", output_dir="./adapter")
weights.build_hf_model(base_model="meta-llama/Llama-3.1-8B", adapter_path=adapter_dir, output_path="./model")
weights.publish_to_hf_hub(model_path="./model", repo_id="user/my-finetuned-model")

Common pitfalls

  • Always use model_info.get_recommended_renderer_name() — never hardcode renderer
  • Use cli_utils.check_log_dir() to avoid clobbering previous runs
  • For custom datasets, ensure JSONL matches the conversation format in example_data/conversations.jsonl
  • LR too high causes instability; LR too low wastes compute

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Guide for checkpointing — saving, loading, and resuming training with CheckpointRecord. Use when the user asks about saving weights, resuming training, checkpoint management, or the checkpoint lifecycle.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

ci

免费

Guide for testing conventions and CI pipelines — unit tests, integration smoke tests, pytest markers, and GitHub Actions workflows. Use when the user asks about testing, CI, running tests, or adding tests for a recipe.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Guide for using completers — TokenCompleter and MessageCompleter for text generation during RL rollouts and evaluation. Use when the user asks about generating text, completing messages, or using completers in RL environments.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Guide for contributing to the tinker-cookbook repo — development setup, code style, type checking, PR process, and design conventions. Use when the user asks about how to contribute, set up the dev environment, code style, or project conventions.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

datasets

免费

Guide for dataset construction — SupervisedDatasetBuilder, RLDatasetBuilder, ChatDatasetBuilder, and custom dataset creation from JSONL, HuggingFace, or conversation data. Use when the user asks about datasets, data loading, data preparation, or custom data formats.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Set up and run knowledge distillation (on-policy, off-policy, or multi-teacher) from a teacher model to a student model using the Tinker API. Use when the user wants to distill knowledge, compress models, or train a student from a teacher.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

查看 uiuc-kang-lab 的全部技能

报告此技能的问题