
    ;i                     T   S SK JrJr  S SKrS SKrS SKJr  S SKrS SKJ	r	J
r
  S SKJr  S SKJr  Sr1 Skr\	(       a  S	OS
r\R$                  " \5      rS\S\\   4S jrS\S\S\4S jrS\\\4   4S jrS\\   4S jrS\SS4S jrS\SS4S jrS\SS4S jrSS jrSS jr SS jr!g)    )IterableIteratorN)Path)HIP_ENVIRONMENTget_cuda_bnb_library_path)	CUDASpecs)print_dedented)CONDA_PREFIXLD_LIBRARY_PATH>   _PWDHOMEMAILPATHTMUXSHELLOLDPWDSSH_TTYLESSOPEN	LESSCLOSESSH_AUTH_SOCKXDG_DATA_DIRSXDG_RUNTIME_DIRXDG_GREETER_DATA_DIRDBUS_SESSION_BUS_ADDRESSGOOGLE_VM_CONFIG_LOCK_FILE)zlibamdhip64.so*)zcudart64*.dllzlibcudart*.so*znvcuda*.dllpaths_list_candidatereturnc              #     #    U R                  [        R                  5       H  nU(       d  M  [        R                  U;  a  M"   [	        U5      n UR                  5       (       d  [        R                  SU 35        M^   [         HM  nUR                  U5       H5  nUR                  5       (       d  M  UR                  5       (       a  M1  Uv   M7     MO     M     g ! [         a     Nhf = f! [        [        4 a     M  f = f7f)Nz?The directory listed in your path is found to be non-existent: )splitospathsepsepr   existsloggerwarningOSErrorCUDA_RUNTIME_LIB_PATTERNSglobis_file
is_symlinkPermissionError)r   
dir_stringdirlib_patternpths        m/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/bitsandbytes/diagnostics/cuda.py find_cuda_libraries_in_path_listr2   /   s     *00<
66#	z"Czz||NN%dehdi#jk $
  988K0C{{}}S^^-=-=!	 1  9 =   ) 		s`   ADC--C>D 1C-5C-C-D
C*'C-)C**C--D=D DDenv_varvaluec                     U [         ;   =(       dG    [        R                  U;   =(       a-    U [        ;  =(       a    SU ;  =(       a    SU ;  =(       a    SU;  $ )NCONDA	BASH_FUNC
)CUDART_PATH_PREFERRED_ENVVARSr!   r#   CUDART_PATH_IGNORED_ENVVARSr3   r4   s     r1   is_relevant_candidate_env_varr<   E   sY    00 	
FFeO "::"w&" 7*" E!	    c                      [         R                  R                  5        V Vs0 s H  u  p[        X5      (       d  M  X_M     snn $ s  snn f N)r!   environitemsr<   r;   s     r1   ,get_potentially_lib_path_containing_env_varsrB   R   s8    131A1A1Cu1C~wGdelGtNGN1Cuuus
   AAc               #      #    [        5       n [         H2  nX;   d  M
  X   n[        U5       Sh  vN   U R                  U5        M4     U R	                  5        H  u  p4[        U5       Sh  vN   M     g NF N7f)af  
Searches for a cuda installations, in the following order of priority:
    1. active conda env
    2. LD_LIBRARY_PATH
    3. any other env vars, while ignoring those that
        - are known to be unrelated
        - don't contain the path separator `/`

If multiple libraries are found in part 3, we optimistically try one,
while giving a warning message.
N)rB   r9   r2   poprA   )candidate_env_varsenvvar	directoryr3   r4   s        r1   find_cudart_librariesrH   V   su      FG/'*2I7	BBB""6*	 0 -2243E::: 5 C 	;s&   A:A:A6<A:,A8-
A:8A:
cuda_specsc                     [        SU R                   SU R                   S35        [        U 5      nUR	                  5       (       d  [        SU S35        U R                  (       d  [        S5        g g )Nz%PyTorch settings found: CUDA_VERSION=z, Highest Compute Capability: .z 
            Library not found: z8. Maybe you need to compile it from source?
            a  
            WARNING: Compute capability < 7.5 detected! Only slow 8-bit matmul is supported for your GPU!
            If you run into issues with 8-bit matmul, you can try 4-bit quantization:
            https://huggingface.co/blog/4bit-transformers-bitsandbytes
            )printcuda_version_stringhighest_compute_capabilityr   r$   r	   has_imma)rI   binary_paths     r1   _print_cuda_diagnosticsrQ   n   s    	
/
0N0N/O P''1'L'L&MQ	P
 ,J7K  +} -	
 	
 r=   c                     [        SU R                   35        [        U 5      nUR                  5       (       d  [	        SU S35        U R
                  u  p#X#4S:  a  [	        S5        g g )Nz%PyTorch settings found: ROCM_VERSION=z
        Library not found: z.
        Maybe you need to compile it from source? If you compiled from source, check that ROCm version
        in PyTorch Settings matches your ROCm install. If not, reinstall PyTorch for your ROCm version
        and rebuild bitsandbytes.
        )      zV
            WARNING: bitsandbytes is fully supported only from ROCm 6.1.
            )rL   rM   r   r$   r	   cuda_version_tuple)rI   rP   	hip_major	hip_minors       r1   _print_hip_diagnosticsrX      s{    	1*2P2P1Q
RS+J7K'= )		
 &88I&	
 'r=   c                 H    [         (       a  [        U 5        g [        U 5        g r?   )r   rX   rQ   )rI   s    r1   print_diagnosticsrZ      s    z*
+r=   c                      [        [        5       5      n U (       d  [        S5        g [        U 5      S:  a?  [	        S[
        R                  R                   S35        U  H  n[        SU 35        M     g g )NzLCUDA SETUP: WARNING! CUDA runtime files not found in any environmental path.rT   z
            Found duplicate CUDA runtime files (see below).

            We select the PyTorch default CUDA runtime, which is a]  ,
            but this might mismatch with the CUDA version that is needed for bitsandbytes.
            To override this behavior set the `BNB_CUDA_VERSION=<version string, e.g. 122>` environmental variable.

            For example, if you want to use the CUDA version 122,
                BNB_CUDA_VERSION=122 python ...

            OR set the environmental variable in your .bashrc:
                export BNB_CUDA_VERSION=122

            In the case of a manual override, make sure you set LD_LIBRARY_PATH, e.g.
            export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.2,
            z* Found CUDA runtime at: )listrH   rL   lenr	   torchversioncudacudart_pathsr0   s     r1   _print_cuda_runtime_diagnosticsrc      sw    -/0L\]	\	Q	B CH--BTBTAU V	
$  C-cU34  ' 
r=   c                      [        [        5       5      n U (       d  [        S5        g [        U 5      S:  a?  [	        S[
        R                  R                   S35        U  H  n[        SU 35        M     g g )Nz@WARNING! ROCm runtime files not found in any environmental path.rT   z
            Found duplicate ROCm runtime files (see below).

            We select the PyTorch default ROCm runtime, which is aN  ,
            but this might mismatch with the ROCm version that is needed for bitsandbytes.

            To resolve it, install PyTorch built for the ROCm version you want to use

            and set LD_LIBRARY_PATH to your ROCm install path, e.g.
            export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm-6.1.2/lib,
            z* Found ROCm runtime at: )r\   rH   rL   r]   r	   r^   r_   hipra   s     r1   _print_hip_runtime_diagnosticsrf      sw    -/0LPQ	\	Q	B CH--BSBSAT U
	
  C-cU34   
r=   c                  D    [         (       a  [        5         g [        5         g r?   )r   rf   rc    r=   r1   print_runtime_diagnosticsri      s    &(')r=   )r   N)"collections.abcr   r   loggingr!   pathlibr   r^   bitsandbytes.cextensionr   r   bitsandbytes.cuda_specsr   bitsandbytes.diagnostics.utilsr	   r9   r:   r(   	getLogger__name__r%   strr2   boolr<   dictrB   rH   rQ   rX   rZ   rc   rf   ri   rh   r=   r1   <module>ru      s    .  	   N - 9 C  ,  
  
		8	$3 8D> ,
3 
s 
t 
vd38n v;x~ ;0
	 
d 
2
y 
T 
.,) , ,565.*r=   