Skip to content

[.ai] document single-file model layout and "don't reimplement Diffus… - #14048

Merged
yiyixuxu merged 9 commits into
mainfrom
ai-docs-single-file-and-base-pipeline
Jun 24, 2026
Merged

[.ai] document single-file model layout and "don't reimplement Diffus…#14048
yiyixuxu merged 9 commits into
mainfrom
ai-docs-single-file-and-base-pipeline

Conversation

@yiyixuxu

Copy link
Copy Markdown
Collaborator

adding two gotcha from review in #14040

yiyixuxuand others added 2 commits June 23, 2026 01:51
…ionPipeline"
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>
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>
@github-actionsgithub-actionsBot added the size/S PR with diff < 50 LOC label Jun 23, 2026
yiyixuxuand others added 6 commits June 23, 2026 01:59
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>
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>
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>
…#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>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yiyixuxu
yiyixuxu requested a review from dg845June 23, 2026 02:23
Comment thread.ai/models.md Outdated

@dg845dg845 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
@yiyixuxu
yiyixuxu merged commit 03040e5 into mainJun 24, 2026
5 checks passed
DN6 pushed a commit that referenced this pull request Jul 1, 2026
#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>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/SPR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@yiyixuxu@dg845