afnio.serialization#
Functions
|
Loads an object from a disk file using zip compression and pickle serialization. |
|
Saves an object to a disk file using zip compression and pickle serialization. |
- afnio.serialization.load(f)[source]#
Loads an object from a disk file using zip compression and pickle serialization.
- Parameters:
f (
Union[str,PathLike,BinaryIO,IO[bytes]]) – A file-like object (must implement read) or a string or os.PathLike object containing a file name.- Returns:
The deserialized object.
Example
>>> # Load from file >>> obj = hf.load('model.hf') >>> # Load from io.BytesIO buffer >>> buffer = io.BytesIO() >>> obj = hf.load(buffer)
- afnio.serialization.save(obj, f, pickle_protocol=2)[source]#
Saves an object to a disk file using zip compression and pickle serialization.
- Parameters:
Note
A common Afnio convention is to save variables using .hf file extension.
Example
>>> # Save to file >>> x = hf.Variable(data="You are a doctor.", role="system prompt") >>> hf.save(x, 'variable.hf') >>> # Save to io.BytesIO buffer >>> buffer = io.BytesIO() >>> hf.save(x, buffer)