
    9i                         S SK r S SKrS SKJrJr  S SKrSrSrSrSr	Sr
SrS	rS
rSrSrSrSr   SS\S\\\4   S\\   4S jjr\ R*                  SS j5       rS rg)    N)OptionalUnionz@min_scalesz@max_scalesz@scaleszconfig.jsonzmodel_config.jsonzmodel_state.pdparamszmodel_state.pdparams.index.jsonzpytorch_model.bin.index.jsonzpytorch_model.binzmodel.safetensors.index.jsonzmodel.safetensorszgeneration_config.jsonpretrained_model_name_or_path	filenames	subfolderc                    U c   S5       eUc   S5       eUb  UOSn[        U[        5      (       a  U/n[        R                  R	                  U 5      (       a  U $ [        R                  R                  U 5      (       a  [        U5       H  u  pE[        R                  R                  [        R                  R                  XU5      5      (       au  [        R                  R	                  [        R                  R                  XU5      5      (       d  [        U  SU S35      e[        R                  R                  XU5      s  $ U[        U5      S-
  :  a  M  [        SU S	U  35      e   g[        S
5      e)zf
This is a load function, mainly called by the from_pretrained function.
Adapt for PaddleX inference.
Nz,pretrained_model_name_or_path cannot be Nonezfilenames cannot be None z$ does not appear to have file named .   zplease make sure one of the z under the dir zQplease make sure `pretrained_model_name_or_path` is either a file or a directory.)
isinstancestrospathisfileisdir	enumerateexistsjoinEnvironmentErrorlenFileNotFoundError
ValueError)r   r   r   kwargsindexfilenames         i/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/inference/models/common/vlm/utils.pyresolve_file_pathr   #   s^    	&16561 <"<< &2	I)S!!K		ww~~344,,	4	5	5(3OEww~~:xP  ww~~GGLL!>8T  +899]^f]gghi  ww||$AhWWY!++'29+_MjLkl   4& _
 	
    c              #   D  #    [         R                  R                  5       nU S:X  a  [         R                  " U 5        O+U S;   a%  [         R                  " SR	                  X5      5         S v   [         R                  " U5        g ! [         R                  " U5        f = f7f)Ncpu)gpuxpunpuz{}:{})paddledevice
get_device
set_deviceformat)r%   dev_idorigin_devices      r   device_guardr+   R   sp     MM,,.M&!	(	('..89)-(-(s   A'B *B .B BB c                  h   [         R                  " 5       (       a  gS[         R                  R                  5       ;   a  gS[         R                  R                  5       ;   a  g[         R                  " 5       (       a  g[         R
                  " 5       (       a  g[         R                  " 5       (       a  gg)z0
Return the device name of running environment.
r!   r#   gcurocmr"   	metax_gpur    )r$   is_compiled_with_cudar%   get_all_custom_device_typeis_compiled_with_rocmis_compiled_with_xpuis_compiled_with_maca r   r   get_env_devicer6   _   s     ##%%	&--::<	<	&--::<	<		%	%	'	'		$	$	&	&		%	%	'	'r   )NNN)r    r   )
contextlibr   typingr   r   r$   ASYMMETRY_QUANT_SCALE_MINASYMMETRY_QUANT_SCALE_MAXSYMMETRY_QUANT_SCALECONFIG_NAMELEGACY_CONFIG_NAMEPADDLE_WEIGHTS_NAMEPADDLE_WEIGHTS_INDEX_NAMEPYTORCH_WEIGHTS_INDEX_NAMEPYTORCH_WEIGHTS_NAMESAFE_WEIGHTS_INDEX_NAMESAFE_WEIGHTS_NAMEGENERATION_CONFIG_NAMEr   listr   contextmanagerr+   r6   r5   r   r   <module>rG      s     	 " ) )   ( , = ; * 8 ' 1  *."&#,
#&,
S$Y,
 },
^ 	) 	)r   