+
    QV-jÍ  ã                  óØ   € ^ RI Ht ^ RIHt ^ RIHtHt ^RIHt ^RI	H
t
Ht ]P                  ! ]4      t]! 4       '       d   ^ RIt^ RIHt RR R llt ! R	 R
]4      t ! R R]4      tR# )é    )Úannotations)ÚAny)Úis_torch_availableÚlogging)ÚConversionOps)Úget_module_from_nameÚshould_convert_moduleNc               ó4   € V ^8„  d   QhRRRRRRRRR	R
RRRR/# )é   Úmodelztorch.nn.ModuleÚmodules_to_not_convertzlist[str] | NoneÚquant_configzdict | NoneÚcompute_dtypeztorch.dtypeÚdeviceÚstrÚpre_quantizedÚboolÚreturn© )Úformats   "Úo/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/integrations/sinq.pyÚ__annotate__r       sN   € ÷ 0ñ 0Øð0à,ð0ð ð0ð ð	0ð
 ð0ð ð0ð ñ0ó    c                óÜ  € ^ RI Hp Vf   . p\        V P                  4       4       FÂ  w  rx\	        V\
        P                  4      '       g   K'  \        Wq4      '       g   K:  VP                  R4      w  ršpV	'       d   V P                  V	4      MT pT! V'       g   VP                  MRV'       g   VP                  MRV'       g   VP                  RJMRVVVRR7      p\        WËV4       KÄ  	  V # )aÑ  
Replace nn.Linear modules with empty SINQLinear modules.

Args:
    model: The model to modify
    modules_to_not_convert: List of module names to skip
    quant_config: SINQ quantization config dict (None for pre-quantized models)
    compute_dtype: Computation dtype for the quantized layers
    device: Device string for the quantized layers
    pre_quantized: Whether loading a pre-quantized checkpoint

Returns:
    The modified model with SINQLinear modules
)Ú
SINQLinearNÚ.FT)Úin_featuresÚout_featuresÚbiasr   r   r   Úuse_unpack_kernel)Úsinq.sinqlinear_hfr   ÚlistÚnamed_modulesÚ
isinstanceÚnnÚLinearr	   Ú
rpartitionÚget_submoduler   r   r   Úsetattr)r   r   r   r   r   r   r   Ú	full_nameÚmoduleÚparent_pathÚ_Ú
child_nameÚparentÚ
sinq_layers   &&&&&&        r   Úreplace_with_sinq_linearr1       sÌ   € õ, .àÒ%Ø!#Ðä! %×"5Ñ"5Ó"7Ö8Ñˆ	Ü˜&¤"§)¡)×,Ò,ÙÜ$ Y×GÒGÙà%.×%9Ñ%9¸#Ó%>Ñ"ˆ˜
ß5@�×$Ñ$ [Ô1Àeˆáß2?˜×*Ò*ÀTß4A˜×,Ò,Àtß2?�&—+‘+ TÑ)ÀUØ%Ø'ØØ"ô
ˆ
ô 	� JÖ/ñ' 9ð* €Lr   c                  ó0   € ] tR t^StRtR tRR R lltRtR# )ÚSinqQuantizea  
Param-level ConversionOp for SINQ (from FP weights).

At load time, for each `Linear.weight` that should be quantized:
  - The SINQLinear module already exists (created in _process_model_before_weight_loading)
  - We just call quantize() on it with the loaded weight tensor
c                	ó   € Wn         R # ©N©Úhf_quantizer©Úselfr7   s   &&r   Ú__init__ÚSinqQuantize.__init__\   ó   € Ø(Ör   Nc               ó(   € V ^8„  d   QhRRRRRRRR/# ©	r   Ú
input_dictzdict[str, Any]r   ztorch.nn.Module | NoneÚfull_layer_namez
str | Noner   zdict[str, torch.Tensor]r   )r   s   "r   r   ÚSinqQuantize.__annotate___   s2   € ÷ ñ à"ðð &ðð $ð	ð 
!ñr   c                	ó  € \        \        VP                  4       4      4      w  rg\        V\        4      '       d
   V^ ,          MTp\        W#4      w  ršV	P                  V4       Ve   VP                  V4       RV	n        / # )r   T)	ÚnextÚiterÚitemsr$   r"   r   ÚquantizeÚdiscardÚ_is_hf_initialized)r9   r?   r   r@   Úmissing_keysÚkwargsr-   ÚvaluesÚweight_tensorr+   Útensor_names   &&&&&,     r   ÚconvertÚSinqQuantize.convert_   so   € ô œ˜j×.Ñ.Ó0Ó1Ó2‰	ˆÜ%/°¼×%=Ò%=˜˜qž	À6ˆä2°5ÓJÑˆà�‰˜Ô&àÒ#Ø× Ñ  Ô1à$(ˆÔ!àˆ	r   r6   )NNN©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r:   rN   Ú__static_attributes__r   r   r   r3   r3   S   s   † ñò)÷ó r   r3   c                  ó0   € ] tR t^vtRtR tRR R lltRtR# )ÚSinqDeserializea  
ConversionOp for loading *pre-quantized* SINQ checkpoints.

Checkpoint layout (what `SINQLinear.state_dict` produces) is, per module:
    <prefix>.W_q
    <prefix>.bias
    <prefix>.meta

WeightConverter in the quantizer is configured so that:
  - we group ".W_q", ".meta", ".bias" as input_dict
  - conceptually treat them as belonging to "<prefix>.weight"
  - and call this SinqDeserialize.convert to load the state into the existing SINQLinear.

The returned dict is {} because we load directly into the module.
c                	ó   € Wn         R # r5   r6   r8   s   &&r   r:   ÚSinqDeserialize.__init__‡   r<   r   Nc               ó(   € V ^8„  d   QhRRRRRRRR/# r>   r   )r   s   "r   r   ÚSinqDeserialize.__annotate__Š   s2   € ÷ #ñ #à"ð#ð &ð#ð $ð	#ð 
!ñ#r   c                	óô  € \        VP                  4       4       F(  w  rV\        V\         4      '       g   K  V^ ,          W&   K*  	  VP                  R4      pVP                  R4      pVP                  R4      p	Ve   VfE   \	        \        VP                  4       4      4      p\        V\         4      '       d
   V^ ,          pW6/# \        W#4      w  r«RVRV/pV	e   WœR&   V
P                  V4       RV
n	        / # )r   z.W_qz.metaz.biasÚW_qÚmetar   T)
r"   rE   r$   ÚgetrC   rD   rK   r   Úload_state_dictrH   )r9   r?   r   r@   rJ   ÚkÚvr^   r_   r   r+   r-   Ústates   &&&&,        r   rN   ÚSinqDeserialize.convertŠ   sí   € ô ˜×)Ñ)Ó+Ö,‰DˆAÜ˜!œT×"Ô"Ø ! !¥�
“ñ -ð �n‰n˜VÓ$ˆØ�~‰~˜gÓ&ˆØ�~‰~˜gÓ&ˆð Š;˜$š,Ü”T˜*×+Ñ+Ó-Ó.Ó/ˆAÜ˜!œT×"Ò"Ø�a•D�Ø#Ð'Ð'ä(¨Ó@‰	ˆð �3Ø�Dð
ˆð ÒØ �&‰Mà×Ñ˜uÔ%Ø$(ˆÔ!àˆ	r   r6   )NNrP   r   r   r   rX   rX   v   s   † ñò )÷#ó #r   rX   )NNNzcuda:0F)Ú
__future__r   Útypingr   Útransformers.utilsr   r   Úcore_model_loadingr   Úquantizers.quantizers_utilsr   r	   Ú
get_loggerrQ   ÚloggerÚtorchÚtorch.nnr%   r1   r3   rX   r   r   r   Ú<module>ro      sV   ðõ #å ç :å .ß Uð 
×	Ò	˜HÓ	%€á×ÒÛÝ÷0ôf �=ô  ôF7�mö 7r   