§
    *`ƒi¸  ã                   óŒ   — d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	 dgZ
dej        j        defd	„Zdej        j        fd
„ZdS )é    )ÚDictN)ÚTRANSFORM_CONFIG_NAME)ÚTransformConfigÚTransformFactory)Úhas_offloaded_paramsÚapply_transform_configÚmodelÚconfigc                 óä   — |j                              ¦   «         D ]0\  }}t          j        ||¬¦  «        }|                     | ¦  «         Œ1t          | t          |¦  «         t          | ¦  «         dS )a
  
    Apply a transform config to a model. Weight transforms are fused into weights, while
    activation transforms are attached as submodules and trigger via pytorch hooks

    :param model: model to apply config to
    :param config: transform config to apply
    )ÚnameN)Úconfig_groupsÚitemsr   Úfrom_schemeÚapply_to_modelÚsetattrr   Ú_tie_offloaded_tensors)r	   r
   r   ÚschemeÚfactorys        úv/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/compressed_tensors/transform/apply.pyr   r      s}   € ð Ô,×2Ò2Ñ4Ô4ð &ð &‰ˆˆfÝ"Ô.¨v¸DÐAÑAÔAˆØ×Ò˜uÑ%Ô%Ð%Ð%õ ˆEÕ(¨&Ñ1Ô1Ð1õ
 ˜5Ñ!Ô!Ð!Ð!Ð!ó    c                 óJ  — t          ¦   «         }|                      ¦   «         D ]}t          |¦  «        rn|                     d¬¦  «        D ]W\  }}|j        j        |                              ¦   «         }||vrt          ||¦  «        ||<   t          ||||         ¦  «         ŒXŒ€dS )a  
    When accelerate replaces tensors with meta tensors during offloading, the meta
    tensors may not be identical, even if the offloaded values are identical.

    However, transformers can only serialize correctly if meta tensors are identical
    (see transformers#39263).

    This function collects all meta tensors which have shared offloaded values and sets
    those tensors to be identical so that they can be removed during serialization

    :param model: model potentially containing offloaded meta tensors to fix
    F)ÚrecurseN)	ÚdictÚmodulesr   Únamed_parametersÚ_hf_hookÚweights_mapÚdata_ptrÚgetattrr   )r	   Úptr_to_metaÚmoduleÚkeyÚ_Úoffloaded_ptrs         r   r   r   /   s¾   € õ  26±´€KØ—-’-‘/”/ð Að AˆÝ Ñ'Ô'ð 	AØ ×1Ò1¸%Ð1Ñ@Ô@ð Að A‘QØ &¤Ô ;¸CÔ @× IÒ IÑ KÔ Kà ¨Ð3Ð3Ý18¸ÀÑ1EÔ1EK Ñ.Ý˜  [°Ô%?Ñ@Ô@Ð@Ð@øðAð Ar   )Útypingr   ÚtorchÚcompressed_tensorsr   Úcompressed_tensors.transformr   r   Ú compressed_tensors.utils.offloadr   Ú__all__ÚnnÚModuler   r   © r   r   ú<module>r.      s¾   ðð Ð Ð Ð Ð Ð à €€€Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø JÐ JÐ JÐ JÐ JÐ JÐ JÐ JØ AÐ AÐ AÐ AÐ AÐ Að $Ð
$€ð" %¤(¤/ð "¸?ð "ð "ð "ð "ð*A %¤(¤/ð Að Að Að Að Að Ar   