Expand description
The .psk.d data container and the training data pipeline.
A .psk.d file is a sequence of samples of one Presk type:
magic "PSKD" 4 bytes
version u16 = 1 little-endian
type_len u32, then the type, UTF-8 the sample type in Presk syntax
count u64 number of samples
data the samples, back to back: the leaves of the type in order,
idx[N] as the smallest of u8/u16/u32/u64 holding N−1,
ℝ as f64 little-endianVersion 2 (plan 0.17.0 step 7, D180) adds, after the count, one byte per leaf in storage order, the leaf’s encoding:
leaves u32 number of leaves of the type
encodings u8 per leaf 0 f64 (and every idx), 1 f32, 2 bf16and stores each real leaf in its encoding, little-endian (bf16 as the
upper sixteen bits of an f32). Every number of f32 and of bf16 is
a number of f64, so a leaf is read exactly whatever its encoding. A
writer writes version 1 unless a leaf is narrower, so that a file of
f64 leaves is the same bytes as before.
Real values are f64 and are injected exactly into ℝ when read (the
hyperparameter rule of the language). The type is parsed with the Presk
parser; a closed type (every dimension a literal) gives the leaf layout
directly. A params M type needs the program to know its layout: the
reader then returns the header only, and the caller supplies the
Layout with Reader::with_layout.
Errors carry a code: E9001 (type not closed or not a data type),
E9002 (not a .psk.d file), E9003 (truncated), E9004 (a value out
of its bound or unparsable), E9005 (type mismatch).
Structs§
- Data
Error - Header
- Pipeline
stream … |> shuffle(seed) |> batch(B) |> take(n)over sample indices.- Reader
- A reader with random access to samples (fixed sample size).
Enums§
- Enc
- How a real leaf’s elements are stored (version 2). Each is exactly a
number of
f64. - Layout
- The leaf structure of a sample type, in the order the leaves are stored.
- Leaf
- One tensor leaf of a sample type.
- Value
- One sample: the same tree as its
Layout, with flat row-major data per leaf.
Constants§
- MAGIC
- VERSION
- The version a file of
f64leaves is written in. - VERSION_
ENCODED - The version of a file with a leaf narrower than
f64.
Functions§
- char_
vocab - The character vocabulary of a text: every distinct character, sorted, one
token each. Tokens are
Strings so that the same format can later hold sub-word tokens; indexidenotesvocab[i]. - decode_
text - Decode a token stream back to text (the inverse of
encode). - encode
- Encode a text against a vocabulary. Only single-character vocabularies are
supported: sub-word tokens need longest-match encoding, which comes with
presk data bpe. - idx_
width - The width of an
idx[N]element: the smallest unsigned integer holdingN−1. - info
presk data info: the header and the firstnsamples.- lm_
windows - Language-modelling windows of a token stream: sample
kis(tokens[k·stride .. +seq], tokens[k·stride + 1 .. +seq]), of type(idx[vocab][seq: T], idx[vocab][seq: T]). - shuffle_
indices - A permutation of
0..nfromseedand the epoch (1-based): the same on every machine, different for every epoch. - write
- Writes a
.psk.dfile:sample_tyis the header text,layoutits leaf structure (needed forparams M, whose layout the text does not give). - write_
encoded - [
write], each real leaf in its encoding (encsin storage order, empty for every leaf inf64). The file is version 2 when a real leaf is narrower thanf64, and version 1 otherwise, byte for byte what [write] writes. A value that is not a number of its leaf’s encoding is refused (E9004): the file holds the numbers it is given, exactly.