diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 980fc67e0..0f0bbe83d 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -109,6 +109,14 @@ Use these repo-local skills for recurring SD.Next model integration work: File: `.github/skills/analyze-model/SKILL.md` Use when analyzing an external model URL to identify implementation style and estimate how difficult it is to port into SD.Next. +- `diffusers-code` + File: `.github/skills/diffusers-code/SKILL.md` + Use when creating or editing code that must comply with Hugging Face diffusers conventions, including preparing PR-ready changes targeting diffusers. + +- `reference-catalog` + File: `.github/skills/reference-catalog/SKILL.md` + Use when maintaining and validating model reference catalogs in `data/reference*.json`, including duplicate checks and thumbnail alignment. + - `fix-lint` File: `.github/skills/fix-lint/SKILL.md` Use when running the full lint workflow in required order (`pre-commit`, `eslint`, `ruff`, `pylint`) and fixing findings as needed, while ignoring lint issues explicitly marked with `TODO`. diff --git a/.github/skills/README.md b/.github/skills/README.md index a1f5bd0d3..d41712ee2 100644 --- a/.github/skills/README.md +++ b/.github/skills/README.md @@ -44,6 +44,14 @@ This folder contains repo-local Copilot skills for recurring SD.Next tasks. File: `analyze-model/SKILL.md` Use when analyzing an external model URL to classify implementation style and estimate SD.Next porting difficulty before coding. +- `diffusers-code` + File: `diffusers-code/SKILL.md` + Use when creating or editing code to be compliant with Hugging Face diffusers conventions, including PR-ready change preparation for diffusers. + +- `reference-catalog` + File: `reference-catalog/SKILL.md` + Use when maintaining and validating model reference catalogs in `data/reference*.json`, including duplicate checks and thumbnail alignment. + - `fix-lint` File: `fix-lint/SKILL.md` Use when running the full lint workflow in strict order and fixing issues as needed (`pre-commit`, `eslint`, `ruff`, `pylint`), while ignoring findings explicitly marked with `TODO`. diff --git a/.github/skills/diffusers-code/SKILL.md b/.github/skills/diffusers-code/SKILL.md new file mode 100644 index 000000000..41b93c6e2 --- /dev/null +++ b/.github/skills/diffusers-code/SKILL.md @@ -0,0 +1,162 @@ +--- +name: diffusers-code +description: "Create or edit code that is compliant with Hugging Face diffusers conventions, including models, pipelines, schedulers, tests, docs, and PR preparation targeting diffusers." +argument-hint: "Describe the target feature/bug, affected diffusers components, reference implementation links, and whether to prepare a PR-ready change" +--- + +# Diffusers Code Implementation And PR Skill + +Use this skill to implement, edit, review, and prepare pull-request-ready changes for the diffusers library with high compliance to diffusers conventions. + +## When To Use + +- Adding or editing diffusers models, pipelines, schedulers, or loaders +- Fixing bugs in inference code paths in diffusers-compatible style +- Refactoring existing diffusers code while preserving behavior +- Adding tests and docs for diffusers changes +- Preparing a PR that targets the diffusers repository + +## Primary Objectives + +1. Keep behavior explicit, minimal, and inference-focused. +2. Match existing diffusers architecture and code patterns. +3. Preserve numerical behavior unless a behavior change is explicitly required. +4. Produce change sets that are clean, reviewable, and PR-ready. + +## Hard Rules + +- Keep logic simple and readable in the main forward or call path. +- Avoid defensive, speculative, or fallback code paths unless required by existing diffusers APIs. +- Do not silently guess intent. For unsupported inputs, raise concise errors. +- Do not introduce new mandatory dependencies without maintainer agreement. +- If optional dependencies are needed, guard imports and provide proper dummy paths. +- Keep implementation torch.compile-friendly: avoid graph-break patterns in core model paths. +- Prefer native PyTorch tensor ops over external reshape helpers. + +## Code Structure Rules + +### Models + +- Use ModelMixin patterns and register constructor args with register_to_config. +- Keep layer invocation visible in forward, avoid hiding key module calls in extra helpers. +- Avoid hardcoded dtypes in forward paths; infer from tensors or module dtype. +- Follow existing model family patterns in src/diffusers/models/transformers. + +### Attention + +- Keep Attention class and processor together in the model file when following the standard diffusers pattern. +- Processor should perform the compute path and use dispatch_attention_fn pattern where applicable. +- Ensure processor registration and available processor declarations are complete. + +### Pipelines + +- Inherit from DiffusionPipeline. +- Decorate inference __call__ with @torch.no_grad(). +- Support generator for reproducibility when workflow requires it. +- Support output_type="latent" where latent output skip is expected. +- Use self.progress_bar(timesteps) in denoising loops. +- Do not build variant behavior by subclassing an unrelated existing pipeline class. + +### Schedulers + +- Use SchedulerMixin and ConfigMixin. +- Keep scheduler config semantics consistent with existing scheduler implementations. + +## Import And Registration Rules + +- Register new classes in relevant __init__.py lazy import structures. +- Ensure import structure entries are complete for all newly exposed objects. +- Validate that public imports from diffusers work after edits. + +## Copied Code Rules + +- Respect # Copied from linkage. +- Do not manually diverge copied blocks unless intentionally breaking linkage. +- Run make fix-copies after changes that touch copied sources or copied blocks. + +## Change Workflow + +1. Gather context +- Confirm target files, model family, and expected behavior. +- Obtain reference implementation and runnable inference flow when porting. + +2. Plan minimal scope +- Separate structural adaptation from algorithmic changes. +- Keep one coherent workflow per change set. + +3. Implement +- Edit only required files. +- Preserve naming, config shape, and API contracts unless change requires otherwise. + +4. Validate +- Run focused tests first, then broader checks as needed. +- Confirm imports and serialization/deserialization behavior. + +5. Polish +- Run make style. +- Run make fix-copies. +- Re-run impacted tests. + +## Testing Expectations + +Include tests for the exact behavior being changed: + +- Model tests for shape, dtype/device behavior, serialization, and config parity +- Pipeline tests for deterministic generation paths, outputs, and parameter handling +- Scheduler tests when scheduler logic or config behavior changes +- Regression tests for any bug fix + +When parity with a reference implementation is required: + +- Add component-level parity checks +- Add end-to-end parity checks +- Use explicit tolerances and deterministic seeds + +## PR Preparation For Diffusers + +When asked to prepare a PR targeting diffusers, produce: + +1. Scope statement +- One-paragraph summary: problem, solution, and non-goals. + +2. Change map +- File-by-file list describing what changed and why. + +3. Validation evidence +- Commands run, tests passed, and any skipped tests with reasons. + +4. Compatibility notes +- Backward compatibility, serialization impact, and optional dependency impact. + +5. Reviewer guidance +- Key files to review first, known tradeoffs, and follow-up items. + +### PR Quality Checklist + +- [ ] Minimal focused diff +- [ ] No unrelated refactors mixed with behavior changes +- [ ] New/updated tests for changed behavior +- [ ] Docs updated when public APIs or user-facing behavior changed +- [ ] make style completed +- [ ] make fix-copies completed +- [ ] Relevant test suites pass +- [ ] Commit messages are clear and scoped + +## Common Failure Modes To Prevent + +- Missing lazy import registration causes runtime ImportError +- New config params not registered, causing from_pretrained mismatch +- Pipeline __call__ missing @torch.no_grad(), causing memory growth +- Hardcoded dtype assumptions break mixed precision usage +- Hidden behavior changes introduced during structural refactor +- Unnecessary dependency additions for simple tensor reshaping + +## Output Contract For This Skill + +When using this skill, provide: + +- Implementation summary +- Exact files changed +- Validation summary with command outcomes +- Residual risks or deferred follow-ups +- PR-ready summary text when requested diff --git a/.github/skills/reference-catalog/SKILL.md b/.github/skills/reference-catalog/SKILL.md new file mode 100644 index 000000000..a4648d503 --- /dev/null +++ b/.github/skills/reference-catalog/SKILL.md @@ -0,0 +1,85 @@ +--- +name: reference-catalog +description: "Maintain and validate SD.Next model reference catalogs in data/reference*.json, including schema consistency, deduplication, link checks, and thumbnail alignment." +argument-hint: "Describe which catalog files to audit (or use all), whether to only report or also fix, and whether to include thumbnail sync in models/Reference" +--- + +# Reference Catalog Maintenance + +Use this skill to audit and update SD.Next model reference catalogs with minimal, safe, and deterministic edits. + +## When To Use + +- Adding or updating model entries in `data/reference*.json` +- Cleaning duplicates, stale entries, or inconsistent metadata +- Verifying category placement across `base/cloud/quant/distilled/nunchaku/community` +- Syncing catalog entries with thumbnail files in `models/Reference` + +## Catalog Files In Scope + +- `data/reference.json` (base) +- `data/reference-cloud.json` +- `data/reference-quant.json` +- `data/reference-distilled.json` +- `data/reference-nunchaku.json` +- `data/reference-community.json` + +## Core Rules + +- Do not move entries between categories unless explicitly requested or strongly evidenced. +- Keep changes targeted to only affected records. +- Preserve existing field names and conventions used by neighboring entries. +- Prefer deterministic normalization (stable key order, consistent value style). +- Do not overwrite real thumbnails with placeholders. + +## Validation Checklist + +1. Structural validity +- Confirm JSON parses cleanly. +- Ensure top-level structure matches existing catalog conventions. + +2. Entry integrity +- Required identifiers exist and are non-empty. +- URLs/repo references are syntactically valid. +- No malformed numeric/string fields compared with peer entries. + +3. Cross-catalog consistency +- Detect likely duplicates across `reference*.json` files. +- Flag conflicting metadata for the same model key/name. +- Report category conflicts; only auto-fix when rules are explicit. + +4. Thumbnail alignment +- Check expected thumbnail presence under `models/Reference`. +- If missing and requested, create zero-byte placeholder only. +- Never replace existing non-empty image assets with placeholders. + +5. Deterministic formatting +- Keep formatting style consistent with nearby file conventions. +- Avoid broad reformatting unrelated to edited records. + +## Safe Edit Workflow + +1. Identify target entries and category intent. +2. Audit only relevant catalog files first. +3. Propose minimal edits (or apply when asked). +4. Re-validate JSON and duplicate checks. +5. Summarize exact changed records and rationale. + +## Common Failure Modes To Prevent + +- Adding a model to wrong category file +- Duplicating near-identical entries under different names +- Breaking JSON structure while editing by hand +- Inconsistent key naming across similar entries +- Creating placeholder thumbnail over an existing asset + +## Output Contract + +When using this skill, provide: + +- Files audited +- Validation findings grouped by severity +- Exact records changed (before/after summary) +- Duplicate/conflict report across catalogs +- Thumbnail sync result for `models/Reference` +- Residual risks or follow-up items diff --git a/CHANGELOG.md b/CHANGELOG.md index e01b17c63..21bf94b25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,8 +54,9 @@ - skills in in `skills/README.md`: *coding*: `fix-lint` (must before commit) *validation*: `check-models`, `check-api`, `check-schedulers`, `check-processing`, `check-scripts` - *model*: `port-model`, `debug-model`, `analyze-model` + *model*: `port-model`, `debug-model`, `analyze-model`, `reference-catalog` *github*: `github-issues`, `github-features` + *diffusers*: `diffusers-code` *other*: `todo` - **CLI** - add `cli/hf-info` and update `cli/hf-search.py` @@ -87,6 +88,7 @@ - patch `z-image` for fp16 compatibility, thanks @resonantsky - patch `unipc` for timesteps device placement, thanks @resonantsky - `civitai` search and base-model discovery improvements + - validate all `reference` jsons ## Update for 2026-04-01 diff --git a/data/reference-community.json b/data/reference-community.json index 6af580180..a4e410995 100644 --- a/data/reference-community.json +++ b/data/reference-community.json @@ -82,7 +82,7 @@ "extras": "" }, "WAI-Ani-Pony XL v14": { - "path": "waiANIPONYXL_v140.safetensors.safetensors@https://civitai.com/api/download/models/1767402", + "path": "waiANIPONYXL_v140.safetensors@https://civitai.com/api/download/models/1767402", "preview": "waiANIPONYXL_v140.jpg", "desc": "", "tags": "community", diff --git a/data/reference-distilled.json b/data/reference-distilled.json index 1fee1b0e6..7de9c1fbe 100644 --- a/data/reference-distilled.json +++ b/data/reference-distilled.json @@ -73,7 +73,7 @@ "desc": "This open-source project is based on Qwen-Image and has attempted model pruning, removing 20 layers while retaining the weights of 40 layers, resulting in a model size of 12B parameters.", "skip": true, "tags": "distilled", - "date": "2025 Ocotober" + "date": "2025 October" }, "Qwen-Image-Edit Pruning-13B": { "path": "OPPOer/Qwen-Image-Edit-Pruning", @@ -82,7 +82,7 @@ "desc": "This open-source project is based on Qwen-Image-Edit and has attempted model pruning, removing 20 layers while retaining the weights of 40 layers, resulting in a model size of 13.6B parameters.", "skip": true, "tags": "distilled", - "date": "2025 Ocotober" + "date": "2025 October" }, "Qwen-Image-Edit-2509 Pruning-13B": { "path": "OPPOer/Qwen-Image-Edit-2509-Pruning", @@ -91,7 +91,7 @@ "desc": "This open-source project is based on Qwen-Image-Edit and has attempted model pruning, removing 20 layers while retaining the weights of 40 layers, resulting in a model size of 13.6B parameters.", "skip": true, "tags": "distilled", - "date": "2025 Ocotober" + "date": "2025 October" }, "lodestones Chroma1 Flash": { "path": "lodestones/Chroma1-Flash", @@ -208,6 +208,7 @@ "preview": "meituan-longcat--LongCat-Image-Edit.jpg", "desc": "LongCat-Image-Edit-Turbo, the distilled version of LongCat-Image-Edit. It achieves high-quality image editing with only 8 NFEs (Number of Function Evaluations) , offering extremely low inference latency.", "skip": true, + "tags": "distilled", "extras": "", "size": 27.30, "date": "2026 February" diff --git a/installer.py b/installer.py index a25831dad..f25dc22d5 100644 --- a/installer.py +++ b/installer.py @@ -485,7 +485,7 @@ def check_diffusers(): t_start = time.time() if args.skip_all: return - target_commit = "dc8d9032171c83741fd37ed2b12bc9d8274464f3" # diffusers commit hash == 0.37.1.dev-0331 + target_commit = "c41a3c3ed8ab16d4fadd2f08ee0f49cb78e79994" # diffusers commit hash == 0.37.1.dev-0331 # if args.use_rocm or args.use_zluda or args.use_directml: # sha = '043ab2520f6a19fce78e6e060a68dbc947edb9f9' # lock diffusers versions for now pkg = package_spec('diffusers') diff --git a/modules/hashes.py b/modules/hashes.py index 487271e52..0c6c1021e 100644 --- a/modules/hashes.py +++ b/modules/hashes.py @@ -18,7 +18,7 @@ class HashStore(dict[str, HashEntry]): def __init__(self, *args): super().__init__(*args) - def add_hash(self, key: str, mtime: float = 0, sha256: str | None = None): + def add_hash(self, key: str, mtime: float = 0, sha256: str | None = None): # pylint: disable=redefined-outer-name self.__setitem__(key, {"mtime": mtime, "sha256": sha256 or ""})