Token-Level Length Control for LLM Generation: A Value Function Approach
Controlling the output length of large language models has long been a weak spot of autoregressive generation. This article examines why existing length-control methods fall short and introduces a value function–based approach that treats "remaining generation length" as an estimable quantity at every decoding step. It covers the token-level reward construction, the training-label formulation with pseudocode, the four properties that make this approach scalable (annotation-free, dense, unbiased, and extensible), and the practical implications for inference cost, capacity planning, and reasoning accuracy.
Token-Level Length Control for LLM Generation: A Value Function Approach
Why Generation Length Deserves Serious Attention
Tokens are the basic computational unit of modern autoregressive models. Every generated token means one forward pass, additional KV cache memory, accumulated latency, and energy consumption. With the widespread adoption of long chain-of-thought (long-CoT) reasoning and agentic workflows, generation length now directly affects two critical concerns:
First, it is a core variable in inference cost. Online service billing, compute scheduling, and concurrency capacity planning are all fundamentally built around token throughput. A model whose output length cannot be predicted is like a machine whose job duration cannot be estimated — it introduces significant uncertainty into engineering resource planning.
Second, it affects reasoning quality. More tokens mean more “thinking space.” For complex math problems and multi-step planning tasks, sufficient reasoning length often yields higher accuracy. But overly long generations produce redundancy, repetition, and even self-contradiction, wasting compute. The ideal state is a model that generates long when it should be long, short when it should be short — and can be precisely constrained by the caller.
In cost-sensitive deployment scenarios, whether running a self-hosted inference cluster or relying on general-purpose cloud compute services, “how many tokens it takes to solve a given problem” has become a key metric of inference efficiency.
The Common Flaws in Existing Length-Control Methods
Before introducing the new paradigm, it is worth reviewing the three mainstream approaches in the industry — and why none of them is good enough.
1. Sequence-level penalties during training. In the RL post-training stage, a penalty is applied to complete sequences that exceed the target length. The problem is that this signal is sparse and delayed: the model only learns it “went over” after the entire sequence is generated, with no awareness during decoding of how much budget remains. It is like telling students they ran out of exam time only after the exam ends, with no reminders while they answer.
2. Prompt-level instruction constraints. Writing “please answer in no more than 500 words” in the prompt is essentially a plea to the model, with no hard guarantee. In practice, the more precise the length requirement (e.g., “exactly 1024 tokens”), the lower the compliance rate; vague requests like “answer briefly” work somewhat, but fine-grained control almost entirely fails.
3. Pre-decoding length predictors. An auxiliary module predicts roughly how long the generation will be before decoding begins. But it makes only a single, one-shot judgment — once decoding starts, it cannot adjust dynamically. If the prediction is significantly off, the budget either runs out before the content is complete, or generation ends early with substantial waste.
The shared limitation of these methods is that they all operate at the sequence level, while autoregressive decoding itself happens token by token. The granularity of the control signal does not match the granularity of the generation process — this is the fundamental reason length control has never been precise.
The Core Idea: Modeling “Remaining Length” as a Value Function
Looking deeper, value functions have long been proven in reinforcement learning as a powerful tool for modeling “future rewards.” A natural question arises: can “how far we are from the end of generation” also be treated as a value to estimate?
A Length Value Model (LenVM), proposed by a joint academic and industry research team, follows exactly this path. Its construction is remarkably simple:
- Assign a fixed negative reward to every token during generation (e.g., -1 per token);
- Starting from the current decoding position, compute the discounted cumulative sum of future rewards, yielding a value estimate of “remaining generation length”;
- This value serves as a bounded, monotonic proxy signal for remaining token count — the longer the remaining generation, the lower the value; the closer to the end, the closer the value approaches zero.
With this, the model has a clear, quantified estimate of “how much is left” at every decoding step. Length information shifts from being a post-hoc statistic known only after the sequence ends, to a state quantity queryable at every step. This fundamentally resolves the granularity mismatch problem.
The following pseudocode illustrates how training labels are constructed:
# For a complete generated sequence of length L# Immediate reward per token: r_t = -1# Discount factor gamma ∈ (0, 1)def build_value_targets(seq_len, gamma=0.99):targets = []for t in range(seq_len):remaining = seq_len - t # remaining token count# Discounted sum of future rewards — the value label at this positionv = sum(-(gamma ** k) for k in range(remaining))targets.append(v)return targets # monotonically increasing (negative values approach 0),# one-to-one mapping with remaining length
The model’s training objective is to predict the value at the current position, given the context and a length instruction. At inference time, the target length is encoded into the conditional input, and the model perceives its “budget consumption progress” at every decoding step — enabling precise token-level control.
Why This Constitutes “Scalable Value Pretraining”
This construction matters not only for control precision, but because it naturally possesses four properties highly favorable to large-scale pretraining:
1. Annotation-free. Value labels are derived entirely from the sequence’s own length and the discount formula. No human annotation, no reward model scoring, no additional preference data required.
2. Dense signals. Every token position in the sequence has a training label — unlike sequence-level rewards, where one data point yields only a single scalar signal. Training signal density directly determines sample efficiency.
3. Unbiased. Labels are generated by a deterministic mathematical formula, introducing neither annotator subjectivity nor the approximation errors of a reward model.
4. Scalable. The training is essentially a self-supervised process — like pretraining a language model, it keeps improving simply by “feeding more data.” The research team validated scaling behavior along model size, data volume, and sampling count, observing no signs of saturation. This suggests value pretraining could become a new scalable dimension in the pretraining family, alongside next-token prediction.
Experimental Findings and Engineering Implications
Published experimental results highlight several notable findings:
First, small models can outperform much larger closed-source models on length control. After value pretraining, a roughly 3B open-source model comprehensively surpassed several top-tier general-purpose models with orders of magnitude more parameters on precise length-control benchmarks. This is not contradictory: length control is a specialized capability. No matter how strong a model’s general abilities, it cannot execute precisely if it has never modeled remaining length at the token level. This once again confirms that task-aligned training signals matter more than raw parameter scale.
Second, length controllability translates into reasoning accuracy gains. Under the same token budget constraints, a length-aware model can spend its budget where it counts, achieving order-of-magnitude improvements in reasoning accuracy (from roughly 6% to roughly 63% in the reported results). The reason: models without length awareness either exhaust their budget early and are forced to truncate their reasoning chain, or squander their budget on easy problems. With an explicit value estimate, the model can dynamically adjust the depth of its reasoning during decoding.
Third, direct implications for engineering deployment. For inference services running in general-purpose cloud environments, predictable generation length means:
- More accurate capacity planning and queue scheduling: compute resources can be allocated by estimated length, reducing long-tail blocking;
- Finer-grained cost accounting: token budgets can be set per task type, avoiding waste from unproductive generation;
- More reliable service-level guarantees: in latency-sensitive scenarios, a hard length cap translates into a hard latency cap.
Conclusion and Outlook
LenVM’s core contributions can be summarized in two points. First, it moves length modeling from the sequence level down to the token level, using a value function to provide a quantified estimate of “remaining budget” at every decoding step. Second, it demonstrates that value pretraining — as a self-supervised, annotation-free, dense-signal, and scalable training paradigm — has the potential to scale along multiple axes.
From a broader perspective, this work points to a direction worth sustained attention: many of the “control capabilities” of large language models — length, structure, style, cost — may be reformulated as value estimation problems and incorporated into pretraining through self-supervision, rather than relying on patch-style post-training fixes. As inference cost becomes a key constraint on LLM deployment, “letting the model know how much budget it has left” will no longer be a nice-to-have feature, but a foundational capability of efficient inference systems.
