
    ϑi^                        S SK Jr  S SKrS SKrS SKJrJr  S SKrS SKJ	r	  \(       a2  S SK
Jr   " S S\5      r " S S	\5      r " S
 S\5      r " S S\5      rS/rSSS jjrg)    )annotationsN)TYPE_CHECKING	TypedDict)core)NotRequiredc                  *    \ rS rSr% S\S'   S\S'   Srg)_Kernel   boolenablezlist[int] | tuple[int, int]tuning_range N__name__
__module____qualname____firstlineno____annotations____static_attributes__r       X/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/incubate/autotune.pyr	   r	      s    11r   r	   c                       \ rS rSr% S\S'   Srg)_Layout   r   r   r   Nr   r   r   r   r   r      s    r   r   c                  *    \ rS rSr% S\S'   S\S'   Srg)_Dataloader"   r   r   inttuning_stepsr   Nr   r   r   r   r   r   "   s    r   r   c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg	)
_ConfigKernel&   zNotRequired[_Kernel]kernelzNotRequired[_Layout]layoutzNotRequired[_Dataloader]
dataloaderr   Nr   r   r   r   r!   r!   &   s    $$$$,,r   r!   
set_configc                J   U cR  [         R                  " 5         [         R                  " 5         [        R                  R
                  R                  SS9  g0 n[        U [        5      (       a  U nOA[        U [        5      (       a,   [        U S5       n[        R                  " U5      nSSS5        SU;   a  US   nSU;   ad  [        US   ["        5      (       a6  US   (       a  [         R                  " 5         O,[         R$                  " 5         O[        R                   " S	5        S
U;   ab  [        US
   [&        5      (       a4  US
   n[)        U5      S:X  d   e[         R*                  " US   US   5        O[        R                   " S5        SU;   ao  US   nSU;   ad  [        US   ["        5      (       a6  US   (       a  [         R                  " 5         O,[         R,                  " 5         O[        R                   " S5        SU;   a  US   nSnSU;   a4  [        US   ["        5      (       a  US   nO[        R                   " S5        SU;   a  [        US   [.        5      (       a-  [        R                  R
                  R                  XS   5        g[        R                   " S5        [        R                  R
                  R                  U5        ggg! , (       d  f       GN5= f! [         a/  n[        SU 35        [        R                   " S5         SnAGNlSnAff = f)a  
Set the configuration for kernel, layout and dataloader auto-tuning.

1. kernel: When it is enabled, exhaustive search method will be used to select
and cache the best algorithm for the operator in the tuning iteration. Tuning
parameters are as follows:

- enable(bool): Whether to enable kernel tuning.
- tuning_range(list): Start and end iteration for auto-tuning. Default: [1, 10].

2. layout: When it is enabled, the best data layout such as NCHW or NHWC will be
determined based on the device and data type. When the origin layout setting is
not best, layout transformation will be automatically performed to improve model
performance. Layout auto-tuning only supports dygraph mode currently. Tuning
parameters are as follows:

- enable(bool): Whether to enable layout tuning.

3. dataloader: When it is enabled, the best num_workers will be selected to replace
the origin dataloader setting. Tuning parameters are as follows:

- enable(bool): Whether to enable dataloader tuning.

Args:
    config (dict|str|None, optional): Configuration for auto-tuning. If it is a
        dictionary, the key is the tuning type, and the value is a dictionary
        of the corresponding tuning parameters. If it is a string, the path of
        a json file will be specified and the tuning configuration will be set
        by the json file. Default: None, auto-tuning for kernel, layout and
        dataloader will be enabled.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> import json

        >>> # config is a dict.
        >>> config = {
        ...     "kernel": {
        ...         "enable": True,
        ...         "tuning_range": [1, 5],
        ...     },
        ...     "layout": {
        ...         "enable": True,
        ...     },
        ...     "dataloader": {
        ...         "enable": True,
        ...     }
        >>> }
        >>> paddle.incubate.autotune.set_config(config) # type: ignore[arg-type]

        >>> # config is the path of json file.
        >>> config_json = json.dumps(config)
        >>> with open('config.json', 'w') as json_file:
        ...     json_file.write(config_json)
        >>> paddle.incubate.autotune.set_config('config.json')

NT)use_autotunerzLoad config error: z*Use default configuration for auto-tuning.r#   r   ztThe auto-tuning configuration of the kernel is incorrect.The `enable` should be bool. Use default parameter instead.r      r      zzThe auto-tuning configuration of the kernel is incorrect.The `tuning_range` should be list. Use default parameter instead.r$   ztThe auto-tuning configuration of the layout is incorrect.The `enable` should be bool. Use default parameter instead.r%   FzxThe auto-tuning configuration of the dataloader is incorrect.The `enable` should be bool. Use default parameter instead.r   z}The auto-tuning configuration of the dataloader is incorrect.The `tuning_steps` should be int. Use default parameter instead.)r   enable_autotuneenable_layout_autotunepaddleioreaderset_autotune_config
isinstancedictstropenjsonload	Exceptionprintwarningswarnr   disable_autotunelistlenset_autotune_rangedisable_layout_autotuner   )	configconfig_dict
filehandleekernel_configr   layout_configdataloader_configr(   s	            r   r&   r&   /   s   x ~##%		,,$,?K&$	FC	 	 	Hfc"j"ii
3 # ;#H-}$-1488 *((*))+R ]*-7>>,^<<(A---''QaIX ;#H-}$-1488 *//1002R {"'5((+H5t<<0:R ..+N;SAA		  44 N"C W 		  44\B / #U #" 	H's+,MMFGG	Hs6   K) K)K) 
K&!K) &K) )
L"3$LL")N)rA   z_ConfigKernel | str | NonereturnNone)
__future__r   r6   r:   typingr   r   r.   paddle.baser   typing_extensionsr   r	   r   r   r!   __all__r&   r   r   r   <module>rO      s_    #   +  -2) 2) i -	 - .FCr   