Add Model Port Encoder
Goal
Prototype or parity-debug one encoder or encoder-like conditioner in
FastVideo-native code. Use this for text encoders, image encoders, audio
encoders, and compound conditioners that fit the encoder config/loader bucket.
Inputs
Follow ../add-model/shared/component_skill_common.md and require the complete
packet from ../add-model/contracts/component_context.md.
Encoder-specific packet fields:
component: encoder or encoder-like conditioner name.
parity_test: tests/local_tests/encoders/test_<family>_<component>_parity.py.
weights: converted encoder dir, HF subfolder, or external HF id.
target_files: fastvideo/models/encoders/<arch_or_family>.py and
fastvideo/configs/models/encoders/<arch_or_family>.py.
Modes
Use the common prototype and parity-debug modes from
../add-model/shared/component_skill_common.md.
Encoder-specific prototype concerns include tokenizer kwargs, hidden-state
extraction, output packing, connector order, and external/passthrough weight
needs.
Reuse Proof
Apply the shared reuse proof. Encoder-specific comparison must include tokenizer
contracts, hidden-state extraction, masks, positional IDs, output packing,
connector/projection ordering, passthrough paths, and returned dataclass shape.
Existing FastVideo Patterns
- Base classes:
TextEncoder and ImageEncoder in
fastvideo/models/encoders/base.py.
- Output type:
BaseEncoderOutput.
- Config bases:
TextEncoderConfig, ImageEncoderConfig,
TextEncoderArchConfig, and ImageEncoderArchConfig in
fastvideo/configs/models/encoders/base.py.
- Use the matching encoder config bucket. Wrong bucket inheritance can typecheck
but fail during pipeline wiring.
- Config export: add the config to
fastvideo/configs/models/encoders/__init__.py.
- Registry discovery: set
EntryClass = <ClassName> or a list of class names in
the model file.
- Reference examples: native
t5.py, clip.py, siglip.py, llama.py,
qwen2_5.py, gemma.py, and compound stable_audio_conditioner.py.
- Layer guidance:
fastvideo/layers/AGENTS.md.
Implementation Rules
- Reuse tokenizers and pure data utilities when needed, but do not add runtime
third-party model-class imports as a placeholder for a component that owns
weights or numerical behavior.
- For LLM-style encoders, follow existing tensor-parallel patterns such as
QKVParallelLinear, MergedColumnParallelLinear, RowParallelLinear,
VocabParallelEmbedding, and RMSNorm when matching native examples.
- Match official hidden-state extraction exactly: layer index, pooled output,
attention mask dtype, padding side, truncation, special tokens, final norm,
output_hidden_states, and returned tuple/dataclass shape.
- For connector or conditioner modules, preserve sub-conditioner order and the
exact packing of cross-attention tokens, masks, and global conditioning.
- Put tokenizer kwargs and architecture constants on the arch config when they
affect numerical behavior.
- If an external HF encoder is explicitly accepted as a lazy wrapper, keep it
isolated, document why it is not a native port, and still require parity for
the wrapper's output contract.
Hybrid external-HF encoder checklist:
- Put external model folders in passthrough subfolders such as
text_encoder/<external_name>/, or record a root model_index.json path field
that the loader resolves to a local directory.
- Keep external model parameters out of the FastVideo-owned state-dict surface
when the external model is loaded lazily from its own HF files.
- Convert and strict-check only the FastVideo-owned connector/projection weights;
document external model weights as passthrough.
- Add parity for the wrapper's final output contract and, when useful, a narrower
connector-only parity test that labels its scope as
implementation_subcomponent.
- Verify the production loader resolves the same external path used by the
pipeline, not just the direct class used in the parity test.
Prototype Checks
Follow the shared prototype success criteria.
Parity-Debug Loop
Run the shared parity-debug loop. The component test command is:
pytest <parity_test> -v -s
For numerical drift, check tokenization, masks, hidden-state selection,
positional IDs, dtype/autocast, and output packing before changing layers.
Escape Hatches
Follow ../add-model/shared/common_rules.md and the component-specific guidance
in ../add-model/shared/component_skill_common.md. Encoder-specific ask cases
include accepting private model-code execution, choosing between incompatible
tokenizer/encoder references, or dropping a required conditioning stream.
Handoff
Return ../add-model/contracts/component_skill_handoff.md following the common
handoff rules in ../add-model/shared/component_skill_common.md.
1---2name: add-model-05-port-encoder3description: Use during /add-model Phase 4 or Phase 6 to prototype or parity-debug one FastVideo-native text, image, audio, or compound encoder component.4---56# Add Model Port Encoder78## Goal910Prototype or parity-debug one encoder or encoder-like conditioner in11FastVideo-native code. Use this for text encoders, image encoders, audio12encoders, and compound conditioners that fit the encoder config/loader bucket.1314## Inputs1516Follow `../add-model/shared/component_skill_common.md` and require the complete17packet from `../add-model/contracts/component_context.md`.1819Encoder-specific packet fields:2021- `component`: encoder or encoder-like conditioner name.22- `parity_test`: `tests/local_tests/encoders/test_<family>_<component>_parity.py`.23- `weights`: converted encoder dir, HF subfolder, or external HF id.24- `target_files`: `fastvideo/models/encoders/<arch_or_family>.py` and25 `fastvideo/configs/models/encoders/<arch_or_family>.py`.2627## Modes2829Use the common prototype and parity-debug modes from30`../add-model/shared/component_skill_common.md`.3132Encoder-specific prototype concerns include tokenizer kwargs, hidden-state33extraction, output packing, connector order, and external/passthrough weight34needs.3536## Reuse Proof3738Apply the shared reuse proof. Encoder-specific comparison must include tokenizer39contracts, hidden-state extraction, masks, positional IDs, output packing,40connector/projection ordering, passthrough paths, and returned dataclass shape.4142## Existing FastVideo Patterns4344- Base classes: `TextEncoder` and `ImageEncoder` in45 `fastvideo/models/encoders/base.py`.46- Output type: `BaseEncoderOutput`.47- Config bases: `TextEncoderConfig`, `ImageEncoderConfig`,48 `TextEncoderArchConfig`, and `ImageEncoderArchConfig` in49 `fastvideo/configs/models/encoders/base.py`.50- Use the matching encoder config bucket. Wrong bucket inheritance can typecheck51 but fail during pipeline wiring.52- Config export: add the config to53 `fastvideo/configs/models/encoders/__init__.py`.54- Registry discovery: set `EntryClass = <ClassName>` or a list of class names in55 the model file.56- Reference examples: native `t5.py`, `clip.py`, `siglip.py`, `llama.py`,57 `qwen2_5.py`, `gemma.py`, and compound `stable_audio_conditioner.py`.58- Layer guidance: `fastvideo/layers/AGENTS.md`.5960## Implementation Rules6162- Reuse tokenizers and pure data utilities when needed, but do not add runtime63 third-party model-class imports as a placeholder for a component that owns64 weights or numerical behavior.65- For LLM-style encoders, follow existing tensor-parallel patterns such as66 `QKVParallelLinear`, `MergedColumnParallelLinear`, `RowParallelLinear`,67 `VocabParallelEmbedding`, and `RMSNorm` when matching native examples.68- Match official hidden-state extraction exactly: layer index, pooled output,69 attention mask dtype, padding side, truncation, special tokens, final norm,70 output_hidden_states, and returned tuple/dataclass shape.71- For connector or conditioner modules, preserve sub-conditioner order and the72 exact packing of cross-attention tokens, masks, and global conditioning.73- Put tokenizer kwargs and architecture constants on the arch config when they74 affect numerical behavior.75- If an external HF encoder is explicitly accepted as a lazy wrapper, keep it76 isolated, document why it is not a native port, and still require parity for77 the wrapper's output contract.7879Hybrid external-HF encoder checklist:8081- Put external model folders in passthrough subfolders such as82 `text_encoder/<external_name>/`, or record a root `model_index.json` path field83 that the loader resolves to a local directory.84- Keep external model parameters out of the FastVideo-owned state-dict surface85 when the external model is loaded lazily from its own HF files.86- Convert and strict-check only the FastVideo-owned connector/projection weights;87 document external model weights as passthrough.88- Add parity for the wrapper's final output contract and, when useful, a narrower89 connector-only parity test that labels its scope as90 `implementation_subcomponent`.91- Verify the production loader resolves the same external path used by the92 pipeline, not just the direct class used in the parity test.9394## Prototype Checks9596Follow the shared prototype success criteria.9798## Parity-Debug Loop99100Run the shared parity-debug loop. The component test command is:101102```bash103pytest <parity_test> -v -s104```105106For numerical drift, check tokenization, masks, hidden-state selection,107positional IDs, dtype/autocast, and output packing before changing layers.108109## Escape Hatches110111Follow `../add-model/shared/common_rules.md` and the component-specific guidance112in `../add-model/shared/component_skill_common.md`. Encoder-specific ask cases113include accepting private model-code execution, choosing between incompatible114tokenizer/encoder references, or dropping a required conditioning stream.115116## Handoff117118Return `../add-model/contracts/component_skill_handoff.md` following the common119handoff rules in `../add-model/shared/component_skill_common.md`.