Skip to main content
A .serva file is bytes on disk like any other file. Unpacking means loading those bytes into something you can compute on, so a training job or an analysis can read the file as it stands. Dependencies: none for reading the bytes, numpy and torch for the sections that use them.

Open one file

Path.read_bytes returns the whole file as a bytes object. There is no reader to install and no password to supply, because nothing is being decoded at this point.

Into a NumPy array

Bytes map straight onto uint8, one value per byte, in the range 0 to 255.
np.frombuffer does not copy, so the array is a view over the bytes you read. Call .copy() if you plan to write to it.

Into a PyTorch tensor

Same idea, with one wrinkle worth knowing.
The bytearray is worth keeping. read_bytes hands back an immutable bytes object, and PyTorch has no read only tensor, so passing one straight in warns that the tensor can write into a buffer that is meant to be immutable. Wrapping it gives PyTorch a buffer it is allowed to own and the warning goes away. Cast to float() when your model wants floats.

The blocks inside

Everything above treats the file as one flat run of bytes. get_blocks reads its structure instead it slices the container on disk and returns each block’s hypervector as uint8. No request, no key, and nothing is decoded.

A folder of files

One file is easy. A dataset is where the real work is, because every .serva file has a different length and nothing stacks into a batch until they all match. Start by looking at the spread:
The simplest thing that works is to pad every file to the largest one:
That is fine when your files are roughly the same size. When they are not, it is wasteful: a set whose largest file is ten times the median spends most of its memory on zeros. Two ways out:
  • Pick a fixed width and pad or truncate to it. Cheap and predictable, but anything past the cut is thrown away, so choose it from the size spread rather than by guessing.
  • Pad per batch instead of per dataset, to the longest file in that batch only, and carry a mask marking which positions are real. Keeps every byte and adds the least padding possible.
Whichever you choose, keep the padding value at zero and stay consistent across train and validation. A model that learns where the padding starts is learning file size, not content.

Or let the SDK do it

ServaDataset in the Python SDK does everything above for you: it walks the folder, reads each file, handles the length problem, and hands your loader a tensor.
Class subfolders become labels, a flat folder gives you bare tensors, and length=None with pad_collate is the per batch padding described above. The PyTorch page covers the options in full.

Where to go next