All pages
Loaders and prepare
train-loader says where training records come from; prepare turns one
batch of them into the model's inputs and the objective's targets. Shapes
are static, so every field declares its shape.
(defvar train-loader
(loader :sources [(files ["data/train.parquet"])]
:fields [(field :tokens :from "input_ids" :dtype :i32 :shape [1025])]
:batch-size 4
:infinite true))
(defun prepare (batch)
(let ((tokens (field batch :tokens)))
(counter :tokens (numel tokens))
(list :inputs (slice tokens 1 0 seq)
:targets (slice tokens 1 1 (+ seq 1)))))
The forms
| form | keywords | notes |
|---|---|---|
loader | :sources :stages :fields :batch-size :shuffle :infinite | :sources, :shuffle and :infinite describe the single main stage; needs :fields and at least one source or stage |
stage | :name :sources :shuffle :infinite | :name defaults to main |
files | a vector of paths, :encoding | one URI per string, no globbing; the encoding is inferred from the name when absent: parquet, jsonl.gz, msgpack.zstf |
manifest | a URI, :split :weight :encoding | an S3 data manifest |
field | a name, :from :dtype :shape | :from defaults to the name, :dtype to :f32, :shape to a scalar |
- An unknown keyword anywhere here is
E-CONTRACT-003, and the fix lists the accepted ones. :shuffle Nis a buffer ofNrows.:batch-sizebelongs to the loader, not the stage: every stage has the same batch size because shapes are static.- A relative path in
filesresolves against the experiment file's directory. Absolute paths ands3://URIs pass through untouched; S3 credentials are in environment. - Use
:stages [(stage :name "easy" ...) (stage :name "hard" ...)]when a curriculum moves between them. - A loader read by an evaluation pass without
:batchesmust be finite. See evaluation passes.
prepare
prepare receives the batch and returns a plist with :inputs and
:targets (E-CONTRACT-004 otherwise).
(field batch :name)reads one field, shaped[batch-size] ++ field-shape. A name the loader does not declare isE-CONTRACT-005, and the fix lists what it declares.:inputsand:targetsare each a tensor or a list of tensors; a list of inputs is spread over the model's parameters.- Any other key of the returned plist is passed to
objectiveandevaluateas a thirdmetadataargument, when they are written with three parameters. eval-prepare, when defined, replacesprepareon every evaluation pass; otherwiseprepareserves both.
prepare is traced into the training graph, so a metric
in it behaves as one in objective.
Counters
(counter :name scalar) declares a progress counter. It belongs in
prepare, where records are counted (E-CONTRACT-010 elsewhere). The
runtime sums it over microbatches and keeps it for the whole run and the
current stage:
ctxoffers it as:nameand:stage-nameto schedules and the curriculum; see ctx.- every step emits
counter/<name>andrate/<name>(per second); see metrics. - the status file and the summary carry the total.
A counter is not a metric: (counter :tokens (numel tokens)) gives a
counter/tokens curve and tokens per second without reporting either. The
runtime itself counts records.
Related: the run file, tensor operations.