
    %hO              
          S SK r S SKJrJrJr  S SKrS SKrS SK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
\S\	S\\	\R                  4   4S jjrSS\\	\ R                  4   S\\	\R                  4   4S jjrSS\\	\R"                  4   S\	S\\	\R                  4   4S jjrS\\	\R                  4   S\\	\R&                  4   4S jrg)    N)DictOptionalUnion)numpytensorsmetadatareturnc                 @    [        U 5      n[        R                  " X!S9$ )a  
Saves a dictionary of tensors into raw bytes in safetensors format.

Args:
    tensors (`Dict[str, paddle.Tensor]`):
        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.paddle import save
import paddle

tensors = {"embedding": paddle.zeros((512, 1024)), "attention": paddle.zeros((256, 256))}
byte_data = save(tensors)
```
r   )
_paddle2npr   save)r   r   
np_tensorss      J/var/www/auris/envauris/lib/python3.13/site-packages/safetensors/paddle.pyr   r   
   s    2 G$J::j44    filenamec                 B    [        U 5      n[        R                  " X1US9$ )a  
Saves a dictionary of tensors into raw bytes in safetensors format.

Args:
    tensors (`Dict[str, paddle.Tensor]`):
        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.paddle import save_file
import paddle

tensors = {"embedding": paddle.zeros((512, 1024)), "attention": paddle.zeros((256, 256))}
save_file(tensors, "model.safetensors")
```
r   )r   r   	save_file)r   r   r   r   s       r   r   r   '   s    > G$J??:(CCr   datadevicec                 D    [         R                  " U 5      n[        X!5      $ )a  
Loads a safetensors file into paddle format from pure bytes.

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

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

Example:

```python
from safetensors.paddle import load

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

loaded = load(data)
```
)r   load
_np2paddle)r   r   flats      r   r   r   J   s    . ::dDd##r   c                 H    [         R                  " U 5      n[        X!5      nU$ )a[  
Loads a safetensors file into paddle format.

Args:
    filename (`str`, or `os.PathLike`)):
        The name of the file which contains the tensors
    device (`Union[Dict[str, any], str]`, *optional*, defaults to `cpu`):
        The device where the tensors need to be located after load.
        available options are all regular paddle device locations

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

Example:

```python
from safetensors.paddle import load_file

file_path = "./my_folder/bert.safetensors"
loaded = load_file(file_path)
```
)r   	load_filer   )r   r   r   outputs       r   r   r   e   s!    . ??8$D%FMr   
numpy_dictc                 d    U R                  5        H  u  p#[        R                  " X1S9X'   M     U $ )N)place)itemspaddle	to_tensor)r   r   kvs       r   r   r      s/      "((9
 #r   paddle_dictc                     U R                  5        H3  u  pUR                  5       R                  5       R                  5       X'   M5     U $ N)r    detachcpur   )r%   r#   r$   s      r   r   r      s:    !!#)//1 $r   r'   )r)   )ostypingr   r   r   r   npr!   safetensorsstrTensorbytesr   PathLiker   r   r   ndarrayr   arrayr    r   r   <module>r5      sh   	 ( (   5$sFMM)* 5htCH~6N 5Z_ 5@ *. D#v}}$% DC$% D tCH~& D 
	 DF$u $c $d33E.F $6c2;;./ $sFMMGYBZ 84RZZ0 # $sTZTaTaOaJb Dfmm!34 c288m9L r   