Support New Model¶
Please make sure you have install and initialize pre-commit before adding any new commit. Refer PRE_COMMIT for more details.
Cache Acceleration¶
In order to support cache acceleration for new model, we have to register it's BlockAdapter at caching/block_adapters/adapter.py and use _safe_import func to import it at caching/block_adapters/__init__.py. For example:
- step 1: Implement the
qwenimage_adapterat caching/block_adapters/adapters.py
@BlockAdapterRegister.register("QwenImage")
def qwenimage_adapter(pipe, **kwargs) -> BlockAdapter:
try:
from diffusers import QwenImageTransformer2DModel
except ImportError:
QwenImageTransformer2DModel = None # requires diffusers>=0.35.2
_relaxed_assert(pipe.transformer, QwenImageTransformer2DModel)
return BlockAdapter(
pipe=pipe,
transformer=pipe.transformer,
blocks=pipe.transformer.transformer_blocks,
forward_pattern=ForwardPattern.Pattern_1,
check_forward_pattern=True,
has_separate_cfg=True,
**kwargs,
)
- step 2: use
_safe_importto import it at caching/block_adapters/__init__.py.
Modular Pipelines (e.g. FLUX.3)¶
Some new models only ship as a diffusers modular pipeline
(ModularPipeline + ModularPipelineBlocks, e.g. Flux3DistilledModularPipeline). There, pipe
is neither a DiffusionPipeline nor a torch.nn.Module, so the pipeline-level paths need a small
amount of extra care:
- All pipeline dispatch resolves the pipe through
cache_dit.utils.is_pipeline()/_resolve_pipe(), so no per-model change is needed forenable_cache,summaryandparse_extra_modules. - A modular denoise step builds the transformer kwargs by inspecting
transformer.forward; cache-dit therefore keeps the original__signature__when it patchesforward(CachedAdapter.mock_transformer). Do not remove it: required inputs such asimg_idswould be silently dropped. - Register the BlockAdapter under the transformer class name prefix, and remember that the registry
returns the first matching prefix (
"Flux3"must be registered before"Flux"). - In
ModelConfig,pipeline_class=Flux3DistilledModularPipelineis loaded withfrom_pretrained+load_components(dtype=...), and the model is called withoutput="images".
Reference implementation: flux3_adapter in
caching/block_adapters/adapters.py,
the flux3 / flux3_edit registrations in
cli/models/flux3.py,
and the TP planner in
distributed/transformers/flux3.py.
Context Parallelism¶
In order to support context parallelism for new model, we have to register it's ContextParallelismPlanner at context_parallelism and use _safe_import func to import it at cp_planners.py. For example:
- step 1: Implement the
FluxContextParallelismPlannerat FLUX.1 CP planner at flux.py - step 2: use
_safe_importfunc to import it at planners.py.
Tensor Parallelism¶
In order to support tensor parallelism for new model, we have to register it's TensorParallelismPlanner at tensor_parallelism and use _safe_import func to import it at planners.py. For example:
- step 1: Implement the
FluxTensorParallelismPlannerat FLUX.1 TP planner at flux.py - step 2: use
_safe_importfunc to import it at planners.py.
Text Encoder Parallelism¶
In order to support text encoder tensor parallelism for new model, we have to register it's TextEncoderTensorParallelismPlanner at text_encoders and use _safe_import func to import it at planners.py. For example:
- step 1: Implement the
T5EncoderTensorParallelismPlannerat T5 TP planner at t5_encoder.py - step 2: use
_safe_importfunc to import it at text_encoders/planners.py.
Auto Encoder (VAE) Parallelism¶
In order to support auto encoder (VAE) data parallelism for new model, we have to register it's AutoEncoderDateParallelismPlanner at autoencoders and use _safe_import func to import it at planners.py. For example:
- step 1: Implement the
AutoencoderKLDataParallelismPlannerat AutoencoderKL DP planner at autoencoder_kl.py - step 2: use
_safe_importfunc to import it at autoencoders/planners.py.
Models and Tests¶
Once the acceleration support for the new model is completed, add a family module or a registration to
cli/models/, declare its
task and path metadata in ModelRegistry.register, add the module to _MODEL_MODULES, and perform
the necessary tests.