Self-paced training with adaptive learning rates and resumable progress.
GPU time costs money. If your model already predicts an example well, why spend another forward pass on it next time? Hajeri Trainer uses the model’s loss to decide what still needs training and how large the next update should be.
The method records low-loss examples in a mastery registry, skips them before the forward pass on later visits, and bypasses whole chunks once every example is mastered. The learning rate adapts to the loss of the examples still training. Checkpoints preserve the mastery registry, optimizer state, and data position so a run can pick up after an interruption.
I’ve used this method across multiple models and training runs. It applies to pretraining from scratch, continued training, and fine-tuning. Bring your own model and data, try it on a small run, and tell us what you observe.
Try it on your model · Read the methodology · Share your run · Star us · Cite this work
- Pre-tokenize and mix the data. Prepare token IDs and loss labels once, mix diverse examples, and keep the same data and labels when resuming.
- Mastery registry. Score each eligible example using its supervised tokens. An example whose loss falls below the threshold enters the registry and is skipped before the forward pass on later visits.
- Chunk bypass. If every example in a chunk is mastered, the trainer skips the whole chunk.
- Resume. The checkpoint restores the current pass and chunk position, so the trainer skips chunks already completed in that pass.
- Adaptive learning rate. Adjust the rate from the loss of the examples still contributing to the update.
The methodology covers masking, the learning-rate rule, how to compare runs, and the historical Operator 1B evaluation.
- Spend less compute on repeat work. Skip later forward passes for mastered examples and bypass fully mastered chunks. That can reduce GPU time and cost. Compare runs at the same held-out quality to see how much it saves on your data.
- Keep progress across interruptions. Resume from the saved chunk position with the mastery registry and training state intact.
- Adapt updates to the data still training. Adjust the learning rate using the losses of the examples that still contribute to updates.
- Pretraining from scratch when the run revisits training data.
- Continued training when adapting an existing model to new data or a new domain.
- Fine-tuning when you want to see which examples still contribute to training on later passes.
The Operator 1B checkpoint u15600 had seen an estimated 17.9B tokens and scored 49.03% on ARC Easy, 62.51% on PIQA, and 52.09% on WinoGrande in project-reported zero-shot evaluations. The full table also includes ARC Challenge and HellaSwag. Benchmark table and context
These are scores from one checkpoint, and the data and other training choices may have influenced them. During my experiments, I also found issues in a separate multi-GPU DDP trainer I built with an AI coding agent. I’m sharing those limits so others can compare runs on their own data and help separate the effect of the method from the data and implementation.
The reference trainer runs on one CPU or CUDA device. Bring a compatible model and tokenizer.
Use Python 3.11 or later. Write one JSON object per line and split the dataset into multiple files for mid-pass checkpoints. Prepare chunks with a mix of categories and difficulties. The script shuffles the chunk order and shuffles the eligible rows within each chunk.
- Pre-tokenized rows. Provide unpadded
input_idswith the matching tokenizer, plus equally long, unshiftedlabels. Use the original token ID where it should contribute to loss and-100elsewhere. Include a turn-ending token if your format needs one. The script shifts labels once and ignores padding. - Text rows. Use
{"text":"..."}or{"prompt":"...","completion":"..."}. Include any separator or role markers in the prompt. The script appends EOS when available. The default scores completion tokens for prompt/completion rows. Use--loss-on allto score both sides. For exact chat formatting or role masks, prepare the token IDs and labels yourself.
python -m pip install torch "transformers>=4.56,<6" filelock
python hajeri-trainer.py --model ./base-model --data ./train-chunks \
--run-dir ./run --passes 2 --stop-after-chunks 1
python hajeri-trainer.py --model ./base-model --data ./train-chunks \
--run-dir ./run --passes 2 --resumeKeep the model and tokenizer files fixed on resume. For a Hub model, pin its commit using --revision. The script checks the JSONL contents and training settings against the saved checkpoint. It saves after each completed chunk, including weights, AdamW state and LR, mastery state, and the next chunk to process. If training stops within a chunk, resume starts again from the last saved chunk boundary. The trained model and tokenizer export to run/model. Choose a small model first. Full-parameter FP32 AdamW and repeated checkpoint writes both have a cost.
The run log shows newly mastered examples, rows filtered by the registry, and whole chunks bypassed. Use --skip-threshold 0 in a fresh run directory to compare with full-data training.
What did your model skip on the second pass? Share the model, threshold, and a line from your training log. Questions and runs where nothing was skipped are welcome. Join the discussion · Report a bug
If Hajeri Trainer is useful to you or you want to follow the work, give the repository a star using the Star button at the top of the page. Hajeri Trainer on GitHub
If you use or evaluate the method, cite Mohamed Al Hajeri, Hajeri Trainer and include the version or commit you used. Citation metadata