
    |j%                    f    d dl mZ d dlZd dlZd dlZg Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 ZddZdS )    )annotationsNc            	        t           j                            dg dd          } t          j        ddgdt          j        t           j        j                            d                    	          }t          j        dgd
          }t           j        j        	                    | ||          }t           j
                            |          }| ||fS )zD
    Define a simple network composed by a single linear layer.
    input)N   r   float32)nameshapedtyper      g?)initializer)r	   r
   attr)r	   r
   )xweightbias)paddlestaticdatacreate_parameter	ParamAttrnnr   Constant
functionallineartensorsum)r   r   r   
linear_outouts        j/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/paddle/utils/install_check.py_simple_networkr      s     MLLL	   E $!f&)*?*H*H*M*MNNN  F
 "!I>>>D%,,uV$,OOJ
-

J
'
'C#v    c                 |    t          j        ddgddggt           j                  } |                     ddd          S )zK
    Prepare feeding data for simple network. The shape is [1, 2, 2].

          ?g       @g      @g      @)r
      r   )nparrayr   reshape)np_input_singles    r   _prepare_datar(   ,   s?     hc
S#J7rzJJJO""1a+++r    c                     	 t          t          j                                                  dk    sJ dS # t          $ r"} t          j        d|             Y d} ~ dS d} ~ ww xY w)z*
    Check whether CUDA is available.
    r   TzYou are using GPU version PaddlePaddle, but there is no GPU detected on your machine. Maybe CUDA devices is not set properly.
 Original Error is NF)lenr   r   cuda_places	Exceptionloggingwarninges    r   _is_cuda_availabler1   6   s    	6=,,..//!3333t   ($%( (	
 	
 	

 uuuuu   15 
A!AA!c                     	 t          t          j                                                  dk    sJ dS # t          $ r"} t          j        d|             Y d} ~ dS d} ~ ww xY w)z)
    Check whether XPU is available.
    r   TzYou are using XPU version PaddlePaddle, but there is no XPU detected on your machine. Maybe XPU devices is not set properly.
 Original Error is NF)r*   r   r   
xpu_placesr,   r-   r.   r/   s    r   _is_xpu_availabler5   F   s    	6=++--..2222t   ($%( (	
 	
 	

 uuuuur2   c                V   t          j                     | rt          j        d           nB|rt          j        d           n+|rt          j        |           nt          j        d           t          j        dt           j        j                            d                    }t          j        dt           j        j                            d	                    }t           j                            d
d||          }t                      }t          j	        |          } ||          }	t           j
                            |	          }
|
                                 t           j                            d|                                          }|                                 dS )z
    Testing the simple network in dygraph mode using one CPU/GPU/XPU.

    Args:
        use_cuda (bool): Whether running with CUDA.
        use_xpu (bool): Whether running with XPU.
    gpuxpucpur   g      ?)value)r   r   r   r"   r      )weight_attr	bias_attrMbP?learning_rate
parametersN)r   disable_static
set_devicer   r   r   r   Linearr(   	to_tensorr   r   backward	optimizerAdamrA   step)use_cudause_xpu
use_customcustom_device_namer<   r=   r   input_npinput_tensorr   r   opts               r   _run_dygraph_singlerQ   V   s     !%    	 !%    	 !,----%   "69#8#A#A#A#L#L  K  !6!?!?c!?!J!J  I Y	1+   F H#H--L%%J
-

J
'
'CLLNNN



(9(9(;(;    C HHJJJJJr    c                   t          j                     t           j                            t           j                                                  5  t           j                                        }t           j                                        }d|_        t           j                            ||          5  t                      \  }}}t           j        	                    ||g          d         }	ddd           n# 1 swxY w Y   | rt          j
        d          }
nB|rt          j        d          }
n+|rt          j        |d          }
nt          j                    }
t           j                            |
          }|                    |           |                    ||j        t#                      i||	d         g           ddd           n# 1 swxY w Y   t          j                     dS )z
    Testing the simple network with executor running directly, using one CPU/GPU/XPU.

    Args:
        use_cuda (bool): Whether running with CUDA.
        use_xpu (bool): Whether running with XPU.
    r#   )parameter_listr   N)feed
fetch_list)r   enable_staticr   scope_guardScopeProgramrandom_seedprogram_guardr   append_backward	CUDAPlaceXPUPlaceCustomPlaceCPUPlaceExecutorrunr   r(   rB   )rJ   rK   rL   rM   
train_progstartup_progr   r   r   param_gradsplaceexes               r   _run_static_singlerh   {   s9    		"	"6=#6#6#8#8	9	9 
 
]**,,
},,..#$ ]((\BB 	 	!0!2!2E3 -77VH 8  K	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	&$Q''EE 	&OA&&EE 	&&'91==EEO%%Em$$U++*moo.[^, 	 	
 	
 	
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4 s8   A$G3;C:.G:C>	>GC>	CGGGc                 \    G d dt           j        j                  } t           j                                          |             }t          j        |          }t           j                                        }t           j                            d|	                                          }t          j
        ddgd          } ||          }t          j
        ddgd          } |||          }|                                 |                                 |                                 dS )	z2
    train script for parallel training check
    c                  (     e Zd ZdZ fdZd Z xZS ))train_for_run_parallel.<locals>.LinearNetz?
        simple fc network for parallel training check
        c                    t                                                       t          j                            dd          | _        t          j                            dd          | _        d S )N
   r#   )super__init__r   r   rD   _linear1_linear2)self	__class__s    r   ro   z2train_for_run_parallel.<locals>.LinearNet.__init__   sO    GG"I,,R44DM"I,,R33DMMMr    c                R    |                      |                     |                    S )z!
            forward
            )rq   rp   )rr   r   s     r   forwardz1train_for_run_parallel.<locals>.LinearNet.forward   s"     ==q!1!1222r    )__name__
__module____qualname____doc__ro   ru   __classcell__)rs   s   @r   	LinearNetrk      sQ        	 		4 	4 	4 	4 	4
	3 	3 	3 	3 	3 	3 	3r    r{   r>   r?   rm   r   r#   N)r   r   Layerdistributedinit_parallel_envDataParallelMSELossrG   rH   rA   randnrF   rI   
clear_grad)	r{   layerdp_layerloss_fnadaminputsoutputslabelslosss	            r   train_for_run_parallelr      s   3 3 3 3 3FIO 3 3 3  ((***IKKE"5))Hi!!G  (;(;(=(= !  D \2r(I..FhvG\2q'9--F77F##DMMOOOIIKKKOOr    c                l    t           j                            t          t	          |                      dS )z
    Testing the simple network in data parallel mode, using multiple CPU/GPU.

    Args:
        use_cuda (bool): Whether running with CUDA.
        use_xpu (bool): Whether running with XPU.
        device_list (int): The specified devices.
    )nprocsN)r   r}   spawnr   r*   )device_lists    r   _run_parallelr      s/     3C<L<LMMMMMr    returnNonec                    t          d           d} d}d}d}t          j                    rt                      } nt          j                    rt                      }nt          t          j        j        	                                          dk    rud}t          t          j        j        	                                          dk    r?t          j        dt          j        j        	                                d          d           | r!d	}t          j                                        }n|r!d
}t          j                                        }n|rjt          j        j        	                                d         }|}t          t!          t          j        j                            |                              }n"d}t          j                            d          }t          |          }t'          | |||           t)          | |||           t          d| d           	 t          |          dk    r5|rddl}d|j        d<   t/          |           t          d| d| d           t          d           dS # t0          $ rL}t          j        d| d| d           t          j        d|            t          d| d           |d}~ww xY w)a  
    Check whether PaddlePaddle is installed correctly and running successfully
    on your system.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> # doctest: +SKIP('the output will change in different run')
            >>> paddle.utils.run_check()
            Running verify PaddlePaddle program ...
            I0818 15:35:08.335391 30540 program_interpreter.cc:173] New Executor is Running.
            I0818 15:35:08.398319 30540 interpreter_util.cc:529] Standalone Executor is Used.
            PaddlePaddle works well on 1 CPU.
            PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.
    z(Running verify PaddlePaddle program ... FNr   Tr#   zWMore than one kind of custom devices detected, but run check would only be executed on .GPUXPUCPU)device_countzPaddlePaddle works well on 1 xcclPADDLE_DISTRI_BACKENDzPaddlePaddle works well on  zs.zXPaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.z%PaddlePaddle meets some problem with aq  s. This may be caused by:
 1. There is not enough GPUs visible on your system
 2. Some GPUs are occupied by other process now
 3. NVIDIA-NCCL2 is not installed correctly on your system. Please follow instruction on https://github.com/NVIDIA/nccl-tests 
 to test your NCCL, or reinstall it following https://docs.nvidia.com/deeplearning/sdk/nccl-install-guide/index.htmlz
 Original Error is: z7PaddlePaddle is installed successfully ONLY for single z2! Let's start deep learning with PaddlePaddle now.)printr   is_compiled_with_cudar1   is_compiled_with_xpur5   r*   	frameworkcoreget_all_custom_device_typer-   r.   r   r+   r4   listrangeget_custom_device_count
cpu_placesrh   rQ   osenvironr   r,   )	rJ   rK   rL   rM   
device_strr   r   r   r0   s	            r   	run_checkr      sX   & 

4555HGJ#%% 	%''		$	&	& #%%	V"==??	@	@1	D	D
v$??AABBQFFO cjpjzj  k[  k[  k]  k]  ^_  k`  c  c  c    ?
m//11	 ?
m..00	 ?%*EEGGJ
' %==&  
 
 
m..A.>>{##Lx*6HIII':7IJJJ	
7*
7
7
7888{a =			6<
23+&&&MMMzMMMNNNf	
 	
 	
 	
 	
    EL E E: E E E	
 	
 	
 	444555?j ? ? ?	
 	
 	
 s    AI9 9
KAK

K)r   r   )
__future__r   r-   numpyr$   r   __all__r   r(   r1   r5   rQ   rh   r   r   r    r    r   <module>r      s    # " " " " "      
  $, , ,      " " "J# # #L' ' 'T	N 	N 	NW W W W W Wr    