# PaddlePaddle API

## PaddlePaddle API

**safetensors.paddle.load\_file**

[\<source>](https://github.com/huggingface/safetensors/blob/main/src/safetensors/paddle.py#L101)

( filename: typing.Union\[str, os.PathLike]device = 'cpu' ) → `Dict[str, paddle.Tensor]`

Parameters

* **filename** (`str`, or `os.PathLike`)) — The name of the file which contains the tensors
* **device** (`Dict[str, any]`, *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`

Loads a safetensors file into paddle format.

Example:

Copied

```
from safetensors.paddle import load_file

file_path = "./my_folder/bert.safetensors"
loaded = load_file(file_path)
```

**safetensors.paddle.load**

[\<source>](https://github.com/huggingface/safetensors/blob/main/src/safetensors/paddle.py#L74)

( data: bytesdevice: str = 'cpu' ) → `Dict[str, paddle.Tensor]`

Parameters

* **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

Loads a safetensors file into paddle format from pure bytes.

Example:

Copied

```
from safetensors.paddle import load

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

loaded = load(data)
```

**safetensors.paddle.save\_file**

[\<source>](https://github.com/huggingface/safetensors/blob/main/src/safetensors/paddle.py#L39)

( tensors: typing.Dict\[str, paddle.Tensor]filename: typing.Union\[str, os.PathLike]metadata: typing.Union\[typing.Dict\[str, str], NoneType] = None ) → `None`

Parameters

* **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`

Saves a dictionnary of tensors into raw bytes in safetensors format.

Example:

Copied

```
from safetensors.paddle import save_file
import paddle

tensors = {"embedding": paddle.zeros((512, 1024)), "attention": paddle.zeros((256, 256))}
save_file(tensors, "model.safetensors")
```

**safetensors.paddle.save**

[\<source>](https://github.com/huggingface/safetensors/blob/main/src/safetensors/paddle.py#L10)

( tensors: typing.Dict\[str, paddle.Tensor]metadata: typing.Union\[typing.Dict\[str, str], NoneType] = None ) → `bytes`

Parameters

* **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

Saves a dictionnary of tensors into raw bytes in safetensors format.

Example:

Copied

```
from safetensors.paddle import save
import paddle

tensors = {"embedding": paddle.zeros((512, 1024)), "attention": paddle.zeros((256, 256))}
byte_data = save(tensors)
```
