[Paper Review] Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programs
This paper proposes MIPRO, a novel optimizer for multi-stage language model (LM) programs that jointly improves free-form instructions and few-shot demonstrations without access to model gradients or intermediate labels. By using program- and data-aware instruction proposals, a stochastic mini-batch evaluation function, and meta-optimization, MIPRO achieves up to 13% accuracy gain over baselines on five of six LM program benchmarks using Llama3-8B.
Language Model Programs, i.e. sophisticated pipelines of modular language model (LM) calls, are increasingly advancing NLP tasks, but they require crafting prompts that are jointly effective for all modules. We study prompt optimization for LM programs, i.e. how to update these prompts to maximize a downstream metric without access to module-level labels or gradients. To make this tractable, we factorize our problem into optimizing the free-form instructions and few-shot demonstrations of every module and introduce several strategies to craft task-grounded instructions and navigate credit assignment across modules. Our strategies include (i) program- and data-aware techniques for proposing effective instructions, (ii) a stochastic mini-batch evaluation function for learning a surrogate model of our objective, and (iii) a meta-optimization procedure in which we refine how LMs construct proposals over time. Using these insights we develop MIPRO, a novel algorithm for optimizing LM programs. MIPRO outperforms baseline optimizers on five of seven diverse multi-stage LM programs using a best-in-class open-source model (Llama-3-8B), by as high as 13% accuracy. We have released our new optimizers and benchmark in DSPy at http://dspy.ai
Motivation & Objective
- To address the challenge of optimizing prompts in multi-stage LM programs where intermediate module labels and gradients are unavailable.
- To develop a method that jointly optimizes free-form instructions and few-shot demonstrations across multiple LM modules.
- To enable efficient prompt optimization under weak assumptions, relying only on the final metric and input-output data.
- To design a surrogate evaluation mechanism that enables scalable, stochastic optimization of prompt components.
- To derive practical insights and best practices for prompt engineering in complex LM pipelines.
Proposed method
- Propose task-grounded instructions using program- and data-aware strategies that align with the structure and content of downstream tasks.
- Construct a stochastic mini-batch evaluation function to estimate the objective metric efficiently, enabling surrogate modeling of the optimization landscape.
- Implement a meta-optimization procedure that refines how language models generate prompt proposals over time, improving proposal quality iteratively.
- Factorize the optimization problem into independent updates for instructions and demonstrations, enabling targeted improvement of each component.
- Use a black-box optimization loop where the optimizer iteratively proposes new instructions and demonstrations, evaluates performance on a batch of inputs, and updates its proposal policy.
- Leverage the DSPy framework to instantiate and benchmark the optimizer across diverse LM programs with consistent evaluation protocols.
Experimental results
Research questions
- RQ1How can we effectively propose high-quality instructions for multi-stage LM programs when no intermediate supervision is available?
- RQ2What strategies enable robust credit assignment across multiple LM modules when only final outputs and a global metric are accessible?
- RQ3To what extent do optimizing instructions, demonstrations, or both yield the greatest performance gains in complex LM pipelines?
- RQ4Can a surrogate evaluation function based on mini-batch sampling effectively guide prompt optimization in the absence of full gradient information?
- RQ5How does meta-optimization of the proposal process improve convergence and final performance in prompt optimization?
Key findings
- MIPRO outperforms all baseline optimizers on five out of six benchmark tasks, achieving up to a 13% absolute accuracy improvement using Llama3-8B.
- Optimizing bootstrapped few-shot demonstrations was essential for realizing the largest performance gains, especially in few-shot learning scenarios.
- Instruction optimization became more critical for tasks with complex conditional logic or reasoning requirements.
- Jointly optimizing both instructions and demonstrations consistently led to the best overall performance across diverse tasks.
- The proposed surrogate evaluation function enabled efficient, scalable optimization with stable convergence across multiple trials.
- The study derived five actionable lessons for practitioners, including prioritizing demonstration quality and using context-rich instructions for high-stakes tasks.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.