sd-scripts
Use sd-scripts for Stable Diffusion and image-model training, dataset preparation, image generation, LoRA/model utilities, and troubleshooting across SD1/2, SDXL, SD3, FLUX, Lumina, HunyuanImage, and Anima workflows.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- sd-scripts
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use sd-scripts for Stable Diffusion and image-model training, dataset preparation, image generation, LoRA/model utilities, and troubleshooting across SD1/2, SDXL, SD3, FLUX, Lumina, HunyuanImage, and Anima workflows.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/developer-notes.md1.9 KB
- 参考文档references/repo-provenance.md2.0 KB
- 参考文档references/repo-routing-metadata.json502 B
- 参考文档references/troubleshooting.md3.3 KB
- 脚本scripts/check_sd_scripts_environment.py3.3 KB
03 SKILL.md 正文
sd-scripts
Use this skill when a user asks for help with sd-scripts, Kohya-style Stable Diffusion training scripts, LoRA/additional-network training, dataset TOML preparation, image generation, or model/LoRA utility workflows.
This skill is self-contained for planning, validation, troubleshooting, and command construction. Heavyweight sd-scripts training/generation/merge commands still require the user to run them in an sd-scripts installation that contains the project scripts, model files, and required ML dependencies.
Route by Task
- Use
sub-skills/data-preparationfor dataset TOML, DreamBooth/fine-tuning subsets, metadata JSON/JSONL, captions/tags, validation splits, bucketing, masked loss, inpainting data, and safe input validation. - Use
sub-skills/trainingfor LoRA/additional-network training, full fine-tuning, Textual Inversion, LECO, ControlNet-LLLite, validation loss, memory flags, optimizer choices, and model-family training commands. - Use
sub-skills/generationfor image generation, txt2img/img2img/inpainting inference, prompt-file validation, SDXL conditioning, LoRA application during inference, ControlNet/LLLite generation, and minimal inference scripts. - Use
sub-skills/model-utilitiesfor LoRA merge/extract/resize/convert planning, checkpoint or Diffusers conversion, safetensors metadata inspection, model-spec metadata, and safe handling of write-heavy utilities.
Before Suggesting a Runnable Command
- Confirm the user has an sd-scripts checkout or installed copy with the relevant root scripts available.
- Confirm Python dependencies are installed for the chosen workflow. Training and generation usually need PyTorch, Accelerate, Diffusers, Transformers, Safetensors, and model-family-specific optional packages.
- Confirm model files, text encoders, VAE/AE files, datasets, and output directories exist.
- Confirm whether execution is safe: full training, generation, caching, merging, extraction, and conversion can use GPU, download/load large weights, write large files, or run for a long time.
- Use bundled helper scripts for read-only validation or command construction before running heavyweight sd-scripts commands.
Installation and Environment Notes
sd-scripts is normally used from a cloned checkout with Python 3.10-3.12 and a workflow-specific PyTorch install. PyTorch is intentionally not pinned in the project requirements because CUDA, driver, GPU architecture, and platform determine the correct wheel.
A typical setup pattern is:
python -m venv venv
source venv/bin/activate
python -m pip install torch torchvision --index-url <matching-pytorch-wheel-index>
python -m pip install --upgrade -r requirements.txt
accelerate config
On Windows, use the venv activation command for PowerShell or cmd, and match the PyTorch CUDA wheel to the installed NVIDIA driver. For RTX 50-series or other new GPUs, use a recent PyTorch/CUDA wheel that supports the architecture.
Safe Bundled Helpers
scripts/check_sd_scripts_environment.pychecks the active Python for common dependencies and optional backend availability without importing or running training scripts.sub-skills/data-preparation/scripts/validate_dataset_inputs.pyvalidates dataset config and metadata files without loading models.sub-skills/training/scripts/build_training_command.pyprints command templates and never launches training.sub-skills/generation/scripts/validate_prompt_file.pyvalidates prompt files without loading models.sub-skills/model-utilities/scripts/inspect_safetensors_metadata.pyreads safetensors metadata without loading tensor payloads.
Shared References
references/repo-provenance.md: source snapshot used to generate this skill; read before deciding whether to refresh the skill.references/troubleshooting.md: cross-cutting install, dependency, hardware, and execution-safety failures.references/developer-notes.md: repo-specific conventions for coding agents and maintainers.
Safety Defaults
- Do not run training, generation, caching, merging, extraction, or conversion just because a command can be built.
- Prefer read-only validators,
--help, metadata inspection, and dry-run planning first. - Do not use the same file as both input and output for model utilities.
- Treat network downloads, model downloads, external credentials, and long GPU jobs as explicit user-approved operations.
- When dependencies are missing, explain the minimal dependency group for the requested workflow instead of installing every optional package.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).