Implementation checklist¶
Use this checklist when implementing a model package. Complete each applicable item before requesting review, and quote any deviation in the pull request description. A workspace member is a package included in the repository's root uv workspace.
Before starting¶
- Create a fresh worktree from the current
origin/main; local checkouts may be stale, and vendor submodules must remain untouched. - Read the project roadmap, shared data sources, public conventions, and shared-library architecture before applying the current repository contracts; historical umbrella discussion remains preserved in issue 2.
- Read the model issue's plan comment and every later amendment comment; later amendments override earlier plan text when they conflict.
- Add the
in-progresslabel to the model issue before implementation begins.
Interface compliance¶
- Import
LayoutGenerationOutputfromlaygen.modeling_outputsfor Transformers models and fromlaygen.pipelines.pipeline_outputfor Diffusers pipelines, preserve all eight fields (bbox,labels,mask,id2label,sequences,scores,trajectory, andintermediates), use the canonicaltransformers.utils.ModelOutput-based class for Transformers models, keep Diffusers output based ondiffusers.utils.BaseOutput, build both from one field specification, keep no local copies, do not add anextrasfield, and put auxiliary data inintermediates. - Return normalized center
xywhboxes in[0, 1], and represent padding only withmaskrather than a reserved public label id. - Return
id2labelwith outputs and persist it in the config and model card; batched open-vocabulary output uses one batch-local union, with per-example maps inintermediates["id2label_per_example"]. - Make
generatortake precedence overseed, and verify that generation is reproducible from the seed or generator. - Use canonical
condition_typenames (unconditional,label,label_size,completion,refinement,text,content_image,relation,hierarchical, andretrieval); normalize original-implementation aliases before dispatch and raise explicitly for unsupported conditions instead of falling back silently. - Expose the full agreed v1 (initial interface) pipeline
__call__signature and the relevant v2 (later interface) additions even when the model rejects some inputs. - Make discrete-vocabulary layout tokenizers subclass
transformers.PreTrainedTokenizer, use synthetic token strings and standardpad_tokenandmask_tokenvalues, exposeencode_layout()anddecode_layout()as the primary API, serialize auxiliary data such as cluster centers with tokenizer files, preserve float64 decode paths required for agreement checks, and use a custom class only when a documented conflict requires it. - Ensure every
transformers.PreTrainedModelsubclass implementsforward; if its computation cannot be represented as one forward pass, compose the stages in the package pipeline instead of usingPreTrainedModelfor the composite. - Expose only standard model entry points (
forwardand token-levelgenerate) on model classes; put processor encoding, generation, decoding, layout-level orchestration, and theLayoutGenerationOutputresult in the pipeline's__call__, and do not addgenerate_layout-style model methods. Vendor-specific constrained decoding that cannot be expressed as a statelessLogitsProcessormay remain as a model-side helper called by the pipeline, but it is not a public generation API. - Do not override
from_pretrainedorsave_pretrainedin a way that bypasses standard loading and serialization; document the reason in the pull request description if an override is unavoidable. - Use upstream class suffixes only when the class satisfies the upstream contract; for example,
ForConditionalGenerationrequires seq2seq-styleforwardandgeneratemethods. - Before applying
plan-agreed, document and justify any novel public method or override on a Hugging Face base class, and have the coordinator, meaning the maintainer who owns the model issue and is distinct from the evidence producer, check that justification. - Make Transformers-side layout pipelines subclass
laygen.pipelines.LayoutGenerationPipelinerather thantransformers.Pipeline; the shared base owns config and subfolder loading, serialization, device and dtype handling,generator-over-seedbehavior, and the canonical layout-output contract.
Package layout¶
- Create
models/<slug>/as auvworkspace member with its ownpyproject.toml,src/<pkg>/,scripts/,tests/, andtests/vendor_parity/directories. - Isolate original-implementation dependencies in the package's
vendoroptional extra so the package itself stays light. - Put shared logic in
lib/laygen(laygen.common) or poster-sidelib/posgen(posgen.common) and import it rather than copying it between model packages. - Run workspace-member commands with
uv run --package <member-name> ..., such asuv run --package layout-dm pytestoruv run --package laygen pytest, so the member's dependencies and extras resolve instead of running plain rootuv runagainst a member path.
Data¶
- Use organization datasets under
creative-graphic-design/*as the primary source, and put all loading behind the processor. - Respect the pinned dataset configurations: Rico uses
name="ui-screenshots-and-hierarchies-with-semantic-annotations"because the default configuration is metadata-only; RICO13 needs a vendor-derived mapping, PKU filters or reservesINVALIDand uses pixelltrbboxes, Magazine converts polygons to boxes and is train-only, and CGL-v2 usesralf-stylefor validation and saliency. - Keep tests from triggering large dataset downloads; PubLayNet is about 107 GB, so use builders, streaming, synthetic rows, or tiny local fixtures.
- When an organization dataset is missing, use the original implementation's dataset source and record the migration TODO in the model issue.
Parity and tests¶
- Regenerate golden fixtures with the reference-generation script on one explicitly selected GPU and fixed seeds with
CUDA_VISIBLE_DEVICESset to one free GPU; never commit the fixtures, and commit only seeds, environment notes, config hashes, and script arguments needed to regenerate them. - Require exact token or id matches for deterministic generation and tolerance-based comparison only for logits, gate parity tests behind a pytest marker, and skip them cleanly when weights are absent.
- Reach at least 90% coverage per package under the CI selection
-m "not vendor_parity and not integration"with real unit tests such as tiny random-weight CPU configurations; never lower the gate or add broad pragma exclusions. - Run root pytest with
--import-mode=importlibfrom the rootpyproject.tomladdoptssetting, and preserve that setting when resolving pyproject merge conflicts because packages share test basenames; addingtests/__init__.pydoes not fix import mode. - Keep unit tests independent of weights and network access, and do not add
uv lock --checkto CI because the environment uses specific lock options. - Pass a local
save_pretrainedtofrom_pretrainedround-trip test.
Training for train-ourselves models¶
Models whose weights this repository trains itself are called train-ourselves models.
- Use PyTorch Lightning through the
trainingextra withLightningCLI, YAML configurations, and CLI overrides, and keep theLightningModule,LightningDataModule, andconfigs/*.yamlfiles in the model package.
Hub and licensing¶
- Name Hugging Face Hub repositories
creative-graphic-design/<model-slug>-<dataset>, adding a task suffix only for incompatible task-specific checkpoints. - Use the method name known in the literature for
<model-slug>, such aslayoutganppfor vendorconst-layout, rather than the vendor repository slug when they differ, and keep the vendor slug in the model card for traceability. - Verify the license before uploading weights, and obtain explicit approval for AGPL, GPL, or CC-NC models.
- Ship a
README.mdfor every library package underlib/laygen,lib/posgen, and futurelib/*packages that explains its purpose, module map, key API examples, design rules, single-field-spec and no-extrasconstraints, extraction criteria, and links to the project roadmap, shared data sources, and shared library architecture. - Write READMEs for package users rather than reviewers; omit compliance narration and internal tooling walkthroughs, and state only what users need to know about what exists and how to use it.
- Before writing or reviewing model documentation, read the Transformers contributing guide, modular Transformers, and the usage-first DETR, LayoutLMv3, LLaVA, Llama, GPT-2, T5, and BERT and ViT model pages; each model README should open with a short overview, paper link, key idea, and early copy-pasteable usage example before tips, limitations, and reference material.
- Give every model README a top-level
## Reproducibilitysection that opens by stating how to reproduce agreement checks against the original implementation and links tomodels/<pkg>/REPRODUCING.md; that required file contains copy-pasteable commands for download, reference or golden generation withCUDA_VISIBLE_DEVICES,pytest -m vendor_parity, checkpoint conversion, andfrom_pretrainedsmoke tests, with prerequisites, cache locations, and expected artifacts. Prose mentions do not satisfy this contract. - Take dataset identifiers and condition types from shared enums:
laygen.common.DatasetNamefor layout datasets,posgen.common.DatasetNamefor poster and content datasets, andlaygen.common.ConditionTypewith the central original-implementation alias resolver; do not redefine package-local enums or alias tables, and use canonical condition names in Hub task suffixes such as-labelrather than-gen-t. - Apply the typing rules in the code and review safeguards below to closed sets such as
box_format,condition_type,output_type, sampling modes, and dataset or vocabulary keys, as well as exhaustive branches, module constants, public signatures, and structured specification data. - Apply
ruffdocstring rules (D) to allsrc/code without adding per-file ignores forlib/*/srcormodels/*/src; write the docstrings instead, while keeping test and script exemptions where they already apply. - Give public pipelines, tokenizers, processors, configs,
laygen.commonmodules, and agents google-style docstrings withArgs,Returns,Raises, and runnable doctest-styleExamples; these docstrings feed the generated API reference. - Do not commit machine-specific absolute paths that contain a developer's local checkout directory; resolve script defaults relative to the repository root and provide an explicit CLI override, and use repository-relative paths such as
./vendor/<repo>in documentation. - Give every script under
models/<pkg>/scripts/a module docstring and an argparse--helpdescription for every argument and default, with defaults that work from a clean checkout. - Ship every model package README in model-card style with an overview, install and usage snippet using
from_pretrainedor a pipeline call, supported Hub ids, datasets, a numeric original-implementation agreement summary, and the original implementation's license and citation. - Give every model README a
### Parity Resultssection under## Evaluationwith a numeric table stating what was compared, the number of cases, the match criterion, and the result. Prose mentions do not satisfy this contract; usemodels/layout-dm/README.mdas the reference format. - Give every Hub model repository a model card based on the official Hugging Face model-card template through
huggingface_hub.ModelCard.from_template, with YAML metadata forlicense,library_name(transformersordiffusers),pipeline_tag,tagsincludinglayout-generation, and organization dataset ids, plus model details, intended uses and limitations, afrom_pretrainedexample, training data, numeric agreement results, citation BibTeX, and a link to the original implementation. - Close a model issue only after the implementation is merged to
main, agreement has been independently verified, and a localsave_pretrainedtofrom_pretrainedsmoke test passes; keep Hub publishing separate from implementation PRs.
Process¶
- Treat completion as a pull request with green CI or a documented CI blocker; do not self-merge because the user makes the merge decision.
- Apply the same lane or topic labels as the implementation issue to the pull request, and keep status labels such as
plan-agreed,in-progress, andparity-verifiedon the issue rather than the pull request. - Build the pull request description from
.github/PULL_REQUEST_TEMPLATE.md, keep it as the single current summary of the pull request, and keep progress reports out of pull request comments. - Include the pull request URL, checklist verification with deviations, agreement results, and follow-ups in progress reports.
Code and review safeguards¶
- Use
StrEnumwithauto()for closed string sets rather than barestr,tuple[str, ...], or string-literal unions; type alias tables asdict[SomeAliasEnum, SomeEnum], and use shared dataset and condition enums instead of local redefinitions. - Use
typing.assert_neverfor exhaustive enum dispatch. - Annotate module constants with
Final[...], including tokens, thresholds, and paths. - Annotate every public signature and structured specification; use
NamedTupleorTypedDictfor structured tuples and dictionaries, and useLiteralor enums for closed parameter sets. - Do not import private underscore-prefixed modules across modules; make a needed module public instead.
- Use Hugging Face base classes where they exist, including
PreTrainedTokenizerfor tokenizers andtransformers.ProcessorMixinfor processors, rather than hand-written save and load logic. - Do not use
*argsor**kwargsgrab-bag signatures on public APIs; expose explicit keyword-only parameters and reject unsupported call shapes at the signature level. - Do not use
sys.pathhacks in tests or conftest files; workspace and package execution must resolve imports. - Accept
strat public boundaries only when the boundary normalizes it immediately to a shared enum; use the enum type internally. - Check shared helpers before writing local copies of bbox, label, or serialization utilities, and list extraction candidates for LayoutDM-like logic instead of duplicating it.
Maintainer confirmation needed¶
- Confirm the model-issue closure rule before closing model issues: the source checklist text requires merge to
main, independently verified agreement, and a passing local round-trip, while current repository guidance additionally requires a passingfrom_pretrainedsmoke test for every planned Hub repository.