o
    ãÊiG  ã                   @   sj   U d dl Z d dlmZmZmZ d dlZd dlmZ i Zeee eej	j
egej	j
f f ed< dd„ ZdS )é    N)ÚCallableÚDictÚType)ÚAOBaseConfigÚ_QUANTIZE_CONFIG_HANDLERc                    s   t  ˆ ¡‡ fdd„ƒ}|S )ar  
    A decorator to register a transform function to map from a workflow
    configuration (child of `AOBaseConfig`) to a function that transforms
    a `torch.nn.Module` according to the specified configuration.

    For example::

        # user facing code
        class WorkflowFooConfig(AOBaseConfig): ...
            # configuration for workflow `Foo` is defined here
            bar = 'baz'

        # non user facing code
        @register_quantize_module_handler(WorkflowFooConfig)
        def _transform(
            mod: torch.nn.Module,
            config: WorkflowFooConfig,
        ) -> torch.nn.Module:
            # the transform is implemented here, usually a tensor sublass
            # weight swap or a module swap
            ...

        # then, the user calls `quantize_` with a config, and `_transform` is called
        # under the hood by `quantize_.

    c                    s   | t ˆ < | S )N)r   )Úfunc©Úconfig_type© úY/home/ubuntu/.local/lib/python3.10/site-packages/torchao/quantization/transform_module.pyÚ	decorator/   s   z3register_quantize_module_handler.<locals>.decorator)Ú	functoolsÚwraps)r	   r   r
   r   r   Ú register_quantize_module_handler   s   r   )r   Útypingr   r   r   ÚtorchÚtorchao.core.configr   r   ÚnnÚModuleÚ__annotations__r   r
   r
   r
   r   Ú<module>   s   
ýÿÿ