Forward-Only Search for Adaptive LLM Inference Optimization
This article explains a forward-only search method for choosing which weight matrix to low-rank truncate in a large language model at inference time. The method scores candidates with angular concentration computed from per-component activations, so it needs no backpropagation. The article covers the three-step search pipeline, a comparison with gradient-based and exhaustive search, and engineering concerns including probe data, memory management, post-pruning validation, and versioning.
1. Background: Why Inference-Time Adaptation Is Needed
After a large language model (LLM) goes live, the same set of parameters must serve many tasks: knowledge question answering, multi-hop reasoning, fact verification, bias evaluation, hallucination detection, and information retrieval. These tasks need different internal representations. The traditional approach fine-tunes the model separately for each task. Fine-tuning requires labeled data, backpropagation, and extra GPU memory. Iteration cycles are long, and it is hard to respond to changing needs in a live inference service.
Another approach changes the model structure at inference time. Low-rank approximation is a common technique. It decomposes a weight matrix and keeps only the first few dominant singular directions, approximating the original matrix with fewer parameters. Some studies have observed that pruning certain layers this way can sometimes improve outputs on some tasks. The key questions are three: which layer to choose, which matrix within that layer to choose, and how many ranks to keep.
2. Problem Definition
Assume the model has a set of linear layer weights, W_1 through W_L. The goal is to select one matrix W_k and a retained rank r, so that the pruned model does not regress on the target task, while keeping the search cost under control.
The search space is determined by the number of layers, the matrix types, and the candidate ranks together. Suppose there are 32 layers, 4 matrix types per layer, and 16 candidate ranks per type. The number of combinations already exceeds two thousand. Running a full evaluation for each combination is expensive. The efficiency of the search method therefore matters as much as the quality of the result it selects.
Two mainstream approaches each have weaknesses.
- Gradient-based methods: These compute the gradient of the loss with respect to the parameters. They must store intermediate results from backpropagation, which leads to high peak memory usage.
- Exhaustive methods: These run an actual evaluation for every candidate. The results are reliable, but the computation cost is the highest.
3. Core Idea: Replacing Gradients with Angular Concentration
3.1 Angular Concentration
Angular concentration measures whether the directions of a set of vectors cluster together. Take N samples with hidden states h_n. First normalize each vector to a unit vector, then average them:
R = || (1/N) × Σ h_n / ||h_n|| ||
R ranges from 0 to 1. When the directions agree closely, R approaches 1, which means the vectors are highly concentrated. When the directions are scattered, R approaches 0, which means they are dispersed.
3.2 Component Decomposition Enables Analysis
Apply singular value decomposition (SVD) to a matrix, and it can be written as W = Σ σ_i u_i v_i^T. For an input x, the linear layer output is Wx = Σ σ_i u_i (v_i^T x). Each term is the activation of a rank-one component, and the sum of all components equals the standard forward result exactly.
This identity matters. It means we do not need to change the model’s computation path. By splitting the output into parts, we can observe how each component affects the directional distribution of the hidden states one by one. Some components make the hidden states more concentrated, and others make them more dispersed. Angular concentration is the metric used to quantify this difference.
Note that if a layer includes a bias term, the bias must be handled separately because it does not belong to any singular component.
4. Three-Step Forward Search Pipeline
Step 1: Multi-Component SVD Decomposition
Apply SVD to each candidate weight matrix to obtain components sorted by singular value, from largest to smallest. This step runs only once, and the results can be cached.
Step 2: Forward Pass to Collect Component Activations
Run a forward pass on a small batch of representative samples. Record the activation of each component, a_i = σ_i u_i (v_i^T x). Because the components sum to the standard output, the computation cost of this step is close to normal inference. No backpropagation is required.
Step 3: Compute Angular Concentration and Select a Matrix
For each matrix, compare the angular concentration of the hidden states with all components against the concentration after removing one component. Aggregate these changes into a dispersion score. The matrix with the highest dispersion score is selected, and then rank reduction is applied at the target rank r.
The following is pseudocode that illustrates the logic. It is not a complete implementation:
def forward_search(layers, probe_batch, keep_rank):best_layer, best_score = None, float("-inf")for layer in layers:# Step 1: SVD decomposition, obtaining U, singular values S, and V^TU, S, Vt = svd(layer.weight)# Step 2: Forward pass to collect per-component activations# The sum of components should equal the standard output (bias handled separately)comps = per_component_outputs(U, S, Vt, layer.capture_input(probe_batch))# Step 3: Compute a dispersion score based on angular concentrationscore = dispersion_score(comps, layer.capture_output(probe_batch))if score > best_score:best_layer, best_score = layer, scoretruncate_rank(best_layer, keep_rank)return best_layer
In real engineering work, layer inputs must be captured from the model through hooks. The example above calls them directly for brevity.
5. Comparison with Other Methods
| Dimension | Gradient-based method | Exhaustive method | Forward search method |
|---|---|---|---|
| Signal source | Gradient of the loss with respect to parameters | Actual evaluation of each candidate | Angular concentration of forward activations |
| Requires backpropagation | Yes | No | No |
| Peak memory | High | Low | Low |
| Search cost | Medium | Very high | Low |
| Result reliability | Depends on how well gradients map to the task | Most direct | Depends on a proxy metric |
The source reports the following. Compared with gradient-based methods, forward search has lower peak memory and a higher speedup. Compared with exhaustive methods, it has a higher speedup and comparable accuracy. The source validates the method on datasets covering knowledge reasoning, knowledge intervention, multi-hop reasoning, fact verification, fairness and bias evaluation, hallucination detection, and information retrieval. Readers should use the specific figures in the source. This article does not add any numbers beyond those in the source.
6. Engineering Considerations
6.1 Selecting the Probe Dataset
The probe data needs only a small number of samples, but it must cover typical inputs for the target task. Too few samples make the angular concentration estimate unstable. Samples unrelated to the task make the search results meaningless. Prepare a separate probe set for each task.
6.2 Memory Control
When there are many components, storing all intermediate results at once takes a large amount of GPU memory. A safer approach processes one layer at a time. After computing the score for a layer, release its intermediate tensors immediately, keeping only the final score and the selected result.
6.3 Controlling Computation
For long sequences, you can randomly sample tokens and compute statistics only on the hidden states at some positions. Sampling introduces some error, so run multiple samplings to check whether the results are stable.
6.4 Validation and Rollback After Pruning
The search returns the candidate that is best according to the proxy metric. That candidate is not guaranteed to be best on the task itself. After pruning, check key metrics on a held-out validation set and set up a rollback mechanism. At deployment, save the pruned version and the original version as two configurations that can be switched between.
6.5 Integration with the Inference Service
If different tasks select different matrices, the serving layer must route each request to the matching configuration by task type. Give each configuration a version number. Record the search parameters, the probe data version, and the validation results for every change, so that results can be reproduced and audited.
7. Limitations and Risks
- Angular concentration is a proxy metric. A high score does not guarantee an improvement in task metrics, so the final choice must be verified with task metrics.
- Low-rank pruning loses some information. Long-tail knowledge or rare language patterns may be affected, so use a dedicated evaluation set to check for this.
- The best layer may differ across tasks. A configuration that works across all tasks may not exist, so search must be done separately for each task.
- Online adaptation can make the same input produce different behavior at different times, which affects reproducibility. If the business requires stable results, restrict the conditions that trigger adaptation and log every change.
8. Summary
- Forward search selects a layer and matrix with one forward pass, which avoids the memory cost of backpropagation.
- The components of an SVD sum to the original output. This identity makes per-component analysis possible.
- Angular concentration measures how each component affects the directional distribution of the hidden states. The matrix with the highest dispersion is chosen for pruning.
- Engineering work requires attention to probe data, memory release, post-pruning validation, and version management.
- The method’s effect depends on how well the proxy metric aligns with task metrics, so task-level evaluation must be completed before deployment.
