
    %h              
          S SK r S SKJrJrJr  S SKrS SKJr  S SK	J
r
  S SKJrJr  SS\\\
4   S\\\\4      S\4S jjr SS\\\
4   S	\\\ R                   4   S\\\\4      SS4S
 jjrS\S\\\
4   4S jrS	\\\ R                   4   S\\\
4   4S jrS\\\R(                  4   S\\\
4   4S jrS\\\
4   S\\\R,                  4   4S jrg)    N)DictOptionalUnion)Array)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, Array]`):
        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.flax import save
from jax import numpy as jnp

tensors = {"embedding": jnp.zeros((512, 1024)), "attention": jnp.zeros((256, 256))}
byte_data = save(tensors)
```
r
   )_jnp2npr   save)r	   r
   
np_tensorss      H/var/www/auris/envauris/lib/python3.13/site-packages/safetensors/flax.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, Array]`):
        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.flax import save_file
from jax import numpy as jnp

tensors = {"embedding": jnp.zeros((512, 1024)), "attention": jnp.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 flax format from pure bytes.

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

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

Example:

```python
from safetensors.flax import load

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

loaded = load(data)
```
)r   load_np2jnp)r   flats     r   r   r   K   s    . ::dD4=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)aw  
Loads a safetensors file into flax format.

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

Returns:
    `Dict[str, Array]`: dictionary that contains name as key, value as `Array`

Example:

```python
from safetensors.flax import load_file

file_path = "./my_folder/bert.safetensors"
loaded = load_file(file_path)
```
flax)	frameworkN)r   keys
get_tensor)r   resultfks       r   	load_filer#   f   sP    ( F	8v	.!AQFI  
/ M 
/	. Ms   +A
A
numpy_dictc                 h    U R                  5        H  u  p[        R                  " U5      X'   M     U $ N)itemsjnparray)r$   r"   vs      r   r   r      s,      "		!
 #r   jnp_dictc                 h    U R                  5        H  u  p[        R                  " U5      X'   M     U $ r&   )r'   npasarray)r+   r"   r*   s      r   r   r      s)     jjm !Or   r&   )ostypingr   r   r   r   r-   	jax.numpyr(   jaxr   safetensorsr   strbytesr   PathLiker   r   r#   ndarrayr   r)   r    r   r   <module>r9      s<   	 ( (    (5$sEz" 5htCH~.F 5RW 5@ *. D#u* DC$% D tCH~& D 
	 DFu c5j) 6c2;;./ De4D 6S"**_- $sEz2B d3:& 4RXX+> r   