[.ai] document single-file model layout and "don't reimplement Diffus… (#14048)
* [.ai] document single-file model layout and "don't reimplement DiffusionPipeline"
Two conventions that weren't written down, surfaced while reviewing a new
model/pipeline port:
- models.md: add a "Single-file model layout" section. A model lives in one
self-contained `transformer_<name>.py`; reuse shared blocks from
normalization.py/attention.py/embeddings.py and inline model-specific
variants with `# Copied from` rather than creating per-model
`attention_processor_<name>.py` / `block_<name>.py` / `rope_<name>.py`
companion files (no precedent for these in the repo).
- pipelines.md: add gotcha #7, "Don't reimplement DiffusionPipeline." A
subclass adds only pipeline-specific steps; device placement, offloading,
execution-device resolution, and module registration already exist on the
base class. No custom device/offload manager, no `device=` arg on
`__call__`, no `set_<component>` setters.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [.ai] generalize single-file model layout section
Drop the implementation-specific examples (Lumina class names, per-model
transformer_*.py citations) and state the single-file policy generally:
everything (attention, blocks, RoPE, model-specific layers) in one model
file, with shared blocks either imported from the common modules or brought
in via `# Copied from ... with Old->New`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [.ai] trim redundant don't-split sentence from single-file section
The positive statement (everything in one model file) already conveys it;
drop the companion-module filename list and the editorializing.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [.ai] generalize the "don't reimplement DiffusionPipeline" gotcha
State the principle and the canonical base APIs; drop the implementation-
specific anti-pattern callouts (enable_*_flag booleans, set_<component>
setters, the device= arg, a shadow self.execution_device).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [.ai] pare gotcha #7 down to the principle
Drop the per-category API bullets; one sentence — don't add device
placement, offloading, or component loading/registration logic on a
subclass, it's on the base class. Can expand later if needed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [.ai] renumber gotchas after merge: component-mutation #7, reimplement #8
main's newly merged "don't modify registered component on the fly" keeps #7;
our "don't reimplement DiffusionPipeline" becomes #8 (appended after it).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [.ai] add blank line between gotchas 7 and 8
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Update .ai/models.md
Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>