Documentation

Train

Language models

Train
View .mdOpenAPI

Fine-tune a model

Train the Laya page classifier on pages you labelled yourself, so it learns your sites: upload a dataset, start a training job, follow its epochs, keep the model it makes, ft_…. Other bases are listed last.

Status. Fine-tuning is switched on for this service. Fine-tuning has been live since 2026-10-08; upload validation, limits and artifact downloads are included in the implementation reviewed on 2026-10-10.

What you train

In this guide training starts from laya-page-role-base, the classifier's encoder with a fresh head for the five labels, always in this order: detail, listing, landing, not_vacancy, unresolved. A recipe fixes how it trains; you choose a recipe and four options.

RecipeWhat it is
laya-page-role/v2 (the default)AdamW at a learning rate of 2e-5 after 200 warm-up steps, then a linear decay to zero; 8 pages a step; stops early after patience epochs without a better validation score, 3 by default.
laya-page-role/v1The same with a constant learning rate after the warm-up; patience defaults to 10.

v1 is the recipe of the training run of 2026-10-08, whose best epoch was the fourth of ten (validation macro-F1 0.750); v2 adds its two lessons: a decaying learning rate, and stopping after three epochs without improvement.

The dataset

An NDJSON file, one labelled page per line:

json
{"id": "ex-000001", "split": "train", "group_id": "site-0042", "label": "listing", "provenance": {"source": "my crawl"}, "weight": 1.0, "state": "All open positions: 24 results. Filter by city or team."}
FieldRequiredRule
idyesUnique in the file, so that a row can be named in an error (duplicate_example_id).
splityestrain or validation, and you need both: the model learns from the first and is scored on the second (train_and_validation_required). Rows with another split are counted (other_rows) and left out of training, but they still need an id and a group_id.
group_idyesRows that belong together, such as the pages of one site, go in one split. Otherwise the model is scored on pages it has as good as seen, and the score flatters it (group_split_overlap; a row without one: missing_group_id).
labelyesOne of the five labels, and every label appears in both splits, so that each one is learned and scored (missing_label_support:train, missing_label_support:validation).
provenanceyesA JSON object, your own note on where the row came from (invalid_label_or_provenance).
weightnoA positive number, 1 by default; weights are scaled so the training rows average 1 (invalid_example_weight).
stateyesThe page's text.
state_sha256noThe SHA-256 of state; when you give it, it must match (state_digest_mismatch).

The upload checks the dataset rules, refuses blank lines, and names the line and code, never the content. PUT /v1/datasets/{dataset_id}/content also includes a local validation script. A dataset is at most 440 MiB, kept until you delete it, and never written to a log or trace; storage per account and per upload is limited (Errors and limits). A training job names such a dataset by its id; the URIs of data read in place are for ComputePlans.

Upload it

Make the dataset, then send its file to the address the answer gives:

sh
curl -s https://weights.fyi/run/v1/datasets \
  -H "Authorization: Bearer $WEIGHTS_API_KEY" -H "Content-Type: application/json" \
  -d '{"name": "my labelled pages", "format": "laya-page-role/jsonl"}'
curl -s -T dataset.ndjson https://weights.fyi/run/v1/datasets/DATASET_ID/content \
  -H "Authorization: Bearer $WEIGHTS_API_KEY" -H "Content-Type: application/x-ndjson"

The second answer is 200 with status: "ready", the row counts, bytes and sha256; compare the last with shasum -a 256 dataset.ndjson. A refused upload leaves the dataset failed; send the corrected file to the same address. The 161 MB dataset of the live drill uploaded in 41 s on 2026-10-08.

Start the training job

sh
curl -s https://weights.fyi/run/v1/jobs \
  -H "Authorization: Bearer $WEIGHTS_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: finetune-my-pages-1" \
  -d '{"kind": "finetune", "model": "laya-page-role-base", "dataset": "DATASET_ID", "recipe": "laya-page-role/v2", "options": {"epochs": 10, "patience": 3}}'
OptionDefaultAllowed
epochs101 to 10 passes over your training pages.
patiencethe recipe's, 3 or 101 to epochs: how many epochs without a better validation score end the training early. If you ask for fewer epochs than the recipe's patience, give a patience too, or the job is refused with 400 option_out_of_range.
seed1729Any whole number, for the training's random choices.
checkpoint_seconds300From 16.8 (one checkpoint's measured write and sync, 2026-10-08) to 300: how much training a sudden failure can cost at most.

The answer is 201 with job_id and estimate. Your available credit must cover the estimate (402 training_not_covered), which is then set aside while the job is open; GET /v1/quote (finetune) gives it beforehand. A token's daily spend cap holds training too (Prices and billing).

Follow it

GET /v1/jobs/{job_id} answers in training words; state_text says the same for a screen:

stateWhat is happening
queuedWaiting for the model to be ready, for another training job to finish, or for credit (waiting_for says which of the first and the last).
preparingYour data and the base model are being loaded.
trainingSteps are running, each epoch's validation pass included; progress.last_step_at says how fresh the figures are.
movingThe hardware was taken back; the training resumes from its last checkpoint on new hardware by itself.
finishingA stop was asked, yours or because your credit ran out, and the last checkpoint is being saved.
donestatus says SUCCEEDED, FAILED or CANCELLED; the results hold what there is.

progress has the epoch and step, the speed, the best epoch so far with its macro-F1, every finished epoch's score, the last checkpoint, resumes and steps_lost_total; a failed job carries its code in error.

Checkpoints and the move

The training saves a checkpoint every checkpoint_seconds, at every epoch's end, and, when the hardware is taken back with notice, at once. After a move it resumes from the newest complete checkpoint on new hardware by itself. In the drill on the live service on 2026-10-08 we took the hardware away in the middle of epoch 2 of ten: the checkpoint saved on that notice was complete 21 s later, the job showed "Moving to new hardware" for 3 min 37 s, and the training resumed two steps past the last step the service had reported, losing none. Without notice it resumes from the last timed or epoch checkpoint, redoing at most about checkpoint_seconds of training. DELETE /v1/jobs/{job_id} stops it cleanly: 202 while it saves, then CANCELLED with the best model so far.

The model you get

The results (GET /v1/jobs/{job_id}/results) hold every epoch's metrics and the model, the epoch with the best validation macro-F1:

json
{"id": "ft_6e975b0fbd833d058defbbae", "base": "laya-page-role-base", "best_epoch": 4, "best_step": 8916, "macro_f1": 0.743,
 "can_run": false, "note": "Deployment of a trained model is coming."}

That is the drill's model: patience stopped it after epoch 7. It is listed under your models, to you only, and cannot run on the service yet (Bring your own model); its checkpoints are kept, with no call to delete them yet. GET /v1/jobs/{job_id}/model.safetensors downloads its weights, checked against their digest.

What it costs

A fine-tune is charged per training token, as it trains: the tokens of your training pages as the trainer reads them, every epoch, never the validation pass. The estimate assumes about 1,133 tokens a page (a real release, 2026-10-08). A move costs nothing; stopping early saves the skipped epochs (Prices and billing).

Other bases you can train

The same calls train six other kinds of model. Name the base as model, its recipe as recipe, and upload the dataset in that recipe's format; the steps, states, checkpoints and charging are those above.

What you trainmodelrecipeDataset format
The five-label page classifier (this guide)laya-page-role-baselaya-page-role/v2, laya-page-role/v1laya-page-role/jsonl
A Laya specialist: a classifier or an extractor with labels of its ownThe specialist's id, such as laya-link-scorerlaya-specialist/v1laya-specialist/jsonl
The multi-head specialistlaya-specialist-heads-baselaya-specialist-heads/v1laya-specialist-heads/jsonl
A generative student, on chat examplesA student base, such as qwen3.5-4b or gemma3-4blaya-student-lora-sft/v1laya-sft-chat/jsonl
The same student, on preference pairsThe same student baselaya-student-lora-dpo/v1laya-dpo-preference/jsonl
The same student, reinforced by a deterministic verifier (GRPO, plan.rl)The same student baselaya-student-lora-grpo/v1laya-rlvr-prompt/jsonl
The same student, distilled on-policy from a co-resident teacher and verifier (OPD, plan.distill)The same student baselaya-student-lora-opd/v1laya-rlvr-prompt/jsonl

A dataset's labels must be the base's own, else 400 dataset_label_mismatch. A base the recipe does not train answers 400 model_not_available, whose trainable lists the bases it does; GET /v1/quote (finetune) and POST /v1/quote estimate any of them beforehand. GET /v1/models lists only the page classifier's base as trainable today.