o
    3IhH                     @   s`   d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 defddZdefd	d
ZdS )    )NumpyHelper)
ModelProtoTensorProto)set_external_data)	OnnxModel)OrtValuemodelc                 C   s   g }t | }| D ]/}|jD ])}|j}|dr8t|}t|}|	||f t
|dd ||_|d qq
t|ddiS )a  
    Extract external data from model and return the external data as a list of tuples (name, value).
    Note this function does not handle external data that is not loaded into the model as raw data.

    Args:
        model (ModelProto): the model proto to extract external data from.
    Returns:
        (external_names, external_values): a tuple of two lists of external data names and values.
    raw_datazfoo.bin)locationstrictF)r   graphsinitializernameHasFieldr   to_arrayr   ortvalue_from_numpyappendr   
ClearFieldzip)r   external_data
onnx_modelgraphr   r   numpy_tensor	ort_value r   c/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/onnxruntime/transformers/onnx_utils.pyextract_raw_data_from_model   s   





r   c                 C   sD   t | }| D ]}|jD ]}|dr|jtjkr  dS qqdS )z
    Check if the model has external data.

    Args:
        model (ModelProto): the model proto to check for external data.
    Returns:
        bool: True if the model has external data, False otherwise.
    data_locationTF)r   r   r   r   r   r   EXTERNAL)r   r   r   r   r   r   r   has_external_data)   s   	
r   N)fusion_utilsr   onnxr   r   onnx.external_data_helperr   r   r   onnxruntimer   r   r   r   r   r   r   <module>   s   