Exploiting Edited Large Language Models as General Scientific Optimizers

Qitan Lv, Tianyu Liu, Hong Wang

Abstract

Recent advancements in Large Language Models (LLMs) have positioned them as potential catalysts for scientific discovery. However, using LLMs as iterative optimizers typically relies on prompt-based feedback loops, which suffer from context-window limitations and high sensitivity to prompt engineering. This paper presents General Scientific Optimizers (GSO), a framework that replaces long-context prompting with direct model editing. By internalizing experimental feedback into the model's weights, GSO overcomes the "lost-in-the-middle" problem and demonstrates state-of-the-art performance across diverse scientific domains, including combinatorial optimization, physical law discovery, and molecular property prediction.

Introduction

In scientific research, optimization is an iterative process: a hypothesis is proposed, tested via simulation or experiment, and refined based on the results. While LLMs excel at reasoning, their application as optimizers has been bottlenecked by the "prompt-only" paradigm. In this traditional setup, every previous iteration's feedback is appended to the prompt. This leads to two primary failures:

  1. Lost-in-the-Middle: LLMs often struggle to utilize information buried in the center of long prompts, causing them to lose the trajectory of the optimization.
  2. Prompt Sensitivity: Small variations in feedback formatting can lead to inconsistent or degraded performance.

To address these issues, the GSO framework introduces a bi-level optimization strategy that treats the LLM's internal parameters as a dynamic knowledge base, updated through model editing rather than context expansion.

The GSO Framework

GSO operates through a continuous loop between a numerical simulator and an LLM acting as the "scientist."

Bi-Level Optimization

  • Inner-Level (The Simulator): This component acts as the experimental platform. It evaluates the solutions proposed by the LLM and returns quantitative feedback, such as loss values or physical properties.
  • Outer-Level (The LLM): The LLM analyzes the feedback to generate new, improved hypotheses.

Model Editing via Knowledge Triples

The core innovation of GSO is the use of model editing techniques, such as ROME and MEMIT, to inject simulation results directly into the LLM’s MLP layers. Feedback is converted into "knowledge triples" (e.g., [Path A, has distance, 108]). By updating the model's weights, the optimization history is stored internally. This keeps the input prompt concise and ensures the model retains a robust "memory" of the search space without being constrained by the context window.

Dynamic Exploration and Exploitation

To mimic the heuristic strategies of human researchers, GSO employs a dynamic decoding temperature. When the simulator reports a decrease in loss (success), GSO lowers the temperature to "exploit" the current local region. Conversely, if the loss increases, the temperature is raised to encourage "exploration" of new, potentially better regions of the search space.

Experimental Evaluation

The researchers evaluated GSO across seven distinct scientific tasks using six open-source LLM backbones, including Llama 3 (8B), Mistral (7B), and InternLM (7B). The tasks spanned several disciplines:

  • Mathematics & Logic: Linear System Regression (LSR) and the Traveling Salesman Problem (TSP).
  • Physics: Identifying linear and non-linear constitutive laws for elastic materials.
  • Chemistry: Predicting molecular properties (HOMO, LUMO, and the HOMO-LUMO gap) using the QM9 dataset.

Key Results

GSO consistently outperformed six established baselines, including OPRO, Eureka, and Funsearch, across all tested tasks and model backbones.

Precision and Optimality

In molecular property prediction, GSO achieved a remarkable 32.6x precision improvement over existing methods when utilizing the Mistral 7B backbone. In combinatorial optimization (TSP), GSO reached a 0.0 optimality gap on several instances where prompt-based methods failed to find the global optimum.

Generalization vs. Memorization

A critical concern with LLMs in science is whether they are truly optimizing or simply recalling training data. The authors conducted a case study involving an "imaginary" physical law that does not exist in reality. GSO successfully optimized this law, proving its ability to perform genuine scientific discovery rather than relying on memorized information.

Efficiency

While model editing introduces a slight computational overhead (approximately 7.75 seconds per sample), it significantly reduces the token count per iteration. This leads to higher overall inference efficiency compared to methods that require processing massive, ever-growing prompts.

Discussion and Limitations

Despite its success, GSO currently requires "white-box" access to model weights to perform editing. This limits its immediate application to open-source models and excludes closed-source APIs like GPT-4o or Claude. However, the study demonstrated that a GSO-enhanced Mistral 7B can outperform a base GPT-4o on these specific optimization tasks, suggesting that weight-editing is a more powerful lever than model scale alone.

Future work will focus on scaling GSO to higher-dimensional optimization tasks and exploring more efficient inference strategies, such as speculative decoding, to further reduce the computational cost of the editing process.

Conclusion

The GSO framework represents a shift in how LLMs are integrated into the scientific method. By moving from external prompts to internal weight updates, GSO provides a robust, generalizable, and highly precise tool for scientific optimization, overcoming the fundamental limitations of context-based learning.

Summary updated

BibTeX
@inproceedings{lv2025exploiting,
  author = {Qitan Lv and Tianyu Liu and Hong Wang},
  title = {{Exploiting Edited Large Language Models as General Scientific Optimizers}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-long.270},
}
Figure