
    %h2              
          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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S\\\R&                  4   S\\\R                  4   4S jrS\\\R                  4   S\\\R*                  4   4S jrg)    N)DictOptionalUnion)numpy	safe_open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, tf.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.tensorflow import save
import tensorflow as tf

tensors = {"embedding": tf.zeros((512, 1024)), "attention": tf.zeros((256, 256))}
byte_data = save(tensors)
```
r	   )_tf2npr   save)r   r	   
np_tensorss      N/var/www/auris/envauris/lib/python3.13/site-packages/safetensors/tensorflow.pyr   r   
   s    2 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, tf.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.tensorflow import save_file
import tensorflow as tf

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

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

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

Example:

```python
from safetensors.tensorflow import load

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

loaded = load(data)
```
)r   load_np2tf)r   flats     r   r   r   J   s    . ::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 tensorflow format.

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

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

Example:

```python
from safetensors.tensorflow import load_file

file_path = "./my_folder/bert.safetensors"
loaded = load_file(file_path)
```
tf)	frameworkN)r   keys
get_tensor)r   resultfks       r   	load_filer"   e   sP    ( F	8t	,AQFI  
- M 
-	, Ms   +A
A
numpy_dictc                 h    U R                  5        H  u  p[        R                  " U5      X'   M     U $ N)itemsr   convert_to_tensor)r#   r!   vs      r   r   r      s/      ",,Q/
 #r   tf_dictc                 \    U R                  5        H  u  pUR                  5       X'   M     U $ r%   )r&   r   )r)   r!   r(   s      r   r   r      s&    WWY
  Nr   r%   )ostypingr   r   r   r   np
tensorflowr   safetensorsr   strTensorbytesr   PathLiker   r   r"   ndarrayr   arrayr    r   r   <module>r7      sQ   	 ( (   (5$sBII~& 5(4S>2J 5V[ 5@ *. D#ryy.! DC$% D tCH~& D 
	 DFu c299n- 6c2;;./ Dbii4H 6tCO, c299n1E Dbii( T#rxx--@ r   