AI Toolkit LoRA 訓練指南

AI Toolkit 推理一致性:讓結果匹配 Training Samples

使用與 AI Toolkit 訓練採樣/預覽相同的推理管線,讓訓練時看到的效果在推理時原樣復現。

使用 Ostris AI Toolkit 訓練擴散模型

如果你用 Ostris AI Toolkit 訓練了 LoRA(用於 FLUX / FLUX.2Wan 2.2/2.1Qwen ImageZ‑ImageLTX‑2SDXL 等),你大概率遇過這個問題:AI Toolkit 的訓練 Samples 很好看,但把同一 LoRA 拿去 Diffusers / ComfyUI / 其他推理堆疊跑,輸出就開始

這篇指南給你一個快速、可靠的方法,讓 推理結果盡量匹配 AI Toolkit 的訓練預覽,讓你「訓練時看到的」就是「上線時得到的」。


為什麼 AI Toolkit 的預覽經常不匹配推理

AI Toolkit 的 “Samples” 是用一套特定推理設定生成的:

  • 完全一致的基底模型變體
  • 模型家族特定的 scheduler / steps 語義
  • 模型家族特定的 LoRA 套用行為(adapter vs fuse/merge)
  • 解析度 snapping 規則(寬高取整到倍數)
  • 某些 pipeline 必須的輸入(例如 edit / I2V 的 control image

你的推理堆疊只要改了其中任何一項,即使 prompt + seed 相同,結果也可能漂。換句話說:想匹配 AI Toolkit 預覽,你需要對齊 整套推理 pipeline(而不只是幾個參數)。


為什麼 RunComfy 可以讓 LoRA 推理匹配訓練 Samples

RunComfy 會按基底模型運行一套 與 AI Toolkit 訓練預覽一致的 Diffusers 推理 pipeline。然後它會讀取你的 Training config file(YAML),鎖定同一基底模型變體與推理設定,從而讓 Run LoRA inference 更接近 1:1 的訓練 Sample 一致性。由於推理在 託管雲執行環境中進行,你也能避免 CUDA/PyTorch/Diffusers 版本差異帶來的「隱性漂移」。

下面是我們做的 parity 對比示例(AI Toolkit training samples vs Run LoRA inference,使用相同設定):

AI Toolkit training sample RunComfy inference (Playground/API)
AI Toolkit training sample — set 1
Run LoRA inference result — set 1
AI Toolkit training sample — set 2
Run LoRA inference result — set 2
AI Toolkit training sample — set 3
Run LoRA inference result — set 3

Step-by-step: Import → Run LoRA → Inference (Playground + API)

只需要幾分鐘,你就能把整個流程 end‑to‑end 跑通,並獲得與 AI Toolkit training samples 更一致的 LoRA 推理結果。

如果你已經 使用 RunComfy 的 AI Toolkit 訓練過,那麼訓練結束後 LoRA 會自動出現在 LoRA Assets,你可以直接跳到 Step 3(Run LoRA)。入口: AI Toolkit on RunComfy

Step 0 — 從 AI Toolkit 訓練任務準備兩個檔案

通常需要:

1) LoRA weights*.safetensors

2) AI Toolkit 訓練任務的 Training config file(YAML)(常見為 config.yml*.yaml

What is the Config File (YAML)?

在 AI Toolkit 裡打開你的 Training Job,點擊頂部 Config File,即可看到本次訓練用的完整配置。把內容全部複製出來,保存為本地 .yaml 檔案,再上傳到這裡。

AI Toolkit training config file (YAML)

為什麼配置檔很關鍵:它能讓 RunComfy 對齊生成 AI Toolkit samples 所用的 完全一致的基底模型與推理設定


Step 1 — 把 AI Toolkit LoRA 匯入 RunComfy

路徑:TrainerLoRA AssetsImport LoRA

上傳:

  • 你的 *.safetensors LoRA weights
  • 你的 training config file(YAML)(推薦)

如果你沒有配置檔,也可以透過手動選擇 Base Model 來匯入,但若推理預設值不同,預覽一致性可能會變差。

RunComfy Trainer — Import a LoRA trained with AI Toolkit


Step 2 — 確認 LoRA 出現在 LoRA Assets

匯入後(或雲訓練結束後),你的 LoRA 會出現在 LoRA Assets 清單裡。

從這裡你可以點擊 Run(Run LoRA)立刻開始推理(Playground + API)。

RunComFy Trainer — LoRA Assets list


Step 3 — 立即運行 LoRA 推理

LoRA Assets 裡找到你的 LoRA,點擊 Run

這會啟動 Run LoRA:按需推理,使用與你訓練一致的基底模型,並讀取 training YAML 中的 AI Toolkit pipeline 定義,因此不需要手動重搭就能達到 training‑preview parity。

你可以直接在 Playground 裡出圖,也可以用同一配置走 API

RunComFy Trainer — LoRA Assets list


Step 4 — 在 Playground 裡復現訓練 Samples

點擊 Run 後,你會直接進入 Run LoRA Playground

在這裡你可以在上線前驗證 訓練–推理一致性

  • 使用與訓練 samples 相同的設定(prompt、seed、解析度、steps、guidance、LoRA scale)。
  • 如果結果 高度接近 AI Toolkit training samples,表示你已達成 parity。
  • 如果出現 漂移,請跳到下面的 Quick mismatch checklist,逐項核對基底模型與設定。

RunComFy Trainer — LoRA Assets list


Step 5 — 在生產環境使用 API(非同步推理)

Run LoRA 中打開 API 分頁。該 API 是非同步的:

  • 提交推理請求
  • 監控狀態
  • 取得結果

RunComFy Trainer — LoRA Assets list

從面板複製精確的 URL 和請求結構(以及請求 schema 的連結)。

示例(僅示意 — 請使用你自己的 model_id、LoRA 路徑和 API key):

curl --request POST \
  --url "https://model-api.runcomfy.net/v1/models/<MODEL_ID>" \
  --header "Authorization: Bearer <YOUR_API_KEY>" \
  --header "Content-Type: application/json" \
  --data '{
    "prompt": "a studio portrait photo, cinematic lighting",
    "lora": {
      "path": "<YOUR_LORA_NAME_OR_URL>"
    }
  }'

API docs: RunComfy Model API(另見 LoRA inputs (Trainer)


Quick mismatch checklist(快速漂移檢查)

當推理結果不匹配訓練 samples 時,優先檢查:

1) 完全一致的基底模型(repo + variant)

2) 寬/高經過 snapping 後是否與訓練一致(對齊模型 divisor)

3) Steps + guidance + scheduler 語義是否一致

4) LoRA application mode(adapter vs fuse/merge)

5) edit / I2V:是否提供正確的 control image inputs

6) 執行環境漂移(Diffusers / ComfyUI 版本差異)


開源參考實作

想在 ComfyUI 裡推理,並盡量讓結果與 AI Toolkit 的 training samples / previews 保持一致?

見: AI Toolkit LoRA in ComfyUI: Parity Workflows

如果你想審計或自建推理邏輯:Open-source AI Toolkit inference coderuncomfy-com/ai-toolkit-inference


FAQ

匯入時一定需要 AI Toolkit 的 training config file(YAML)嗎?

強烈建議。沒有 training config file,你仍然可以手動選擇 base model 匯入,但會失去模型家族推理預設值的自動匹配。

我能匯入不是在 RunComfy 訓練的 LoRA 嗎?

可以。只要是用 AI Toolkit 訓練的,匯入 *.safetensors 與 training config file(YAML),然後按同樣方式(Run LoRA)推理即可。

這裡的 “Run LoRA” 是什麼意思?

Run LoRA 是按需推理(Playground + API):在不部署專用 endpoint 的情況下,把某個 LoRA 跑在它的 base model 上。按請求計費。

準備好開始訓練了嗎?