1313# limitations under the License. 
1414
1515import  inspect 
16+ from  typing  import  Dict , List , Optional 
1617
1718from  ..utils  import  is_transformers_available , logging 
1819from  .auto  import  DiffusersAutoQuantizer 
@@ -28,9 +29,9 @@ class PipelineQuantizationConfig:
2829    def  __init__ (
2930        self ,
3031        quant_backend : str  =  None ,
31-         quant_kwargs : dict  =  None ,
32-         modules_to_quantize : list  =  None ,
33-         quant_mapping : dict  =  None ,
32+         quant_kwargs : Dict [ str ,  str ]  =  None ,
33+         modules_to_quantize : Optional [ List [ str ]]  =  None ,
34+         quant_mapping : Dict [ str ,]  =  None ,
3435    ):
3536        self .quant_backend  =  quant_backend 
3637        # Initialize kwargs to be {} to set to the defaults. 
@@ -47,6 +48,9 @@ def post_init(self):
4748        self ._validate_init_args ()
4849
4950    def  _validate_init_args (self ):
51+         if  self .quant_backend  and  self .quant_mapping :
52+             raise  ValueError ("Both `quant_backend` and `quant_mapping` cannot be set." )
53+ 
5054        if  not  self .quant_mapping  and  not  self .quant_backend :
5155            raise  ValueError ("Must provide a `quant_backend` when not providing a `quant_mapping`." )
5256
@@ -150,7 +154,8 @@ def _resolve_quant_config(self, is_diffusers: bool = True, module_name: str = No
150154                logger .debug (f"Initializing quantization config class for { module_name }  ." )
151155                mapping_to_use  =  quant_config_mapping_diffusers  if  is_diffusers  else  quant_config_mapping_transformers 
152156                quant_config_cls  =  mapping_to_use [self .quant_backend ]
153-                 quant_kwargs  =  self .quant_kwargs 
157+                 # If `quant_kwargs` is None we default to initializing with the defaults of `quant_config_cls`. 
158+                 quant_kwargs  =  self .quant_kwargs  or  {}
154159                return  quant_config_cls (** quant_kwargs )
155160
156161        # Fallback: no applicable configuration found. 
0 commit comments