mlx-optiq
Fine-tuning · Small datasets

NEFTune and early stopping

Small datasets overfit. These two flags push back from different sides: NEFTune makes the training signal noisier, and early stopping ends the run when it stops helping. Both are off by default.

NEFTune

NEFTune (Jain et al. 2023) adds uniform noise to the token embeddings during the SFT forward pass, scaled by alpha / sqrt(seq_len × embed_dim). The adapter can no longer memorize the exact surface form of a few hundred examples, which tends to improve instruction-following. Nothing changes at inference.

neftune.shbash
$ optiq lora train mlx-community/Qwen3.5-4B-OptiQ-4bit \
    --data ./my_data -o ./my_adapter \
    --neftune-noise-alpha 5

The paper suggests alpha between 5 and 15. It applies to SFT only, as in TRL, and the noise is switched off during validation, so the loss you watch is measured on clean embeddings.

Early stopping

Validation loss falls, bottoms out, then rises for three evaluations; training stops and the best adapter is kept.vallossevaluations, every --steps-per-evalpatience 3eval 1eval 2eval 3eval 4eval 5eval 6eval 7eval 8eval 9best: promotedto the adapterstop
Validation runs every --steps-per-eval steps. After three evaluations with no improvement, training stops and the best adapter, not the last, is what you get.

--early-stopping-patience N stops the run once validation loss has not improved for N evaluations in a row. --early-stopping-min-delta sets how much it has to drop to count, so small wobbles do not keep a run alive. It needs a valid.jsonl; without one the flag does nothing and says so.

When it fires, the best-validation adapter becomes the returned adapter. OptiQ keeps a copy of the best checkpoint in a best/ folder inside the adapter in every run, whether or not early stopping is on.

early-stop.shbash
$ optiq lora train mlx-community/Qwen3.5-4B-OptiQ-4bit \
    --data ./my_data -o ./my_adapter \
    --steps-per-eval 50 \
    --early-stopping-patience 3 --early-stopping-min-delta 0.01 \
    --neftune-noise-alpha 5

Watching the run

--report-to wandb streams train and validation metrics to Weights & Biases (install wandb and log in first), with --wandb-project to name the project. swanlab works too, and you can pass both separated by a comma. They run beside the terminal log and the Lab's live chart.