Matching Features, Not Tokens: Energy-Based Fine-Tuning of Language Models

Samy Jelassi, Mujin Kwun, Rosie Zhao, Yuanzhi Li, Nicolo Fusi, Yilun Du, Sham M. Kakade, Carles Domingo-Enrich

TL;DR

Standard language model fine-tuning suffers from a fundamental mismatch between token-level training (teacher forcing) and sequence-level deployment. This paper introduces Energy-Based Fine-Tuning (EBFT), a method that aligns the sequence-level feature statistics of model rollouts with ground-truth data. EBFT consistently outperforms supervised fine-tuning (SFT) and matches reinforcement learning with verifiable rewards (RLVR) on downstream tasks—all without needing a task-specific reward model or verifier, while uniquely preserving or even improving the model's underlying language modeling capabilities.

What Problem Does This Paper Address?

Large language models are typically trained using cross-entropy loss under "teacher forcing," where the model predicts the next token given a ground-truth prefix. However, during deployment, the model conditions on its own previous generations. This discrepancy causes a distribution shift: early errors compound over time, leading the model into contexts it rarely encountered during training.

While Reinforcement Learning (RL) fine-tuning can mitigate this by optimizing sequence-level rewards, it typically requires a task-specific verifier (like unit tests for code) or a preference model, which are expensive or impossible to obtain for open-ended tasks. Furthermore, standard RL fine-tuning often suffers from "reward hacking" or distributional collapse, significantly degrading the model's general language capabilities and perplexity.

Figure 1. Feature-matching loss grows with completion length. Conditional feature-matching loss (lower is better) as a function of completion length for Qwen2.5-1.5B fine-tuned with SFT on OpenCodeInstruct (Ahmad et al., 2025). Although this increase is expected even under a perfect model due to growing feature variance, part of the degradation reflects SFT’s inability to calibrate the model’s rollout distribution over long horizons.

Methods

The authors propose Energy-Based Fine-Tuning (EBFT), which replaces heuristic scalar rewards with a dense, sequence-level semantic feedback signal.

  1. Feature-Matching Objective: Instead of matching exact tokens, EBFT minimizes a conditional feature-matching loss. It ensures that the average high-dimensional feature embedding of the model's generated rollouts matches the feature embedding of the ground-truth completion.
  2. Constructing the Feature Map: The features are extracted from a frozen copy of the pre-trained model itself, specifically concatenating normalized intermediate activations from depths of 25%, 50%, and 75%.
  3. On-Policy Optimization: EBFT uses a REINFORCE-style gradient estimator with a Leave-One-Out (RLOO) baseline to update the trainable generator.
  4. Strided Block-Parallel Rollouts: To overcome the computational bottleneck of generating multiple rollouts, the authors implement a parallel decoding scheme using a custom attention mask. This allows the model to concurrently sample rollouts from multiple nested prefixes in a single forward pass.
  5. Feature Whitening: To prevent dominant feature dimensions from overriding the loss, the authors apply an online whitening transformation to the feature space.
Figure 4. Overview of Energy-Based Fine-Tuning (EBFT). For each context c, the generator pθ samples n completions. A frozen feature network ϕ embeds each prompt–completion pair, producing features ϕ(c: ˆyj) for the sampled completions and ϕ(c:y) for the ground truth. Each completion receives a feature-matching reward measuring alignment with the ground-truth feature moment, and the generator is updated via REINFORCE with an RLOO baseline.

Datasets

The method was evaluated across three distinct domains:

  • Q&A Coding: Trained on a 100k-sample subset of OpenCodeInstruct and evaluated on HumanEval, MBPP, and MultiPL-E.
  • Unstructured Coding: Trained on a 40k-sample subset of SwallowCode (raw Python code scraped from GitHub without instructions), serving as a non-verifiable task where RLVR cannot be applied.
  • Translation: Trained on a 100k subset of ALMA-Human-Parallel and evaluated on WMT’22, MTNT (noisy Reddit comments), and OpenSubtitles.

Key Insights and Ideas

  • The Perplexity Paradox: Remarkably, EBFT achieves lower validation cross-entropy than SFT, even though SFT explicitly optimizes for cross-entropy. Because whitened feature matching mathematically approximates a sequence-level cross-entropy in the fine-tuning regime, it calibrates long-horizon rollouts much more effectively than token-level supervision.
  • Dense Semantic Feedback without Verifiers: Traditional RL treats rewards as a scalar. EBFT treats the reward as a high-dimensional vector alignment problem. By using the model's own internal representations as the feature space, it gains a dense semantic signal without needing human annotators or test suites.
  • Mitigating Distributional Collapse: While standard RL fine-tuning (RLVR) improves task accuracy at the expense of massive perplexity degradation, EBFT avoids this tradeoff entirely. It acts as an exponential tilt of the base distribution, keeping the model well-calibrated.

Key Results

The authors evaluated EBFT using Qwen2.5-1.5B (for coding) and Llama3.2-1B (for translation).

  • Coding Performance: On Q&A coding, EBFT achieved a greedy accuracy of 0.548 on HumanEval, outperforming SFT (0.483) and matching/exceeding RLVR (0.535).
  • Unstructured Coding: In settings without a verifier, EBFT dominated SFT across all metrics (e.g., HumanEval pass@16 of 0.769 vs. 0.747 for SFT).
  • Language Calibration: On translation tasks, EBFT achieved the lowest validation cross-entropy (1.670) compared to SFT (1.782) and RLVR (2.454), while simultaneously outperforming both on out-of-distribution translation benchmarks like MTNT.
Figure 3. EBFT improves downstream performance without sacrificing distributional calibration. From left to right, we plot HumanEval accuracy (greedy and pass@16), validation cross-entropy (CE), and conditional feature-matching (CFM) loss over training for Qwen2.5-1.5B fine-tuned on OpenCodeInstruct (Ahmad et al., 2025). SFT improves cross-entropy and CFM loss but lags on downstream accuracy. RLVR improves downstream accuracy but substantially degrades both calibration metrics relative to the base model (dashed line). EBFT achieves the best results across all four metrics, avoiding this tradeoff. CE and CFM losses are computed on a 1k-samples held-out subset of OpenCodeInstruct.

Limitations and Future Work

  • Computational Overhead: Because EBFT relies on generating on-policy rollouts during training, it is significantly slower per gradient update than standard SFT (e.g., 36 hours for EBFT vs. 0.5 hours for SFT on an identical setup).
  • Scale and Horizon Constraints: The method has currently only been validated on models up to 7B parameters and with relatively short rollout horizons (e.g., 4 to 8 tokens during training). Scaling to longer generation horizons remains an open engineering challenge.
  • Static Feature Space: EBFT relies on a frozen feature network. Future work could explore adaptive or jointly learned feature networks to capture even richer semantic properties.

Summary updated

BibTeX
@inproceedings{jelassi2026matching,
  author = {Samy Jelassi and Mujin Kwun and Rosie Zhao and Yuanzhi Li and Nicolo Fusi and Yilun Du and Sham M. Kakade and Carles Domingo-Enrich},
  title = {{Matching Features, Not Tokens: Energy-Based Fine-Tuning of Language Models}},
  booktitle = {RLxF @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=j84PUOzLUe},
}
Figure