LoRA SFT on Apple Silicon
Supervised fine-tuning teaches the model your format and your answers. It is the first training step, and for many tasks the only one.
$ optiq lora train mlx-community/Qwen3.5-4B-OptiQ-4bit \ --data ./my_data \ -o ./my_adapter # See how rank was spread across the layers $ optiq lora info ./my_adapter
The model argument is an OptiQ quant, from Hugging Face or a local folder. The base stays frozen; only the adapter trains, and it is saved in PEFT layout (adapter_config.json and adapters.safetensors) next to a small file recording the rank each layer got.
What the defaults do
- Every block, all seven projections.
--num-layers -1and the full target-module set, the same coverage Unsloth recommends (PEFT's own default for Qwen is only the query and value projections). - Rank 8, scaled by sensitivity. With
--rank-scaling by_bits, layers OptiQ kept at more bits get twice the base rank.constantgives every layer the same rank;by_klfollows the raw sensitivity score. - Loss on the answer only.
--mask-promptis on, so the prompt tokens do not count. With multi-turn data,--all-turns autotrains every assistant turn, not just the last. - Epochs, not steps. Without
--iters, SFT runs three epochs over your data at a learning rate of 2e-4.--num-epochschanges the count;--iterssets an absolute number of steps;--lroverrides the rate. - Sequences up to 512 tokens. Raise
--max-seq-lengthif your examples are longer.
For more capacity, --preset sets rank and alpha together: small (r=8, α=16), default (r=8, α=8), medium (r=16, α=16), large, xl and xxl up to r=128.
$ optiq lora train mlx-community/Qwen3.5-4B-OptiQ-4bit \
--data ./my_data -o ./my_adapter \
--preset medium --num-epochs 2 --max-seq-length 2048
When memory runs short
Sequence length is what fills memory. In order of how much they help:
--max-seq-length: shorter examples, or split long ones.--grad-checkpoint: recompute activations instead of keeping them.--num-layers 16: adapt only the last 16 blocks.--batch-size 1with--grad-accumulation-stepsto keep the effective batch.
At long context the full logit tensor is what runs out first. OptiQ switches to a fused loss on its own once that tensor would pass about 512 MB, so it depends on vocabulary size as well as sequence length (--fused-ce forces it, same gradients). That is how Qwen3.5-4B trains at 8k context on a 24 GB M4. Measured on Qwen3.5-4B-OptiQ-4bit, M3 Max 36 GB, batch 1, all layers, with --grad-checkpoint:
| Context | Step time | Peak memory |
|---|---|---|
| 2,048 | 2.8 s | 7.7 GB |
| 4,096 | 6.7 s | 11.4 GB |
| 8,192 | 45 s | 19.9 GB |
The same run in the Lab
In optiq lab, Fine-tune walks through five steps: base model, dataset, hyperparameters, train, and save. It trains on any OptiQ quant, MLX-native with no PyTorch, and uses the same by_bits rank scaling. The hyperparameter page carries the main fields with the same defaults as the CLI, the train step draws the loss as it goes, and the last step can bundle the adapter with its base and push it to Hugging Face with the token saved in Settings.

Every flag, the rank-scaling benchmark and the full ceiling map are in the LoRA reference.