From d0da21adcef0400c738f5663b1fabf3fdfe42bbc Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Sat, 8 Aug 2026 00:17:43 +0100 Subject: [PATCH] feat(video): quantize modular components on load The modular loader passes sdnq quantization configs to load_components as a per-component dict: transformers take the model config, the text encoder takes the te config, and components without an entry load unquantized. Pre-quantized repositories keep their own config, which diffusers detects before a passed config applies. --- modules/video_models/video_modular.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/video_models/video_modular.py b/modules/video_models/video_modular.py index 5ac39e0eb..7fb28eb29 100644 --- a/modules/video_models/video_modular.py +++ b/modules/video_models/video_modular.py @@ -1,7 +1,7 @@ import time import logging import torch -from modules import shared, errors, devices +from modules import shared, errors, devices, model_quant from modules.logger import log @@ -38,10 +38,25 @@ def load_modular_pipe(repo_cls, repo: str, workflow: str | None = None, revision ) # workflow selection stays out of from_pretrained: pruning the blocks tree to one task # would disable runtime auto-dispatch between them; only the component fetch is restricted + load_kwargs = {} + quant_config = {} + quant_args = model_quant.create_config(module='Model') + if 'quantization_config' in quant_args: + quant_config['transformer'] = quant_args['quantization_config'] + quant_config['transformer_ref'] = quant_args['quantization_config'] + te_args = model_quant.create_config(module='TE') + if 'quantization_config' in te_args: + quant_config['text_encoder'] = te_args['quantization_config'] + if quant_config: + # per-component dict without a default entry: only the listed components quantize while + # loading, everything else loads unquantized + load_kwargs['quantization_config'] = quant_config + log.debug(f'Load modular: quant={next(iter(quant_config.values())).__class__.__name__} modules={list(quant_config)}') pipe.load_components( workflow=workflow, dtype=devices.dtype, cache_dir=shared.opts.hfcache_dir, + **load_kwargs, **offline_args, ) loaded = [name for name, component in pipe.components.items() if component is not None]