ó
    �®žjÒ  ã                   ó€   • S SK r S SKJrJr  S SKJr  S SKJr  \ R                  " \	5      r
 S	S\S\\\      S\4S jjrg)
é    N)ÚListÚOptional)ÚAcceleratorDevice)Ú"AcceleratorDeviceNotAvailableErrorÚaccelerator_deviceÚsupported_devicesÚreturnc                 ó  • SSK nSnUR                  R                  R                  5       =(       a    UR                  R	                  5       nUR                  R
                  R                  5       =(       a$    UR                  R
                  R	                  5       n[        US5      =(       a    UR                  R	                  5       nUb¢  U(       a/  [        R                  U;  a  [        R                  SU< 35        SnU(       a/  [        R                  U;  a  [        R                  SU< 35        SnU(       a/  [        R                  U;  a  [        R                  SU< 35        SnU [        R                  R                  :X  a!  U(       a  S	nGOJU(       a  S
nGO?U(       a  SnGO4U R!                  S5      (       Ga	  Ub<  [        R                  U;  a(  [#        SU Vs/ s H  owR                  PM     sn 35      eU(       a¸  U R%                  S5      n['        U5      S:X  av  US   R)                  5       (       a^  [+        US   5      n	X’R                  R-                  5       :  a  SU	 3nGOm[#        SU	 SUR                  R-                  5       S-
   35      e['        U5      S:X  a  S	nGO.[#        SU  S35      e[#        S5      eU [        R                  R                  :X  aT  Ub<  [        R                  U;  a(  [#        SU Vs/ s H  owR                  PM     sn 35      eU(       a  S
nO­[#        S5      eU [        R                  R                  :X  aT  Ub<  [        R                  U;  a(  [#        SU Vs/ s H  owR                  PM     sn 35      eU(       a  SnO;[#        S5      eU [        R.                  R                  :X  a  SnO[#        SU  S35      e[        R                  SU5        U$ s  snf s  snf s  snf )zô
Resolve the device based on the acceleration options and the available devices in the system.

Rules:
1. AUTO: Check for the best available device on the system.
2. User-defined: Check if the device actually exists, otherwise fall-back to CPU
r   NÚcpuÚxpuzLRemoving CUDA from available devices because it is not in supported_devices=FzKRemoving MPS from available devices because it is not in supported_devices=zKRemoving XPU from available devices because it is not in supported_devices=zcuda:0ÚmpsÚcudaz8CUDA is not supported by this model. Supported devices: Ú:é   é   zcuda:zCUDA device 'cuda:z.' is not available. Available CUDA devices: 0-zInvalid CUDA device format 'z:'. Use 'cuda' or 'cuda:N' where N is a valid device index.ztCUDA is not available in the system. Please ensure PyTorch with CUDA support is installed, or use --device auto/cpu.z7MPS is not supported by this model. Supported devices: z~MPS is not available in the system. Please ensure you are running on Apple Silicon with MPS support, or use --device auto/cpu.z7XPU is not supported by this model. Supported devices: zxXPU is not available in the system. Please ensure PyTorch with Intel XPU support is installed, or use --device auto/cpu.zUnknown device option 'z:'. Valid options are: auto, cpu, cuda, mps, xpu, or cuda:NzAccelerator device: '%s')ÚtorchÚbackendsr   Úis_builtÚis_availabler   Úhasattrr   r   ÚCUDAÚ_logÚinfoÚMPSÚXPUÚAUTOÚvalueÚ
startswithr   ÚsplitÚlenÚisdigitÚintÚdevice_countÚCPU)
r   r   r   ÚdeviceÚhas_cudaÚhas_mpsÚhas_xpuÚdÚpartsÚ
cuda_indexs
             Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/docling/utils/accelerator_utils.pyÚdecide_devicer-      sÙ  € ó à€Fà�~‰~×"Ñ"×+Ñ+Ó-×K°%·*±*×2IÑ2IÓ2K€HØ�n‰n× Ñ ×)Ñ)Ó+×Q°·±×0BÑ0B×0OÑ0OÓ0Q€Gô �e˜UÓ#×@¨¯	©	×(>Ñ(>Ó(@€GàÑ$ÞÔ)×.Ñ.Ð6GÓGÜ�I‰IØ_ÐM^ÑL`Ðaôð ˆHÞÔ(×,Ñ,Ð4EÓEÜ�I‰IØ^ÐL]ÑK_Ð`ôð ˆGÞÔ(×,Ñ,Ð4EÓEÜ�I‰IØ^ÐL]ÑK_Ð`ôð ˆGàÔ.×3Ñ3×9Ñ9Ó9ÞØŠFÞØŠFÞØˆFùà	×	&Ñ	& v×	.Ò	.àÑ)Ü!×&Ñ&Ð.?Ó?ä4ØJÑ]nÓKoÒ]nÐXYÏGÌGÑ]nÑKoÐJpÐqóð ö à&×,Ñ,¨SÓ1ˆEÜ�5‹z˜Q‹ 5¨¡8×#3Ñ#3×#5Ñ#5ä   q¡›]�
Ø§
¡
× 7Ñ 7Ó 9Ó9Ø$ Z LÐ1’Fä<Ø,¨Z¨Lð 95Ø5:·Z±Z×5LÑ5LÓ5NÐQRÑ5RÐ4SðUóð ô �U“˜q“Ø!’ä8Ø2Ð3EÐ2Fð GNð Oóð ô
 5ðbóð ð
 
Ô0×4Ñ4×:Ñ:Ó	:àÑ)Ü!×%Ñ%Ð->Ó>ä4ØIÑ\mÓJnÒ\mÐWXÏ7Ì7Ñ\mÑJnÐIoÐpóð ö Ø‰Fä4ðmóð ð
 
Ô0×4Ñ4×:Ñ:Ó	:àÑ)Ü!×%Ñ%Ð->Ó>ä4ØIÑ\mÓJnÒ\mÐWXÏ7Ì7Ñ\mÑJnÐIoÐpóð ö Ø‰Fä4ðgóð ð
 
Ô0×4Ñ4×:Ñ:Ó	:Ø‰ô 1Ø%Ð&8Ð%9ð :Fð Gó
ð 	
ô
 	‡I�IÐ(¨&Ô1Ø€MùòS LpùòF Koùò" Kos   Ç$O8
ÌO=
Í=P
)N)ÚloggingÚtypingr   r   Ú%docling.datamodel.accelerator_optionsr   Údocling.exceptionsr   Ú	getLoggerÚ__name__r   Ústrr-   © ó    r,   Ú<module>r7      sV   ðó ß !å CÝ Aà×Ò˜Ó"€ð UYñ|Øð|Ø08¸Ð>OÑ9PÑ0Qð|àö|r6   