
    biw                    ~    d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZ  ej        e          ZddZddZdS )    )annotationsN)Path)PretrainedConfig)_save_pretrained_wrapperbackend_should_exportbackend_warn_to_savemodel_name_or_pathstrconfigr   	task_namec                   	 ddl }ddlm}m}m}m} |||d}	||	vr<d                    |	                                          }
t          d| d|
           |	|         }n# t          $ r t          d          w xY w|                    d	|                                d                   |d	<   t          |           }|                                }d
}d}t          ||||||          \  }}|r|                    dd            |j        | f||d|}t#          |j        d          |_        |rt'          | ||           |S )a  
    Load and perhaps export an ONNX model using the Optimum library.

    Args:
        model_name_or_path (str): The model name on Hugging Face (e.g. 'naver/splade-cocondenser-ensembledistil')
            or the path to a local model directory.
        config (PretrainedConfig): The model configuration.
        task_name (str): The task name for the model (e.g. 'feature-extraction', 'fill-mask', 'sequence-classification').
        model_kwargs (dict): Additional keyword arguments for the model loading.
    r   N)ONNX_WEIGHTS_NAMEORTModelForFeatureExtractionORTModelForMaskedLM!ORTModelForSequenceClassificationzfeature-extractionz	fill-maskzsequence-classification, Unsupported task: . Supported tasks: zUsing the ONNX backend requires installing Optimum and ONNX Runtime. You can install them with pip: `pip install sentence-transformers[onnx]` or `pip install sentence-transformers[onnx-gpu]`providerONNXz*.onnx	file_namer   exportonnx	subfolder)onnxruntimeoptimum.onnxruntimer   r   r   r   joinkeys
ValueErrorModuleNotFoundError	Exceptionpopget_available_providersr   existsr   from_pretrainedr   _save_pretrainedr   )r	   r   r   model_kwargsortr   r   r   r   task_to_model_mappingsupported_tasks	model_cls	load_pathis_localbackend_nametarget_file_globr   models                     ]/root/projects/butler/venv/lib/python3.11/site-packages/sentence_transformers/backend/load.pyload_onnx_modelr5      s    
!!!!	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 #?,'H!
 !
 111"ii(=(B(B(D(DEEOa)aaP_aabbb))4		 
 
 
?
 
 	

  ,//
C<W<W<Y<YZ[<\]]L'((I!!HL 18\+<>NP\ FL
  ,d+++ &I%  	 E 6e6LX^___E  I/<HHHLs   AA! !A;c                P   	 ddl m}m}m}m} |||d}||vr<d                    |                                          }	t          d| d|	           ||         }
n# t          $ r t          d          w xY wt          |           }|                                }d}d	}t          ||||||          \  }}|r|                    d
d           d|v r|d         }t          |t                    spt          |                                          st          d          t!          |d          5 }t#          j        |          |d<   ddd           n# 1 swxY w Y   ni |d<    |
j        | f||d|}t)          |j        d          |_        |rt-          | ||           |S )a  
    Load and perhaps export an OpenVINO model using the Optimum library.

    Args:
        model_name_or_path (str): The model name on Hugging Face (e.g. 'naver/splade-cocondenser-ensembledistil')
            or the path to a local model directory.
        config (PretrainedConfig): The model configuration.
        task_name (str): The task name for the model (e.g. 'feature-extraction', 'fill-mask', 'sequence-classification').
        model_kwargs (dict): Additional keyword arguments for the model loading.
    r   )OV_XML_FILE_NAMEOVModelForFeatureExtractionOVModelForMaskedLM OVModelForSequenceClassificationr   r   r   r   zUsing the OpenVINO backend requires installing Optimum and OpenVINO. You can install them with pip: `pip install sentence-transformers[openvino]`OpenVINOzopenvino*.xmlr   N	ov_configzXov_config should be a dictionary or a path to a .json file containing an OpenVINO configzutf-8)encodingr   openvinor   )optimum.intel.openvinor7   r8   r9   r:   r    r!   r"   r#   r$   r   r'   r   r%   
isinstancedictopenjsonloadr(   r   r)   r   )r	   r   r   r*   r7   r8   r9   r:   r,   r-   r.   r/   r0   r1   r2   r   r<   fr3   s                      r4   load_openvino_modelrF   Z   s   
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 #>+'G!
 !
 111"ii(=(B(B(D(DEEOa)aaP_aabbb))4		 
 
 
[
 
 	

 '((I!!HL& 18\+;=M| FL
  ,d+++ l"" -	)T** 	9	??))++  n   i'222 9a,0IaLL[)9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 %'[! &I%  	 E 6e6LXbcccE  I/<HHHLs   AA A72EEE)r	   r
   r   r   r   r
   )
__future__r   rC   loggingpathlibr    transformers.configuration_utilsr   #sentence_transformers.backend.utilsr   r   r   	getLogger__name__loggerr5   rF        r4   <module>rQ      s    " " " " " "         = = = = = = u u u u u u u u u u		8	$	$I I I IXQ Q Q Q Q QrP   