Loading a base model
Two main paths — full precision (fp16/bf16) for full fine-tuning or LoRA, and 4-bit quantized for QLoRA.
Tokenizer setup
The tokenizer is just as important as the model. Two non-obvious things you must do:
- Set a padding token: many base tokenizers don't have one. Use
tokenizer.pad_token = tokenizer.eos_tokenas a sane default. - Use
apply_chat_template(): every modern model ships its own chat template (Jinja2). Always format withapply_chat_templateinstead of hand-crafting the prompt — it handles special tokens, system messages, and model-specific formatting correctly.