training
Use this sub-skill when the task is about bert, BERT, BERTLM, BERTTrainer, model construction, device choice, training, or checkpoint saving.
What this covers
- Instantiate
BERT and BERTLM.
- Build a
BERTTrainer around a DataLoader.
- Choose CPU or CUDA explicitly for a smoke run.
- Save checkpoints and understand the
.ep{epoch} suffix.
- Diagnose hidden-size, attention-head, CUDA, and checkpoint-path errors.
What to do first
- Build or load a valid vocab and corpus first; if those are missing, hand off to
../data-preparation/SKILL.md.
- Use
scripts/train_smoke.py for a safe one-epoch smoke run with explicit device selection.
- Use CPU smoke when you only need a deterministic quick check.
- Use CUDA smoke only when
torch.cuda.is_available() is true and the host really has a compatible GPU setup.
Read these references
references/training-workflow.md: model/trainer flow, device selection, and checkpoint semantics.
references/troubleshooting.md: CLI bool flags, hidden/head mismatch, GPU, memory, and save-path issues.
../data-preparation/SKILL.md: if the corpus or vocab is the actual blocker.
Related scripts
scripts/train_smoke.py: build a tiny dataset, train one epoch, and save a checkpoint.
../../scripts/make_tiny_corpus.py: create a deterministic tiny corpus fixture when you want to run the smoke script against a known input.
Common outputs
BERT.forward() returns the encoded sequence tensor before the language-model heads.
BERTLM.forward() returns next-sentence and masked-language-model log probabilities.
BERTTrainer.save(epoch, file_path) writes file_path + ".ep{epoch}".
BERTTrainer chooses cuda:0 only when CUDA is available and requested.
Boundary reminders
- Do not solve corpus layout or vocab serialization here.
- Do not bury device-selection guidance inside the data-preparation route.
- Keep the route focused on model instantiation, training, and checkpointing.
1---2name: training-63description: "Use BERT-pytorch to instantiate the model, train on a tiny corpus,4 choose CPU or CUDA, and save checkpoints."5disable-model-invocation: true6metadata:7 source: https://skillmd.com/skills/vectorspacelab/training-68 disco-role: operating9license: Apache 2.010---1112# training1314Use this sub-skill when the task is about `bert`, `BERT`, `BERTLM`, `BERTTrainer`, model construction, device choice, training, or checkpoint saving.1516## What this covers1718- Instantiate `BERT` and `BERTLM`.19- Build a `BERTTrainer` around a `DataLoader`.20- Choose CPU or CUDA explicitly for a smoke run.21- Save checkpoints and understand the `.ep{epoch}` suffix.22- Diagnose hidden-size, attention-head, CUDA, and checkpoint-path errors.2324## What to do first2526- Build or load a valid vocab and corpus first; if those are missing, hand off to `../data-preparation/SKILL.md`.27- Use `scripts/train_smoke.py` for a safe one-epoch smoke run with explicit device selection.28- Use CPU smoke when you only need a deterministic quick check.29- Use CUDA smoke only when `torch.cuda.is_available()` is true and the host really has a compatible GPU setup.3031## Read these references3233- `references/training-workflow.md`: model/trainer flow, device selection, and checkpoint semantics.34- `references/troubleshooting.md`: CLI bool flags, hidden/head mismatch, GPU, memory, and save-path issues.35- `../data-preparation/SKILL.md`: if the corpus or vocab is the actual blocker.3637## Related scripts3839- `scripts/train_smoke.py`: build a tiny dataset, train one epoch, and save a checkpoint.40- `../../scripts/make_tiny_corpus.py`: create a deterministic tiny corpus fixture when you want to run the smoke script against a known input.4142## Common outputs4344- `BERT.forward()` returns the encoded sequence tensor before the language-model heads.45- `BERTLM.forward()` returns next-sentence and masked-language-model log probabilities.46- `BERTTrainer.save(epoch, file_path)` writes `file_path + ".ep{epoch}"`.47- `BERTTrainer` chooses `cuda:0` only when CUDA is available and requested.4849## Boundary reminders5051- Do not solve corpus layout or vocab serialization here.52- Do not bury device-selection guidance inside the data-preparation route.53- Keep the route focused on model instantiation, training, and checkpointing.