
    %hI                        S SK r S SKrS SKJrJrJr  S SKrS SKJ	r	J
r
JrJr  S\R                  S\4S jrSS\\\R                  4   S\\\\4      S\4S	 jjr SS\\\R                  4   S
\\\ R$                  4   S\\\\4      SS4S jjrS\S\\\R                  4   4S jrS
\\\ R$                  4   S\\\R                  4   4S jr\R,                  \R.                  \R0                  \R2                  \R4                  \R6                  \R8                  \R:                  \R<                  \R>                  \R@                  \!S.r"S\S\RF                  4S jr$S\\\R                  4   4S jr%S\R                  S\!4S jr&g)    N)DictOptionalUnion)deserialize	safe_open	serializeserialize_filetensorreturnc                 `    [        U 5      (       d  U R                  SS9n U R                  5       $ )NF)inplace)_is_little_endianbyteswaptobytes)r
   s    I/var/www/auris/envauris/lib/python3.13/site-packages/safetensors/numpy.py_tobytesr   
   s*    V$$/>>    tensor_dictmetadatac           
          U R                  5        VVs0 s H2  u  p#X#R                  R                  UR                  [	        U5      S._M4     nnn[        XAS9n[        U5      nU$ s  snnf )a  
Saves a dictionary of tensors into raw bytes in safetensors format.

Args:
    tensor_dict (`Dict[str, np.ndarray]`):
        The incoming tensors. Tensors need to be contiguous and dense.
    metadata (`Dict[str, str]`, *optional*, defaults to `None`):
        Optional text only metadata you might want to save in your header.
        For instance it can be useful to specify more about the underlying
        tensors. This is purely informative and does not affect tensor loading.

Returns:
    `bytes`: The raw bytes representing the format

Example:

```python
from safetensors.numpy import save
import numpy as np

tensors = {"embedding": np.zeros((512, 1024)), "attention": np.zeros((256, 256))}
byte_data = save(tensors)
```
dtypeshapedatar   )itemsr   namer   r   r   bytes)r   r   kv	flattened
serializedresults          r   saver$      sb    2 `k_p_p_rs_rW[WXggllQWWhqkRR_rIs98J:FM ts   9A&filenamec           
          U R                  5        VVs0 s H2  u  p4X4R                  R                  UR                  [	        U5      S._M4     nnn[        XQUS9  gs  snnf )a  
Saves a dictionary of tensors into raw bytes in safetensors format.

Args:
    tensor_dict (`Dict[str, np.ndarray]`):
        The incoming tensors. Tensors need to be contiguous and dense.
    filename (`str`, or `os.PathLike`)):
        The filename we're saving into.
    metadata (`Dict[str, str]`, *optional*, defaults to `None`):
        Optional text only metadata you might want to save in your header.
        For instance it can be useful to specify more about the underlying
        tensors. This is purely informative and does not affect tensor loading.

Returns:
    `None`

Example:

```python
from safetensors.numpy import save_file
import numpy as np

tensors = {"embedding": np.zeros((512, 1024)), "attention": np.zeros((256, 256))}
save_file(tensors, "model.safetensors")
```
r   r   N)r   r   r   r   r   r	   )r   r%   r   r   r    r!   s         r   	save_filer'   /   sS    : `k_p_p_rs_rW[WXggllQWWhqkRR_rIs9: ts   9Ar   c                 .    [        U 5      n[        U5      $ )a  
Loads a safetensors file into numpy format from pure bytes.

Args:
    data (`bytes`):
        The content of a safetensors file

Returns:
    `Dict[str, np.ndarray]`: dictionary that contains name as key, value as `np.ndarray` on cpu

Example:

```python
from safetensors.numpy import load

file_path = "./my_folder/bert.safetensors"
with open(file_path, "rb") as f:
    data = f.read()

loaded = load(data)
```
)r   _view2np)r   flats     r   loadr+   P   s    . tDD>r   c                     0 n[        U SS9 nUR                  5        H  nUR                  U5      X'   M     SSS5        U$ ! , (       d  f       U$ = f)a  
Loads a safetensors file into numpy format.

Args:
    filename (`str`, or `os.PathLike`)):
        The name of the file which contains the tensors

Returns:
    `Dict[str, np.ndarray]`: dictionary that contains name as key, value as `np.ndarray`

Example:

```python
from safetensors.numpy import load_file

file_path = "./my_folder/bert.safetensors"
loaded = load_file(file_path)
```
np)	frameworkN)r   keys
get_tensor)r%   r#   fr   s       r   	load_filer2   k   sP    ( F	8t	,AQFI  
- M 
-	, Ms   +A
A)F64F32F16I64U64I32U32I16U16I8U8BOOL	dtype_strc                     [         U    $ N)_TYPES)r?   s    r   	_getdtyperC      s    )r   c                     0 nU  HA  u  p#[        US   5      n[        R                  " US   US9R                  US   5      nXQU'   MC     U$ )Nr   r   )r   r   )rC   r-   
frombufferreshape)safeviewr#   r   r    r   arrs         r   r)   r)      sR    F!G*%mmAfIU3;;AgJGq	  Mr   c                     U R                   R                  nUS:X  a  [        R                  S:X  a  ggUS:X  a  gUS:X  a  gUS:X  a  g[        SU 35      e)	N=littleTF|<>zUnexpected byte order )r   	byteordersys
ValueError)r
   rO   s     r   r   r      s_    &&IC==H$	c		c		c	
-i[9
::r   rA   )'osrP   typingr   r   r   numpyr-   safetensorsr   r   r   r	   ndarrayr   r   strr$   PathLiker'   r+   r2   float64float32float16int64uint64int32uint32int16uint16int8uint8boolrB   r   rC   r)   r    r   r   <module>rf      s   	 
 ( (  I IRZZ E d3

?+ xS#X7O [` @ qu;c2::o&;27R[[8H2I;U]^bcfhkck^lUm;	;Bu c2::o. 6c2;;./ Dbjj4I 8 ::::::889988998899
''
((
   $sBJJ/ ;bjj ;T ;r   