PredictionsWriter#
- class ibl_bwb_eval.predictions.PredictionsWriter(enable, base_path, task, seed, label=None, rank=0, metadata=None, path_fn=None)[source]#
Bases:
objectBuffer tensors from an eval loop and save them as a
.safetensorsfile.The output path is structured as:
base_path / label / task / [path_fn(metadata)] / seed_{seed}.safetensors
path_fnis a callable that receives the accumulated path andmetadata, and returns a middle segment of the path. This lets each task suite define its own sub-hierarchy (e.g. a recording id).metadatais also embedded in the file header alongside the common fields (label,task,seed) andibl_bwb_eval_version,ibl_bwb_eval.__version__at write time, which traces a submission back to the writer that produced it. Read that one back withversion_of().Fields are recorded in one of two ways:
add()appends a per-batch chunk; repeated calls for the same key are concatenated along dim 0 at save time.set()stores a single value once, for a field that is constant across batches or already aggregated.
All values must be
torch.Tensor. They are detached and moved to CPU on ingest. Floating-point tensors are cast tofloat32by default; passdtype=toadd()/set()to use a lower-precision dtype instead (e.g.torch.float16for bulky prediction tensors), avoid this for fields used for exact alignment (e.g. timestamps), since low precision can collapse distinct values.save()writes on rank 0 only and is a no-op if nothing was recorded.