Community画像github.com

wshobson/vision-sft

視覚言語モデル(VLM)を教師あり学習で画像+テキストデータによりファインチューニングします。VLMを特定の視覚領域やタスクに適応させる際、凍結された視覚タワーのLoRAを設定する際、または学習が進まないVLMファインチューンをデバッグする際に使用します。

vision-sft とは?

このスキルは、画像+テキスト形式の教師ありデータを用いて視覚言語モデル(VLM)をファインチューニングするための専門的なレシピを提供します。主な用途は、VLMを特定の視覚領域やタスクに適応させること、凍結された視覚タワーに対するLoRA設定、学習が収束しないVLMファインチューンのデバッグです。対応プラットフォームはClaude Code、Cursor、CodexなどのAIエージェント向けツールで、`llm-finetuning-training-engineer`スキルと連携して実行可能なスクリプトを生成します。標準的なレシピでは視覚タワーとプロジェクタを凍結し、LLM部分のみにLoRA(rank 8-16、alpha 16-32)を適用します。視覚的なドメインシフトがある場合のみ、最後の6層のViT層をアンフリーズすることを推奨しますが、その際は学習率をLLMより5-10倍低く設定します。スキルは、画像とテキストのプレースホルダ不一致や解像度バジェットの不適切設定という2つの「サイレントキラー」に特に注意を促し、正常な損失曲線だけに頼らず事前検証の重要性を強調しています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/wshobson/agents/tree/main/plugins/llm-finetuning/skills/vision-sft

Installed? Explore more 画像 skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Vision-Language SFT

このスキルは、finetuning-method-selection が既にこのルートに振り分けたことを前提としています。データの形状は画像+テキストのデモンストレーションであり、嗜好ペアや検証可能な報酬信号ではなく、ベースモデルはテキスト専用ではなく視覚言語モデルです。lora-qlora-recipes はテキスト専用のLoRA/QLoRAレシピをカバーしており、このスキルは視覚タワーとプロジェクタ向けに特化しています。LoRAの基礎(ランク、アルファ、ターゲットモジュール)がまだ十分でない場合は、先にそのスキルを読んでください。

入力: 画像+テキストデータセットと、モデルカタログから既に選択されたVLMベースモデル。 出力形式: 検証済みのアダプタ設定 — どのコンポーネントを凍結するか、LoRAターゲットモジュール、min_pixels/max_pixels バジェット — これを llm-finetuning-training-engineer が実行可能スクリプトを生成する際に直接使用します。

クイックリファレンス

状況デフォルト設定
馴染みのある画像で行動を適応させる場合視覚タワー+プロジェクタを凍結、LoRA r=8–16、α=16–32
視覚的なドメインシフトがある場合最後の6層のViT層をアンフリーズ、視覚学習率はLLMの5–10倍低く
ターゲットランクでbf16に収まらない場合QLoRA — 視覚タワーのみ凍結
fast_inference=Truefinetune_vision_layers=False
損失は正常だが評価が改善しない場合まず以下の「2つのサイレントキラー」を確認

コンセンサスレシピ

視覚タワーとプロジェクタを凍結します。LoRAはLLMのみ、全線形層(テキスト専用SFTと同じアテンション+MLPターゲットリスト — lora-qlora-recipesを参照)に、r=8–16、α=16–32 で適用します。これは、VLMの見え方を乱さずに行動を適応させるための確立されたデフォルトです。

  • 視覚タワーとプロジェクタはデフォルトで凍結されます。 これらは既に一般的な視覚表現をエンコードしており、再訓練はほとんどのタスクでめったに必要なく、能力を追加せずにリスクを増やすだけです。
  • LoRAランクはテキスト専用の一般的なデフォルトよりも低く設定します(ここではr=8–16、テキスト専用SFTではr=16–32)。これは、LLMのみのアダプタが行動を適応させるのであって、新しい視覚知識を注入するわけではないからです。
  • QLoRAは視覚タワーが凍結されている場合のみ許可されます。 ベースを量子化しながら視覚層をアンフリーズして訓練することはサポートされておらず、不安定です — これは調整可能な設定ではなく、厳格なペアリングルールとして扱ってください。視覚タワーをアンフリーズする必要がある場合は、QLoRAをやめてbf16 LoRAを使用してください。
# タワー+プロジェクタを凍結;LoRAはLLMのみ
for name, param in model.named_parameters():
    if "vision_tower" in name or "projector" in name:
        param.requires_grad = False

target_modules = [
    "q_proj", "k_proj", "v_proj", "o_proj",
    "gate_proj", "up_proj", "down_proj",
]  # LLMのみ、全線形 — r=8-16, alpha=16-32

アンフリーズするタイミング

視覚層のアンフリーズは意図的なエスカレーションであり、デフォルトの判断ではありません — ドメインシフトがテキストではなく視覚的である場合にのみ行ってください。

  • 視覚的なドメインシフトがある場合のみアンフリーズします。 タスクが、タワーが既に理解している画像(グラフ、日常の写真)で新しい行動を教えることであれば、上記の凍結タワーレシピで十分です。視覚ドメインそのものがタワーにとって馴染みがない場合(衛星画像、医療スキャン、密度の高い技術図面など)で、凍結タワーレシピが頭打ちになった場合にアンフリーズします。
  • 最後の6層のViT層がスイートスポットです。 最終6層の視覚トランスフォーマー層(タワー全体ではない)をアンフリーズすると、凍結ベースラインと比較して DocVQAで+1.7ポイント、訓練コストは約1.75倍 という結果が測定されています。6層を支払う価値のある上限として扱ってください。それ以上進むと、計算コストがかかるだけで、同等の結果は得られません。
  • アンフリーズ時は、視覚学習率をLLM学習率より5~10倍低く設定する必要があります。 視覚タワーの事前学習済み表現はLLMのアダプタよりも壊れやすく、両方に同じ学習率を適用すると、LLMアダプタが補償するよりも早く視覚表現が上書きされるリスクがあります。
  • パッチ埋め込み層への高いLoRAランクはNaNを引き起こすリスクがあります。 パッチ埋め込みがアンフリーズされたセットに含まれる場合、ランクを低く保ち、初期ステップの損失を注意深く監視してください — VLMでLoRAを適用するのに最も脆弱な場所の一つです。

2つのサイレントキラー

どちらも、エラーなしで訓練が行われるが学習は進まないという実行を引き起こします。損失曲線は正常に見え、モデルは改善せず、例外もスローされません — どちらも訓練ログがきれいなだけでは不十分で、明示的な訓練前チェックが必要です。

  • 画像タグ/カウントの不一致。 テンプレート化されたテキスト内のすべての画像プレースホルダートークンは、実際にコレーターに渡されるメディアアイテムと1対1でマッピングされる必要があります。不一致(プレースホルダーが1つあるが画像が0または2つ添付されている、または画像があるがプレースホルダーがない)は、ほとんどのコレーターでエラーになりません — 画像とテキストを静かに誤整列させ、モデルは「訓練されるが何も学習しません」。訓練を開始する前に、すべての例で、サンプルだけでなく、プレースホルダーとメディアの1対1マッピングを検証してください。完全な検証チェックリストの詳細:references/collators-and-pitfalls.md。
  • min_pixels/max_pixels 解像度バジェット。 このペアは、VLM SFTにおける品質とメモリにとって最も重要なハイパーパラメータです — ランク、アルファ、学習率よりも重要です。低すぎると、タスクに必要な解像度よりも画像が静かにダウンサンプリングされます(小さい文書のテキストが読めなくなるが、訓練は「成功」しているように見える);高すぎると、アクティベーションメモリのバジェットを超えるか、安定して訓練するにはバッチサイズが小さくなりすぎます。フレームワークのデフォルトに任せずに、データセットごとに意図的に設定してください。

Unsloth固有の設定

  • UnslothVisionDataCollator はUnslothがVLM SFTに期待するコレーターです。references/collators-and-pitfalls.md で説明されている画像タグの整列とアーキテクチャごとのプロセッサ契約を処理します。VLMデータにテキスト専用のコレーターを代用しないでください。
  • finetune_vision_layers=False は fast_inference=True の場合に必須です。 vLLMは視覚層にLoRAアダプタを提供できないため、高速推論設定で視覚層をアンフリーズすると、訓練が成功してもサービング時に失敗します。レシピが最後の6層のViT層のアンフリーズを要求する場合(上記「アンフリーズするタイミング」を参照)、その実行では高速推論は選択肢から外れます — どちらか一方を選び、両方は選ばないでください。

モデルの選択

ベースVLMの選択は、このスキルの範囲外です — それは finetuning-method-selection の references/model-catalog.md にあるモデルカタログという一箇所に存在します。このスキルとそのリファレンスは、アーキテクチャファミリーごとのレシピのみを説明し、決してあるモデルを別のモデルより推奨することはありません。

VLM強化学習(VLM-GRPO)は、このプラグインではリファレンスのみです — VLM-RLに固有の断片化されたツールと報酬ハッキングの障害モードは grpo-rlvr-training でカバーされており、ここではありません。このスキルの範囲は教師ありファインチューニングで終わります。

障害モード

上記のすべてのセクションに共通する繰り返しの間違いは、きれいな損失曲線を実行が健全である証拠として扱うことです。正常に見える曲線は、動作中の実行とどちらかのサイレントキラーの両方と一致します。なぜなら、モデルはどちらにしても何かに対して訓練されるからです — キラーが存在する場合は整列した画像テキスト信号ではありません。正常な損失曲線の隣に平坦な評価スコアがある場合は、ハイパーパラメータに触れる前に references/collators-and-pitfalls.md のチェックリストを再実行してください。

リファレンス

  • references/collators-and-pitfalls.md — アーキテクチャごとのコレーター表、画像プレースホルダーを含むデータセット形式の例、訓練前検証チェックリスト、および高度なパターンとしての2段階プロジェクタ整列レシピ。

関連スキル: finetuning-method-selection がここにルーティングします;lora-qlora-recipes がこのスキルが特化するテキスト専用LoRAの基礎をカバーします;grpo-rlvr-training がVLM-RLをカバーします(リファレンスのみ);dataset-curation がこのスキルがカバーしない画像+テキストデータセットの準備をカバーします。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

wshobson/accessibility-compliance

Implement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.

wshobson/airflow-dag-patterns

Build production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.

wshobson/angular-migration

Migrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.

wshobson/anti-reversing-techniques

Understand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.

wshobson/api-design-principles

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

wshobson/architecture-decision-records

Write and maintain Architecture Decision Records (ADRs) following best practices for technical decision documentation. Use when documenting significant technical decisions, reviewing past architectural choices, or establishing decision processes.

wshobson/architecture-patterns

Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.

wshobson/async-python-patterns

Master Python asyncio, concurrent programming, and async/await patterns for high-performance applications. Use when building async APIs, concurrent systems, or I/O-bound applications requiring non-blocking operations.

wshobson/attack-tree-construction

Build comprehensive attack trees to visualize threat paths. Use when mapping attack scenarios, identifying defense gaps, or communicating security risks to stakeholders.

wshobson/auth-implementation-patterns

Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.

wshobson/avoid-ai-writing

Audit and rewrite prose so it stops reading as machine-generated. Use this skill when asked to remove AI-isms, clean up AI writing, edit a draft for AI tells, audit a README, changelog, release note, PR description, or blog post for machine-sounding prose, or make text sound less like AI. Supports a detect-only mode, a rewrite mode, and an edit-in-place mode, with optional voice and context profiles.

wshobson/backtesting-frameworks

Build robust backtesting systems for trading strategies with proper handling of look-ahead bias, survivorship bias, and transaction costs. Use when developing trading algorithms, validating strategies, or building backtesting infrastructure.

wshobson/bash-defensive-patterns

Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.

wshobson/bats-testing-patterns

Master Bash Automated Testing System (Bats) for comprehensive shell script testing. Use when writing tests for shell scripts, CI/CD pipelines, or requiring test-driven development of shell utilities.

wshobson/bazel-build-optimization

Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.

wshobson/before-you-build

Pre-build product and feature risk review for founders, product managers, and AI-assisted builders. Use this skill when the user is about to build a landing page, MVP, SaaS product, internal tool, agent workflow, or major feature and needs to check demand, positioning, monetization, retention, trust, distribution, and adoption risk before implementation starts.

wshobson/billing-automation

Build automated billing systems for recurring payments, invoicing, subscription lifecycle, and dunning management. Use when implementing subscription billing, automating invoicing, or managing recurring payment systems.

wshobson/binary-analysis-patterns

Master binary analysis patterns including disassembly, decompilation, control flow analysis, and code pattern recognition. Use when analyzing executables, understanding compiled code, or performing static analysis on binaries.

wshobson/block-no-verify-hook

Configure a PreToolUse hook to prevent AI agents from skipping git pre-commit hooks with --no-verify and other bypass flags. Use when setting up Claude Code projects that enforce commit quality gates.

wshobson/brand-landingpage

Brand-first landing page designer — runs a brand-identity interview (colors, typography, shape language), then generates and iterates on a polished landing page via Stitch with deployment-ready HTML. Use when the user asks to create, design, or build a landing page, homepage, or marketing page and has no established visual direction. Skip when they have a design mockup, need a dashboard or app UI, are working at component level, building a multi-page app, or restyling with known design tokens — use frontend-design instead.

関連スキル