Skip to content

Utils

flooder.io

IO functionality (for consistent saving).

Copyright (c) 2025 Paolo Pellizzoni, Florian Graf, Martin Uray, Stefan Huber and Roland Kwitt SPDX-License-Identifier: MIT

save_to_disk

save_to_disk(
    obj: Any,
    path: Union[str, Path],
    metadata: bool = True,
    overwrite: bool = False,
) -> None

Save an object to disk using torch.save.

This function saves any Python object to a specified path. If the object is a dictionary and metadata=True, a _meta entry is added to the copy with timestamp and key information. If the file already exists and overwrite=False, an error is raised.

Parameters:

Name Type Description Default
obj Any

The Python object to save (e.g., a tensor, dictionary, or model).

required
path Union[str, Path]

The file path where the object will be saved.

required
metadata bool

Whether to include metadata in the saved file (only applicable if obj is a dictionary). Defaults to True.

True
overwrite bool

Whether to overwrite the file if it already exists. Defaults to False.

False

Raises:

Type Description
FileExistsError

If the file already exists and overwrite is False.

Returns:

Type Description
None

None