Hugging FaceBernardo França de Aguiar, Gabriel Pimenta de Freitas Cardoso, Bruno Duarte, Francisco de Almeida Rocha AlvesProblem & solution
How Specializing the Vocabulary of SLMs Can Cut Inference Cost by 77% in Real Applications
Summary
The post describes how specializing the vocabulary of a small language model cut inference cost by 77% in a Portuguese essay grader built on Qwen3-4B. The original general-purpose tokenizer fragmented domain text and included unused tokens, wasting compute. The authors developed VocabX, which rebuilds the tokenizer by weighting token cost based on whether tokens appear in input or output, since generated tokens cost 7.4 times more due to memory bandwidth limits. VocabX works on sub-word and multi-word layers, reducing vocabulary from 151,669 to about 65,000, and outperformed three reference methods across five domains and three model families. In the grader, it reduced response tokens from 350 to 101, cut cost by 77%, and improved quality from 0.703 to 0.810, though compressing the grade into a macro token hurt quality.
Context
The tokenizer is typically treated as a fixed property of a base model, but for domain-specific models it can be a major cost lever. This post previews the VocabX method, which rebuilds the tokenizer to minimize inference cost by weighting token cost based on whether tokens appear in input or output, and by reducing vocabulary size.
Approach / What changed
VocabX rebuilds the tokenizer using a cost-weighted criterion instead of frequency. It works on two layers: sub-word merging to reduce fragmentation, and multi-word macro tokens for repeated spans. Both layers are selected under the same cost criterion with a budget. The vocabulary size is reduced by removing unused entries. Applied to a Portuguese essay grader on Qwen3-4B, vocabulary was reduced from 151,669 to about 65,000.
Takeaways
Generated tokens cost significantly more than input tokens due to memory bandwidth limits in the decode phase; in the grader, a generated token cost 7.4 times a read token.
VocabX reduces inference cost by rebuilding the tokenizer with a cost-weighted criterion, reducing both token count and vocabulary size, and it outperformed three reference methods in all tested combinations.
Compressing repeated spans into macro tokens can hurt quality if the span includes the decision the model makes; separating the grade from the JSON envelope improved quality and cost.
FAQ
How does VocabX differ from existing vocabulary adaptation methods?
VocabX uses a cost-weighted criterion instead of frequency, and works on both sub-word and multi-word layers simultaneously, unlike methods that only do one or the other.
Why did the fused macro token version hurt quality in the grader?
When the grade was inside the macro token, the model chose both the grade and structure in a single step, reducing accuracy. Separating the grade into its own token cost 2 extra tokens but improved quality.
What was the measured cost reduction in the grader?
VocabX cut inference cost by 77%, reducing average response tokens from 350 to 101, and improved the bench score from 0.703 to 0.810.
Source and freshness
- Source
- huggingface.co
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.