The Trainer pattern
transformers.Trainer is the canonical training loop. You assemble: a model, a tokenizer, a tokenized Dataset, optional metrics, optional callbacks, and a TrainingArguments object. trainer.train() runs; trainer.evaluate() reports; trainer.save_model() persists. The same loop handles fine-tuning, LoRA training, and full pre-training (with appropriate args).
TrainingArguments knobs you'll set 95% of the time
output_dir— checkpoints + tensorboard logs.num_train_epochsormax_steps— budget.per_device_train_batch_size+gradient_accumulation_steps— effective batch.learning_rate,weight_decay,warmup_ratio,lr_scheduler_type— optimization.bf16/fp16— mixed precision.eval_strategy,eval_steps,save_strategy,save_steps— cadence.logging_steps,report_to=['tensorboard', 'wandb']— observability.
What Trainer hides
Distributed setup (single-node multi-GPU "just works" via accelerate), gradient accumulation, mixed precision, gradient clipping, learning-rate scheduling, checkpoint resumption. The price: it's opinionated. For exotic optimizers / non-standard losses, drop down to the raw PyTorch loop — or use trl / peft Trainer subclasses.