
    iJ                         d dl Z d dlZd dlmZ d dlmZmZ d dlmZ e	Z
e	Zed         Ze G d d                      Ze G d d	                      Ze G d
 d                      ZdS )    N)defaultdict)	dataclassfield)Literal)
F64F32F16BF16I64I32I16I8U8BOOLc                   x    e Zd ZU dZeed<   ee         ed<   eeef         ed<    e	d          Z
eed<   dd
Zd	S )
TensorInfoa<  Information about a tensor.

    For more details regarding the safetensors format, check out https://huggingface.co/docs/safetensors/index#format.

    Attributes:
        dtype (`str`):
            The data type of the tensor ("F64", "F32", "F16", "BF16", "I64", "I32", "I16", "I8", "U8", "BOOL").
        shape (`list[int]`):
            The shape of the tensor.
        data_offsets (`tuple[int, int]`):
            The offsets of the data in the file as a tuple `[BEGIN, END]`.
        parameter_count (`int`):
            The number of parameters in the tensor.
    dtypeshapedata_offsetsFinitparameter_countreturnNc                     	 t          j        t          j        | j                  | _        d S # t          $ r d| _        Y d S w xY w)N   )	functoolsreduceoperatormulr   r   	TypeError)selfs    c/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/huggingface_hub/utils/_safetensors.py__post_init__zTensorInfo.__post_init__#   sR    	%#,#3HL$*#M#MD    	% 	% 	%#$D    	%s   )- AAr   N)__name__
__module____qualname____doc__DTYPE_T__annotations__listinttupler   r   r#        r"   r   r      s           NNN9S/!!! 5e,,,OS,,,% % % % % %r/   r   c                       e Zd ZU dZeeef         ed<   eeef         ed<    e	d          Z
eeef         ed<   d
d	ZdS )SafetensorsFileMetadataa  Metadata for a Safetensors file hosted on the Hub.

    This class is returned by [`parse_safetensors_file_metadata`].

    For more details regarding the safetensors format, check out https://huggingface.co/docs/safetensors/index#format.

    Attributes:
        metadata (`dict`):
            The metadata contained in the file.
        tensors (`dict[str, TensorInfo]`):
            A map of all tensors. Keys are tensor names and values are information about the corresponding tensor, as a
            [`TensorInfo`] object.
        parameter_count (`dict[str, int]`):
            A map of the number of parameters per data type. Keys are data types and values are the number of parameters
            of that data type.
    metadatatensorsFr   r   r   Nc                     t          t                    }| j                                        D ]}||j        xx         |j        z  cc<   t          |          | _        d S N)r   r,   r3   valuesr   r   dict)r!   r   tensors      r"   r#   z%SafetensorsFileMetadata.__post_init__B   sh    .9#.>.>l))++ 	D 	DFFL)))V-CC))))#O44r/   r$   )r%   r&   r'   r(   r7   strr*   TENSOR_NAME_Tr   r   r   r)   r,   r#   r.   r/   r"   r1   r1   +   s          " 38n-+,,,,*/%U*;*;*;OT'3,';;;5 5 5 5 5 5r/   r1   c                       e Zd ZU dZedz  ed<   eed<   eeef         ed<   eee	f         ed<    e
d          Zeeef         ed	<   ddZdS )SafetensorsRepoMetadataa  Metadata for a Safetensors repo.

    A repo is considered to be a Safetensors repo if it contains either a 'model.safetensors' weight file (non-shared
    model) or a 'model.safetensors.index.json' index file (sharded model) at its root.

    This class is returned by [`get_safetensors_metadata`].

    For more details regarding the safetensors format, check out https://huggingface.co/docs/safetensors/index#format.

    Attributes:
        metadata (`dict`, *optional*):
            The metadata contained in the 'model.safetensors.index.json' file, if it exists. Only populated for sharded
            models.
        sharded (`bool`):
            Whether the repo contains a sharded model or not.
        weight_map (`dict[str, str]`):
            A map of all weights. Keys are tensor names and values are filenames of the files containing the tensors.
        files_metadata (`dict[str, SafetensorsFileMetadata]`):
            A map of all files metadata. Keys are filenames and values are the metadata of the corresponding file, as
            a [`SafetensorsFileMetadata`] object.
        parameter_count (`dict[str, int]`):
            A map of the number of parameters per data type. Keys are data types and values are the number of parameters
            of that data type.
    Nr2   sharded
weight_mapfiles_metadataFr   r   r   c                     t          t                    }| j                                        D ]1}|j                                        D ]\  }}||xx         |z  cc<   2t          |          | _        d S r5   )r   r,   r?   r6   r   itemsr7   )r!   r   file_metadatar   nb_parameters_s        r"   r#   z%SafetensorsRepoMetadata.__post_init__j   s    .9#.>.>!07799 	9 	9M)6)F)L)L)N)N 9 9%~&&&.8&&&&9#O44r/   r$   )r%   r&   r'   r(   r7   r*   boolr:   
FILENAME_Tr1   r   r   r)   r,   r#   r.   r/   r"   r<   r<   I   s          2 TkMMM]J.////%<<====*/%U*;*;*;OT'3,';;;5 5 5 5 5 5r/   r<   )r   r   collectionsr   dataclassesr   r   typingr   r9   rE   r:   r)   r   r1   r<   r.   r/   r"   <module>rI      s        # # # # # # ( ( ( ( ( ( ( (       

V
W % % % % % % % %: 5 5 5 5 5 5 5 5: %5 %5 %5 %5 %5 %5 %5 %5 %5 %5r/   