
    |j                        d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	 erd dl
mZ ddlmZ  G d d	ej        
          Z G d de          ZeZddZdS )    )annotationsN)partial)TYPE_CHECKINGAnyCallable)Layer   )BaseQuanterc                  n    e Zd ZddZed             Zed             Zej        d	             Z	d
 Z
d ZdS )ClassWithArgumentsargsr   kwargsreturnNonec                "    || _         || _        d S N)_args_kwargs)selfr   r   s      k/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/paddle/quantization/factory.py__init__zClassWithArguments.__init__   s    
    c                    | j         S r   )r   r   s    r   r   zClassWithArguments.args    s
    zr   c                    | j         S r   )r   r   s    r   r   zClassWithArguments.kwargs$   s
    |r   c                    d S r    r   s    r   
_get_classzClassWithArguments._get_class(   s    r   c                    d                     t          | j                  d | j                                        D             z             }| j        j         d| dS )N,c                "    g | ]\  }}| d | S )=r   ).0kvs      r   
<listcomp>z.ClassWithArguments.__str__.<locals>.<listcomp>.   s&    JJJda!zzazzJJJr   ())joinlistr   r   items	__class____name__)r   args_strs     r   __str__zClassWithArguments.__str__,   s`    88OOJJdk6G6G6I6IJJJJ
 
 .)77H7777r   c                *    |                                  S r   )r/   r   s    r   __repr__zClassWithArguments.__repr__2   s    ||~~r   Nr   r   r   r   r   r   )r-   
__module____qualname__r   propertyr   r   abcabstractmethodr   r/   r1   r   r   r   r   r      s              X   X 	  8 8 8    r   r   )	metaclassc                  ,     e Zd ZdZd fdZddZ xZS )QuanterFactoryzr
    The factory holds the quanter's class information and
    the arguments used to create quanter instance.
    r   r   r   r   r   c                H     t                      j        |i | d | _        d S r   )superr   partial_class)r   r   r   r,   s      r   r   zQuanterFactory.__init__<   s-    $)&)))!r   layerr   r
   c                    | j         1t          |                                 g| j        R i | j        | _         |                      |          S )zA
        Create an instance of quanter for target layer.
        )r=   r   r   r   r   )r   r>   s     r   	_instancezQuanterFactory._instance@   s`     %!(!!"$(I" " "15" "D !!%(((r   r2   )r>   r   r   r
   )r-   r3   r4   __doc__r   r@   __classcell__)r,   s   @r   r:   r:   6   s[         
" " " " " ") ) ) ) ) ) ) )r   r:   
class_namestrr   0Callable[[type[BaseQuanter]], type[BaseQuanter]]c                     d fd}|S )a
  
    Annotation to declare a factory class for quanter.

    Args:
        class_name (str): The name of factory class to be declared.

    Examples:
        .. code-block:: python

            >>> # type: ignore
            >>> # doctest: +SKIP('need 2 file to run example')
            >>> # Given codes in ./customized_quanter.py
            >>> from paddle.quantization import quanter
            >>> from paddle.quantization import BaseQuanter
            >>> @quanter("CustomizedQuanter")
            >>> class CustomizedQuanterLayer(BaseQuanter):
            ...     def __init__(self, arg1, kwarg1=None):
            ...         pass

            >>> # Used in ./test.py
            >>> # from .customized_quanter import CustomizedQuanter
            >>> from paddle.quantization import QuantConfig
            >>> arg1_value = "test"
            >>> kwarg1_value = 20
            >>> quanter = CustomizedQuanter(arg1_value, kwarg1=kwarg1_value)
            >>> q_config = QuantConfig(activation=quanter, weight=quanter)

    target_classtype[BaseQuanter]r   c           	        d| j          d| j         d| j         d| j         d	}t          |           t          j                    d         }t          j        |d                   }t          t          ft                      d         t                      d	         d
          }t          ||           d|j
        v r|j                                       | S )Nz
def init_function(self, *args, **kwargs):
    super(type(self), self).__init__(*args, **kwargs)
    import importlib
    module = importlib.import_module("z#")
    my_class = getattr(module, "z")
    globals()["z7"] = my_class
def get_class_function(self):
    return z[
locals()["init_function"]=init_function
locals()["get_class_function"]=get_class_function
r	   r   init_functionget_class_function)r   r   __all__)r3   r-   execinspectstack	getmoduletyper:   localssetattr__dict__rL   append)rG   init_function_strfrmmod	new_classrC   s        r   wrapperzquanter.<locals>.wrappern   s    (4'>	 
 ".!6  %  !   	mooa A''"HH_5$hh';< 
 
	 	Z+++$$Kz***r   )rG   rH   r   rH   r   )rC   rZ   s   ` r   quanterr[   N   s)    @     < Nr   )rC   rD   r   rE   )
__future__r   r6   rN   	functoolsr   typingr   r   r   	paddle.nnr   base_quanterr
   ABCMetar   r:   ObserverFactoryr[   r   r   r   <module>rc      s   # " " " " " 



        / / / / / / / / / / *))))))    3;    6) ) ) ) )' ) ) )* !> > > > > >r   