协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
model-extension【开发与工程】Add or modify Transformers models, tokenizers, processors, pipelines, docs, and tests while respecting contribution policy, modular/Copied-from rules, auto mappings, and quality gates.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when a contributor or maintainer agent must add, port, refactor, or repair model-family code inside Transformers 5.13.0.dev0. It routes the work, identifies the safe extension path, and points to detailed references bundled with this skill.
AutoConfig.register, AutoModel.register, or Hub trust_remote_code.| Need | Go to |
|---|---|
| Contribution gating, duplicate checks, AI-assisted PR requirements | Contribution policy |
| New model similar to an existing architecture | Modular workflow |
| New architecture or manual port | Modular workflow |
| Auto classes, tokenizer, processor, image/video processor registration | Modular workflow |
| Model tests, slow tests, quality commands | Testing and quality |
Copied-from, modular conversion, wrong model_type, missing mappings | Troubleshooting |
| Static local checklist | scripts/model_extension_checklist.py |
Use the modular path when a new model mostly matches an existing model, such as a decoder-only LM with changed norms, attention details, or config fields.
Expected files often include:
src/transformers/models/<model>/modular_<model>.pyconfiguration_<model>.py, modeling_<model>.py, and modality files created by the convertersrc/transformers/models/<model>/__init__.pysrc/transformers/models/auto/docs/source/en/model_doc/ and model indexestests/models/<model>/Core commands:
transformers add-new-model-like
python utils/modular_model_converter.py <model>
python utils/check_modular_conversion.py --files src/transformers/models/<model>/modular_<model>.py
pytest tests/models/<model>/ -v
make style
make typing
make fix-repo
make check-repo
Do not edit generated modeling/configuration files as the source of truth when a modular_<model>.py exists. Edit the modular file and regenerate.
Use the manual path when no existing model is a good parent. Keep model files self-contained and readable. New models should inherit from PreTrainedModel; new configs should inherit from PreTrainedConfig, set a unique model_type, and support from_pretrained / save_pretrained behavior.
Validate that:
config_classmodel_typeis_torch_available() or equivalent helpers@slow only for real checkpoint integration testsTokenizers, image processors, video processors, feature extractors, and processors must be registered consistently with model configs and auto mappings. Verify both slow and fast tokenizer behavior when relevant. If a new processor combines multiple modalities, check that AutoProcessor.from_pretrained resolves correctly and that save/load round-trips preserve the processor class.
If the task is primarily tokenizer or processor design rather than model integration, cross-link to the sibling tokenizers-processors sub-skill.
A pipeline class should implement _sanitize_parameters, preprocess, _forward, and postprocess. Keep inputs/outputs simple and preferably JSON-serializable. Register built-in tasks through PIPELINE_REGISTRY.register_pipeline with supported model classes, defaults, and task type.
Use the sibling inference-pipelines sub-skill for broader pipeline behavior, the public pipeline(...) signature, device placement, dtype='auto', device_map, and trust_remote_code implications.
Route detailed behavior outside model-extension to sibling sub-skills:
GenerationConfig, generate, streamers, cache behavior, and logits processors.TrainingArguments, Trainer, distributed options, FSDP, DeepSpeed, precision flags, and torch_compile.transformers console script and serving-oriented CLI usage.Before coding or summarizing PR-ready work:
gh issue view <issue_number> --repo huggingface/transformers --comments
gh pr list --repo huggingface/transformers --state open --search "<issue_number> in:body"
gh pr list --repo huggingface/transformers --state open --search "<short area keywords>"
These GitHub commands are required for PR coordination, but the bundled checklist script does not run network calls by default.
Run the local checklist from this skill directory for a repo tree:
python scripts/model_extension_checklist.py --repo /path/to/transformers --model <model>
Add --json when another tool needs machine-readable findings.
A model-extension change is ready for human review only when:
CONFIG_MAPPING_NAMES and relevant auto mappings resolve the new model_type@slow and run with RUN_SLOW=1 when safe and necessarymake style or make fix-repo has been run as a final cleanup, followed by targeted verificationA minimal inspection environment may import transformers without PyTorch installed. PyTorch-dependent classes and tests can raise optional dependency ImportError unless torch is installed. When drafting or validating changes in lightweight environments:
is_torch_available() and decorators such as require_torchStop and ask for human clarification when: