
    Ǆg=[                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ 	 d dlZdZ	 edg d      Zh dZh dZd	 Zd
 Zd Zd Zd)dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d)dZ'd  Z(d! Z)d" Z*d# Z+d$jY                         Z-d% Z.d& Z/d' Z0e1d(k(  r e0        yy# e
eeef$ r dZ	Y w xY w)*    N)
namedtupleTF	SystemEnv)torch_versionis_debug_buildcuda_compiled_versiongcc_versionclang_versioncmake_versionoslibc_versionpython_versionpython_platformis_cuda_availablecuda_runtime_versioncuda_module_loadingnvidia_driver_versionnvidia_gpu_modelscudnn_versionpip_versionpip_packagesconda_packageship_compiled_versionhip_runtime_versionmiopen_runtime_versioncaching_allocator_configis_xnnpack_availablecpu_info>   mklmagmanumpytorchoptreetritonsoumithcudatoolkit>   mypyonnxr    r!   flake8r"   r#   c                    t        |       t        u rdnd}t        j                  | t        j                  t        j                  |      }|j                         \  }}|j                  }t               dk(  rd}nt        j                         }|j                  |      }|j                  |      }||j                         |j                         fS )z%Return (return-code, stdout, stderr).TF)stdoutstderrshellwin32oem)typestr
subprocessPopenPIPEcommunicate
returncodeget_platformlocalegetpreferredencodingdecodestrip)	commandr,   p
raw_outputraw_errrcencoutputerrs	            _/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/utils/collect_env.pyrunrD   H   s    MS(DeE *u	>A--/J	
B~ ))+s#F
..
Cv||~syy{**    c                 *     | |      \  }}}|dk7  ry|S )zIRun command using run_lambda; reads and returns entire output if rc is 0.r   N 
run_lambdar;   r?   out_s        rC   run_and_read_allrL   X   s!    G$JBQ	QwJrE   c                 z     | |      \  }}}|dk7  ryt        j                  ||      }|y|j                  d      S )zIRun command using run_lambda, returns the first regex match if it exists.r   N   )researchgroup)rI   r;   regexr?   rJ   rK   matchs          rC   run_and_parse_first_matchrT   `   sB    G$JBQ	QwIIeS!E};;q>rE   c                 N     | |      \  }}}|dk7  ry|j                  d      d   S )zKRun command using run_lambda and returns first line if output is not empty.r   N
)splitrH   s        rC   run_and_return_first_linerX   j   s/    G$JBQ	Qw99T?1rE   c                     t         t        j                  j                  dd      }t	        | dj                  |            }||S dj                  fd|j                         D              S )N	CONDA_EXEcondaz{} listrV   c              3   n   K   | ]+  j                  d       st        fdD              r - yw)#c              3   &   K   | ]  }|v  
 y wNrG   .0namelines     rC   	<genexpr>z/get_conda_packages.<locals>.<genexpr>.<genexpr>~   s     22   N)
startswithanyra   rc   patternss    @rC   rd   z%get_conda_packages.<locals>.<genexpr>z   s3      s#222 	s   15)DEFAULT_CONDA_PATTERNSr   environgetrL   formatjoin
splitlines)rI   ri   r[   rJ   s    `  rC   get_conda_packagesrp   r   sh    )JJNN;0E
:y'7'7'>
?C
{
99 NN$  rE   c                     t        | dd      S )Nzgcc --versionzgcc (.*)rT   rI   s    rC   get_gcc_versionrt      s    $Z+NNrE   c                     t        | dd      S )Nzclang --versionzclang version (.*)rr   rs   s    rC   get_clang_versionrv      s    $Z1BDYZZrE   c                     t        | dd      S )Nzcmake --versionz
cmake (.*)rr   rs   s    rC   get_cmake_versionrx      s    $Z1BMRRrE   c                 h    t               dk(  rd}t        | |d      S t               }t        | |d      S )Ndarwinzkextstat | grep -i cudazcom[.]nvidia[.]CUDA [(](.*?)[)]zDriver Version: (.*?) )r6   rT   get_nvidia_smi)rI   cmdsmis      rC   get_nvidia_driver_versionr~      s?    ~!'(S)KM 	M

C$Z6OPPrE   c                    t               dk(  s:t        rt        t        j                  d      rt        j                  j
                  t        rt        j                  j                         rt        j                  j
                  Jt        j                  j                  d      }t        |d      rdj                  |j                        }nd}nd}t        j                  j                  d       |z   S y t               }t        j                  d      } | |d	z         \  }}}|dk7  ry t        j                  |d|      S )
Nrz   hipr   gcnArchNamez ({})NoGCNArchNameOnOldPyTorch z \(UUID: .+?\)z -L)r6   TORCH_AVAILABLEhasattrr!   versionr   cudais_availableget_device_propertiesrm   r   get_device_namer{   rO   compilesub)rI   propgcnArchr}   
uuid_regexr?   rJ   rK   s           rC   get_gpu_infor      s    ~!o'%--QV:W\a\i\i\m\m\yuzz668}}  ,zz77:4/%nnT-=-=>G9G::--d3g==

C-.JC%K(JBQ	Qw66*b#&&rE   c                     t        | dd      S )Nznvcc --versionzrelease .+ V(.*)rr   rs   s    rC   get_running_cuda_versionr      s    $Z1ACVWWrE   c                    t               dk(  rtt        j                  j                  dd      }t        j                  j                  dd      }t        j                  j                  |dd      }dj                  ||      }nt               d	k(  rd
}nd} | |      \  }}}t        |      dk(  s
|dk7  re|dk7  r`t        j                  j                  d      }|>t        j                  j                  |      rt        j                  j                  |      S yt               }	|j                  d      D ]R  }
t        j                  j                  |
      }
t        j                  j                  |
      sB|	j                  |
       T |	syt        |	      }t        |      dk(  r|d   S dj                  |      }dj                  |      S )zHReturn a list of libcudnn.so; it's hard to tell which one is being used.r-   
SYSTEMROOT
C:\Windows	CUDA_PATHz%CUDA_PATH%System32wherez{} /R "{}\bin" cudnn*.dllrz   z ls /usr/local/cuda/lib/libcudnn*z7ldconfig -p | grep libcudnn | rev | cut -d" " -f1 | revr   rN   CUDNN_LIBRARYNrV   z!Probably one of the following:
{})r6   r   rk   rl   pathrn   rm   lenisfilerealpathsetrW   addsorted)rI   system_root	cuda_path	where_cmd	cudnn_cmdr?   rJ   rK   l	files_setfnfilesresults                rC   get_cudnn_versionr      sj   ~ jjnn\=AJJNN;>	GGLLj'B	077	9M		8	#
 7	M	I&JBQ
3x1}qR1WJJNN?+=RWW^^A.77##A&&Iiio WWb!77>>"MM" 9E
5zQQxYYuF/66v>>rE   c                     d} t               dk(  rt        j                  j                  dd      }t        j                  j                  dd      }t        j                  j                  |dd|       }t        j                  j                  |d	|       }||g}|D ]5  }t        j                  j                  |      s#d
j                  |      }  | S  | S )Nz
nvidia-smir-   r   r   PROGRAMFILESzC:\Program FileszNVIDIA CorporationNVSMIr   z"{}")r6   r   rk   rl   r   rn   existsrm   )r}   r   program_files_rootlegacy_pathnew_pathsmiscandidate_smis          rC   r{   r{      s    
C~ jjnn\=AZZ^^N<OPggll#57KWVYZ77<<Z=+&! 	Mww~~m,mmM2J		 JrE   c                     d\  }}}t               dk(  r | d      \  }}}n3t               dk(  r | d      \  }}}nt               dk(  r | d      \  }}}d}|d	k(  r|}|S |}|S )
N)r   r   r   linuxlscpur-   zwmic cpu get Name,Manufacturer,Family,Architecture,ProcessorType,DeviceID,         CurrentClockSpeed,MaxClockSpeed,L2CacheSize,L2CacheSpeed,Revision /VALUErz   z"sysctl -n machdep.cpu.brand_stringNoner   )r6   )rI   r?   rJ   rB   r   s        rC   get_cpu_infor   /  s    LBS~ !'*C	7	"! #R SC	8	#!"FGCH	Qw O OrE   c                  "   t         j                  j                  d      ryt         j                  j                  d      ryt         j                  j                  d      ryt         j                  j                  d      ryt         j                  S )Nr   r-   cygwinrz   )sysplatformrf   rG   rE   rC   r6   r6   @  s`    
||w'		 	 	)		 	 	*		 	 	*||rE   c                     t        | dd      S )Nzsw_vers -productVersionz(.*)rr   rs   s    rC   get_mac_versionr   M  s    $Z1JGTTrE   c                     t         j                  j                  dd      }t         j                  j	                  |ddd      }t         j                  j	                  |dd      }t        | dj                  ||            S )Nr   r   r   Wbemwmicfindstrz!{} os get Caption | {} /v Caption)r   rk   rl   r   rn   rL   rm   )rI   r   wmic_cmdfindstr_cmds       rC   get_windows_versionr   Q  sa    **..}=Kww||KVVDH'',,{J	BKJ(K(R(RS[]h(ijjrE   c                     t        | dd      S )Nzlsb_release -azDescription:\t(.*)rr   rs   s    rC   get_lsb_versionr   X  s    $Z1ACXYYrE   c                     t        | dd      S )Nzcat /etc/*-releasezPRETTY_NAME="(.*)"rr   rs   s    rC   check_release_filer   \  s    $Z1E%:< <rE   c                 l   ddl m} t               }|dk(  s|dk(  rt        |       S |dk(  r%t	        |       }|y dj                  | |             S |dk(  r_t        |       }|dj                  | |             S t        |       }|dj                  | |             S dj                  | |             S |S )	Nr   )machiner-   r   rz   zmacOS {} ({})r   z{} ({}))r   r   r6   r   r   rm   r   r   )rI   r   r   r   descs        rC   get_osr   a  s     ~H7h(2":..8!*-?%%gwy997z*##D')44 "*-##D')44')44 OrE   c                  *    dd l } | j                         S Nr   r   r   s    rC   get_python_platformr     s    rE   c                  d    dd l } t               dk7  rydj                  | j                               S )Nr   r   N/A-)r   r6   rn   libc_verr   s    rC   get_libc_versionr     s*    ~ 88H%%'((rE   c                      t          fd}t        j                  d   dk(  rdnd} |t        j                  dg      }||fS )zZReturn `pip list` output. Note: will also find conda-installed pytorch and numpy packages.c                 v    t        | ddgz         }dj                  fd|j                         D              S )Nlistz--format=freezerV   c              3   L   K   | ]  t        fd D              r  yw)c              3   &   K   | ]  }|v  
 y wr_   rG   r`   s     rC   rd   zCget_pip_packages.<locals>.run_with_pip.<locals>.<genexpr>.<genexpr>  s     5D44<5re   N)rg   rh   s    @rC   rd   z9get_pip_packages.<locals>.run_with_pip.<locals>.<genexpr>  s'      
5H55 
s    $)rL   rn   ro   )piprJ   ri   rI   s     rC   run_with_pipz&get_pip_packages.<locals>.run_with_pip  s?    z3&:K1L+LMyy 
(
 
 	
rE   r   3pip3r   z-mpip)DEFAULT_PIP_PATTERNSr   r   
executable)rI   ri   r   r   rJ   s   ``   rC   get_pip_packagesr     sI    '
  KKNc1&uK
0
1CrE   c                  F    t         j                  j                  dd      } | S )NPYTORCH_CUDA_ALLOC_CONFr   )r   rk   rl   )	ca_configs    rC   get_cachingallocator_configr     s    

8"=IrE   c                      t         r^t        j                  j                         r@t        j                  j	                          t
        j                  j                  dd      } | S y)NCUDA_MODULE_LOADINGr   r   )r   r!   r   r   initr   rk   rl   )configs    rC   get_cuda_module_loading_configr     s?    5::224

 5r:rE   c                  j    t         r-dd l} t        | j                  j                  j
                        S y)Nr   r   )r   torch.backends.xnnpackr0   backendsxnnpackenabled)r!   s    rC   r   r     s&    %5>>))1122rE   c            
         t         } t        |       \  }}t        rt        j                  }t        t        j                  j                        }t        t        j                  j                               }t        j                  j                  }t        t        j                  d      rt        j                  j                  dx}x}}	nmd }
t        j                  j                         j                  d      } |
|d      } |
|d      }	d}t        j                  j                  }ndx}x}x}}dx}x}}	t        j                  j!                  dd      }t#        |       }t%        d#i d|d	|d
dj'                  |t        j(                  j+                         dz         dt-               d|d|dt/        |       dt1               dt3        |       dt5        |       dt7        |       d|d|d|	d|d|d|dt9        |       dt;               dt=        |       dt?        |       dtA        |       d tC               d!tE               d"tG        |       S )$a  
    Collects environment information to aid in debugging.

    The returned environment information contains details on torch version, is debug build
    or not, cuda compiled version, gcc version, clang version, cmake version, operating
    system, libc version, python version, python platform, CUDA availability, CUDA
    runtime version, CUDA module loading config, GPU model and configuration, Nvidia
    driver version, cuDNN version, pip version and versions of relevant pip and
    conda packages, HIP runtime version, MIOpen runtime version,
    Caching allocator config, XNNPACK availability and CPU information.

    Returns:
        SystemEnv (namedtuple): A tuple containining various environment details
            and system information.
    r   r   c                 l    | D cg c]  }||v s|j                  d d      d    }}|r|d   S dS c c}w )NrN   r   r   )rsplit)cfgprefixs_lsts       rC   get_version_or_naz'get_env_info.<locals>.get_version_or_na  sB    7:J!fkq)"-JJ"&tAw1E1 Ks   	11rV   zHIP RuntimeMIOpen r   r   r   z{} ({}-bit runtime)rN   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r
   r   r   r   rG   )$rD   r   r   r!   __version__r0   r   debugr   r   r   r   _C_show_configrW   r   replacerp   r   rm   maxsize
bit_lengthr   r   r   r   r~   r   r   r   rt   rv   rx   r   r   r   )rI   r   pip_list_outputversion_strdebug_mode_strcuda_available_strcuda_version_strr   r   r   r   r   sys_versionr   s                 rC   get_env_infor	    s     J#3J#? K''U]]001 !8!8!:; ==--u}}e,0A0A0IRWW W#69O2 (('')//5C"3C"G%6sH%E"$#(==#4#4 OTTTnT'9<LNSSS25K++%%dC0K'
3N !% -33KAWAWAY\]A]^ ,-	
 - / 6jA ;< 'z2 8
C (
3 2 0  6    %!" &#$ *%& &''( $J/)* (
3+, (
3-. "=!>/0 2312 j)3 rE   aP  
PyTorch version: {torch_version}
Is debug build: {is_debug_build}
CUDA used to build PyTorch: {cuda_compiled_version}
ROCM used to build PyTorch: {hip_compiled_version}

OS: {os}
GCC version: {gcc_version}
Clang version: {clang_version}
CMake version: {cmake_version}
Libc version: {libc_version}

Python version: {python_version}
Python platform: {python_platform}
Is CUDA available: {is_cuda_available}
CUDA runtime version: {cuda_runtime_version}
CUDA_MODULE_LOADING set to: {cuda_module_loading}
GPU models and configuration: {nvidia_gpu_models}
Nvidia driver version: {nvidia_driver_version}
cuDNN version: {cudnn_version}
HIP runtime version: {hip_runtime_version}
MIOpen runtime version: {miopen_runtime_version}
Is XNNPACK available: {is_xnnpack_available}

CPU:
{cpu_info}

Versions of relevant libraries:
{pip_packages}
{conda_packages}
c                 X  
 dd}dd}dd}dd}d }| j                         
 || j                        
d<   g d}|dgz   }t        
fd	|D              }t        r=t        j
                  j                         s|r|D ]  }	d

|	<   	 | j                  d
d<    |
      
 |
      
 |
d         
d<    |
d         
d<   
d   r( |
d   dj                  | j                              
d<   
d   r |
d   d      
d<   | j                  
d<   t        j                  di 
S )Nc                 F    | j                         D ]  }| |   	|| |<    | S r_   keys)dctreplacementkeys      rC   replace_nonesz!pretty_str.<locals>.replace_nones  s4    88: 	#C3x#"CH	# 
rE   c                 d    | j                         D ]  }| |   du r|| |<   | |   du s|| |<    | S )NTFr  )r  truefalser  s       rC   replace_boolsz!pretty_str.<locals>.replace_bools&  sH    88: 	!C3x4CSU" C		!
 
rE   c                 t    | j                  d      }|D cg c]  }||z   	 }}dj                  |      S c c}w )NrV   )rW   rn   )texttaglinesrc   updated_liness        rC   prependzpretty_str.<locals>.prepend.  s;    

4 056t66yy'' 7s   5c                 *    | t        |       dk(  r|S | S r   )r   )r  r  s     rC   replace_if_emptyz$pretty_str.<locals>.replace_if_empty3  s    D	QrE   c                 f    | .t        | j                  d            dkD  rdj                  |       S | S )NrV   rN   z
{}
)r   rW   rm   )strings    rC   maybe_start_on_next_linez,pretty_str.<locals>.maybe_start_on_next_line8  s1    #fll4&8"9A"=??6**rE   r   )r   r   r   r   c              3   ,   K   | ]  }|   d u   y wr_   rG   )ra   fieldmutable_dicts     rC   rd   zpretty_str.<locals>.<genexpr>K  s"      *F(-Ut#*Fs   zNo CUDAr   r   r   r   z[{}] z[conda] r   )zCould not collect)YesNo)z	[prepend])zNo relevant packagesrG   )_asdictr   allr   r!   r   r   r   rm   r   r   env_info_fmt)envinfor  r  r  r  r   dynamic_cuda_fieldsall_cuda_fieldsall_dynamic_cuda_fields_missingr"  r#  s             @rC   
pretty_strr-    s{   (

 ??$L 	!!:!:; $%
 *_,==O&) *F1D*F 'F#uzz668=\$ 	,E"+L	,((04:L01 !.L !.L $4L4P#QL %5lCS6T%UL!" N#'.|N/K/6~~g>Q>Q/R(T^$$%)0>N1O1;*=%&&//L...rE   c                  (    t        t                     S )a  
    Returns a pretty string of environment information.

    This function retrieves environment information by calling the `get_env_info` function
    and then formats the information into a human-readable string. The retrieved environment
    information is listed in the document of `get_env_info`.
    This function is used in `python collect_env.py` that should be executed when reporting a bug.

    Returns:
        str: A pretty string of the environment information.
    )r-  r	  rG   rE   rC   get_pretty_env_infor/  i  s     ln%%rE   c                  0   t        d       t               } t        |        t        rjt        t        d      rXt        t        j
                  d      r<t        j
                  j                  j                  }t        j                  dk(  rt        j                  j                  |      rt        j                  |      D cg c]"  }t        j                  j                  ||      $ }}t        |t        j                  j                         }t        j                  j!                  |      }t"        j"                  j%                  |      j'                  d      }dj)                  ||      dz   }t        |t        j*                  	       y y y y y y c c}w )
Nz%Collecting environment information...utils_crash_handlerr   )r  z%Y-%m-%d %H:%M:%Sz.
*** Detected a minidump at {} created on {}, zKif this is related to your bug please include it when you file a report ***)file)printr/  r   r   r!   r1  r2  DEFAULT_MINIDUMP_DIRr   r   r   r   r   listdirrn   maxgetctimedatetimefromtimestampstrftimerm   r+   )rA   minidump_dirdumpdumpslatestctimecreation_timemsgs           rC   mainrC  x  s   	
12 "F	&M75'2wu{{L\7]{{11FF<<7"rww~~l'CBD**\BZ[$RWW\\,5[E[BGG$4$45FGG$$V,E$--;;EBKKL_`MCJJ6S`a_`C#CJJ' (D" 8^2 \s   'F__main__r_   )2r9  r7   rO   r1   r   r   collectionsr   r!   r   ImportError	NameErrorAttributeErrorOSErrorr   rj   r   rD   rL   rT   rX   rp   rt   rv   rx   r~   r   r   r   r{   r   r6   r   r   r   r   r   r   r   r   r   r   r   r	  r:   r(  r-  r/  rC  __name__rG   rE   rC   <module>rK     s8     	  
 	 "O
 { % 	8	  + O[SQ',X"?Jv"
UkZ<
<
)*
FP< 
EG= BH/V&($ zF q 	Y8 Os   B3 3C C