
    +h	                     z    S SK Jr  SSKJrJr  \R
                  " \5      r\" 5       (       a  S SKJ	r	  SS\
4S jjrg)    N   )is_accelerate_availablelogging)init_empty_weightsmodules_to_not_convertc                 B  ^^^^	^
^^ SSK JmJnJm	Jm
JmJm  S[        4U	U
UU4S jjmUUU4S jmT" XU5      n [        U4S jU R                  5        5       5      nU(       d,  [        R                  U R                  R                   S35        U(       a  U" U 5        U $ )Nr   )QLinearfreezeqfloat8qint2qint4qint8dtypec                    > TTTTS.U    $ )N)float8int8int4int2 )r   r   r   r   r   s    [/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/quantizers/quanto/utils.py_get_weight_type5_replace_with_quanto_layers.<locals>._get_weight_type   s    !5%OPUVV    c                 X  > [        U R                  5       5      nU(       d  U $ U R                  5        H  u  pET	" XQU5        XB;   a  M  [        U[        R
                  5      (       d  M6  [        5          T" UR                  UR                  UR                  S LUR                  R                  T" UR                  5      S9nX`R                  U'   [        U5      U R                  U   l        U R                  U   R!                  S5        S S S 5        M     U $ ! , (       d  f       M  = f)N)in_featuresout_featuresbiasr   weightsF)listchildrennamed_children
isinstancennLinearr   r   r   r   weightr   weights_dtype_modulestype
source_clsrequires_grad_)
modelquantization_configr   has_childrennamemoduleqlinearr	   r   _replace_layerss
          r   r1   4_replace_with_quanto_layers.<locals>._replace_layers   s    ENN,-L!002LDF9OP-&")),,')%$*$6$6%+%8%8#[[4$mm11 01D1R1R SG ,3NN4(6:6lENN4(3NN4(77> *) 3&  *)s   4BD
D)	c              3   @   >#    U  H  u  p[        UT5      v   M     g 7f)N)r"   ).0_replaced_moduler	   s      r   	<genexpr>._replace_with_quanto_layers.<locals>.<genexpr>.   s      q[pEWQJ@@[ps   z does not appear to have any `nn.Linear` modules. Quantization will not be applied. Please check your model architecture, or submit an issue on Github if you think this is a bug. https://github.com/huggingface/diffusers/issues/new)optimum.quantor	   r
   r   r   r   r   stranynamed_modulesloggerwarning	__class____name__)r+   r,   r   pre_quantizedr
   has_been_replacedr	   r   r1   r   r   r   r   s         @@@@@@@r   _replace_with_quanto_layersrC      s    LLW W W4 E8NOEq[`[n[n[pqq''( )C C	
 uLr   )F)torch.nnr#   utilsr   r   
get_loggerr@   r=   
accelerater   r   rC   r   r   r   <module>rH      s6     5 
		H	%-0TX 0r   