Asia/Kolkata
Posts

Fine-Tuning SmolLM2-360M for Grammar Correction That Beats a 770M T5 Model

November 29, 2026
Small grammar tools often force a bad trade. Huge cloud LLMs fix typos well, yet cost cash per call and add lag. Meanwhile, older Seq2Seq nets like grammarly/coedit-large (770M weights) take over 2 GB of FP16 VRAM and still miss simple typos or add words you never asked for. I wanted a net small enough to run locally on a laptop CPU or a light GPU without changing the user's voice. That led to SmolLM2-360M-GEC, a LoRA tune of HuggingFaceTB/SmolLM2-360M-Instruct saved in both FP16 safetensors (~724 MB) and Q8_0 GGUF (~368 MB).

1. Loss Masking and Clean Text Anchors

General chat models love to talk back. Ask a base 360M chat model to fix "Please recieve my sincere appologies for the delay.", and it will either explain the typo or rewrite the whole line into "I'm sorry for the delay." I fixed both habits during LoRA tuning (r = 16, alpha = 32, dropout = 0.05 across all linear layers):
  1. Loss masking on targets only: Every token in the system prompt and user prompt gets a loss label of -100. The net only learns loss on the fixed sentence.
  2. 290K real text pairs: I mixed grammarly/coedit, Cambridge ESL pairs, agentlans/grammar-correction, typo sets, and confusable sound-alike words.
  3. Clean text anchors: I added clean pairs where source == target. That teaches the net to leave good lines untouched.

2. Head-to-Head Against Base SmolLM2 and CoEdit-Large

Even though SmolLM2-360M-GEC uses less than half the weights of coedit-large (360M vs 770M), it needs just ~550 MB VRAM in Q8_0 GGUF. It runs at 120 to 180+ tokens/sec on consumer GPUs, or ~1.2 to 1.4 seconds per line on CPU. More importantly, it beat both baselines on tricky lines:
  • Missing-letter typos: On "Please close the dor.", coedit-large left "dor" broken. SmolLM2-360M-GEC fixed it cleanly to "Please close the door."
  • Double typos: On "Please recieve my sincere appologies for the delay.", the base model changed the wording, and coedit-large missed "appologies". Our tune fixed both typos while keeping the exact words.
  • Subject-verb match: On "Neither of the students have submitted their assignment.", coedit-large added an extra "yet" at the end. Our model changed "have" to "has" and stopped there.
  • Clean lines: "The quick brown fox jumps over the lazy dog." stayed 100% untouched.

3. Running It With transformers or LM Studio

For Python apps, load it with greedy decoding (do_sample=False) and the ChatML stop token so fixes stay deterministic: If you prefer a local desktop setup without Python, drop smollm2_gec_v1.5.gguf into LM Studio or llama.cpp, pick the ChatML template, set temperature to 0.0, and offload all 32 layers into ~550 MB of VRAM. You can pull the model weights, GGUF file, and Jinja template directly from Hugging Face.