Skip to content

MIPROv2: optimizing instructions and demonstrations for multi-stage LM programs

optionalcorefundamentalpaperrubric 11/122024 · EMNLP 2024 · ~30 min

Krista Opsahl-Ong, Michael J. Ryan, Josh Purtell, David Broman, Christopher Potts, Matei Zaharia, Omar Khattab

Read first: DSPy: compiling declarative LM calls into self-improving pipelines

Status

Paper vs. implementation. The 2024 paper (Opsahl-Ong et al., EMNLP 2024) introduces MIPRO, an algorithm. MIPROv2 is the later DSPy optimizer (dspy.MIPROv2) that this page teaches. The two share the core design below, but details of the current code are not claims of the paper, and paper results (“MIPRO” in its tables) were not produced by today’s MIPROv2.compile.

TL;DR. Given a DSPy program and a metric on its final output, MIPROv2:

  1. bootstraps candidate demo sets for each module;
  2. asks an LM to propose instructions grounded in the program code, a data summary and the traces;
  3. runs Bayesian optimization over (instruction, demos) choices for every module, scoring each trial on a small mini-batch.

Why it matters now. In our editorial view it is the usual first choice once BootstrapFewShot is not enough, and it is the baseline GEPA compares against.

Data splits. Demos are bootstrapped from training examples. Candidate configurations are scored on mini-batches and periodically on a full validation set, and the final program is chosen on that validation score; a separate test set is needed for any reported number.

Optimizing an LM program: modules with tunable parameters, and an optimizer loop Top: a multi-hop question-answering program made of modules (generate search query, retrieve, generate a second query, retrieve, answer). Each LM module has three tunable parameters: its instruction, its few-shot demonstrations and the model weights. Bottom: an optimizer runs the program on training inputs, scores the final output with a metric, and proposes new parameters. Labels show what each optimizer changes: bootstrapping changes demonstrations, MIPROv2 searches instructions and demonstrations with a Bayesian surrogate, BetterTogether alternates prompt optimization and fine-tuning, and GEPA reflects on traces in natural language and keeps a Pareto set of candidates. An LM program (multi-hop QA), written as modules with signatures question query₁ ←question retrieve query₂ ←question, notes retrieve answer ←question, passages output each LM module (shaded) has three knobs: instruction demos weights The optimizer loop (no module-level labels, no gradients through the pipeline) run program ontraining inputs score final outputwith a metric propose newknob settings repeat within a budget of program runs What each one turns Bootstrap (DSPy) demos from passing traces MIPROv2 instructions + demos, Bayesian surrogate BetterTogether alternate prompts ⇄ weights GEPA reflect on traces in text, keep a Pareto set Assertions add constraints: on failure, retry the module with the error in its prompt. The program is the model; prompts and weights are its parameters.
MIPROv2 turns the instruction and demo knobs of every module together.

TPE is the Tree-structured Parzen Estimator, a Bayesian-optimization method. Instead of modelling score as a function of the configuration, it models which configurations tend to appear among good trials. An illustrative two-module program (query writer Q, answerer A), each with 3 instruction candidates and 3 demo-set candidates, so 81 full configurations:

  1. Warm-up. Run a handful of random configurations, each scored on a small random minibatch of training examples (say 25). Scores are noisy: the same configuration can score 0.48 on one minibatch and 0.56 on another.
  2. Split the history. Sort past trials by score and call the top fraction good, the rest bad.
  3. Compare densities per choice. For each module’s categorical choice, estimate how often each candidate appears in good trials versus bad ones. Say Q’s instruction 2 appears in 4 of 5 good trials but 2 of 10 bad ones, while A’s demo set 1 appears equally often in both. Instruction 2 is a promising value; demo set 1 carries no signal yet.
  4. Propose. Sample candidate configurations and pick the one with the highest good-to-bad density ratio, for example (Q: instruction 2, demo set 3; A: instruction 1, demo set 2). Score it on a fresh minibatch and add it to the history.
  5. Full validation. Every few trials, evaluate the current most promising configuration on the full validation set; the final program is the best validated configuration, and only then is it run on the untouched test set.

Two cautions. The per-choice densities are a search heuristic, not a causal decomposition: if Q’s instruction 2 only helps when paired with A’s demo set 3, attributing credit to each choice separately can mislead, and TPE guarantees neither additivity nor that its “importance” readout reflects causal effects. And the minibatch noise in step 1 is why step 5 exists.

  • Needs hundreds of program runs. Expensive with frontier LMs.
  • The scalar metric throws away why a run failed. GEPA’s reflective feedback is the response.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    You run MIPROv2 on a 2-module HotPotQA program (3 LM calls per run). There are v = 4 variables (an instruction and a demo set for each module), T = 300 minibatch trials with minibatch size B = 25, and every S = 10 trials the best mean candidate is fully evaluated on 200 examples. (a) What does the rule of thumb N < T / v allow for the number of candidates per variable, and why does such a rule exist? (b) How many program runs and LM calls does the search take, ignoring proposal and bootstrapping cost? (c) What fraction of that is full evaluation?

    What a strong answer covers
    • (a) N < 300 / 4 = 75. Each trial picks one value for every variable, so each candidate value is observed about T / N times; the rule ensures every candidate is tried at least a few times. With N = 10 each value gets about 30 noisy observations.
    • (b) Minibatch runs: 300 × 25 = 7,500. Full evaluations: 300 / 10 = 30, each of 200 runs, so 6,000. Total 13,500 runs and about 40,500 LM calls.
    • (c) 6,000 / 13,500 ≈ 44% goes to full evaluation, even though it is only 30 of the 330 scoring events.
    • Sanity check: the paper states budgets in full-evaluation units, for example 50 full-evaluation trials for HotPotQA, which it says translates to about 300 minibatch trials.
    • Lever: larger B lowers noise per trial but cuts the number of configurations you can try; smaller S catches lucky minibatch winners sooner but costs more full evaluations.
  2. Mechanism

    MIPROv2 scores each trial on a small random minibatch and fits a Bayesian surrogate (TPE) over each module's categorical choice of instruction and demo set. Explain why this assigns credit across modules better than an OPRO-style proposer that only sees a history of whole-program prompts and scores, and what minibatch noise does to it.

    What a strong answer covers
    • The surrogate models score as a function of each module's choice, so over many trials it pools evidence about each (module, candidate) value, much like estimating marginal effects.
    • An OPRO-style history has one scalar per full configuration; the proposer LM has to guess from text which module's change mattered, with no statistical pooling.
    • Minibatch scores are noisy. TPE does not average per candidate; it splits past trials into a good and a bad group by score and favours choices that are denser in the good group, so one lucky minibatch shifts the densities only a little. Periodic full evaluation of the most promising configuration guards against picking a lucky one.
    • Limits: TPE treats candidates as unrelated categories (no notion that two instructions are similar) and works best when module effects are roughly additive; strong interactions between modules weaken attribution.
    • The surrogate also gives an importance readout: in the paper's analysis, the demo-set choice and the proposal tip mattered most.
  3. What if…

    In the paper's main table (which reports the MIPRO algorithm), compare 0-shot instructions, instruction-only optimization (0-Shot MIPRO), demo-only optimization (Bootstrap RS) and joint MIPRO on HotPotQA (36.1 / 36.8 / 45.8 / 46.4) and on HotPotQA-Cond (6 / 14.6 / 10.4 / 23.3). What explains the different patterns, and what do they predict for a new task?

    What a strong answer covers
    • HotPotQA: demos carry almost all the gain (+9.7); instructions add little alone (+0.7) or on top of demos (+0.6). The format is familiar and examples show how to search and answer.
    • HotPotQA-Cond adds conditional rules about the answer format. A few demos cannot reliably show a rule that only applies to some inputs, so instructions matter, and joint optimization more than doubles either one alone.
    • This matches the paper's lessons: bootstrapped demos are key but vary a lot across demo sets, and instructions matter most for tasks with conditional rules.
    • Prediction: if the task hides rules that a few examples will not reveal, spend budget on instruction search; if it is pattern-following, bootstrap demos first.
    • Caveat: sub-point differences on HotPotQA should be checked against the paper's significance tests over 5 runs before reading anything into them.
  4. Critique

    Critique the paper's case that joint instruction and demo optimization is the best default. Use the settings where it does not win (e.g., Heart Disease, 74.2 vs 79.2 for Bootstrap RS) and the experimental design, and propose one experiment that could falsify the claim.

    What a strong answer covers
    • MIPRO outperforms the baselines on five of seven tasks; against the runner-up it is not significantly better on HotPotQA, Heart Disease and Iris without a typo.
    • The paper's own explanation for Heart Disease is a bare seed instruction with no classification criteria, which instruction proposers cannot infer. So the result depends on how good the seed prompt is.
    • One task LM (Llama-3-8B) and one proposer (GPT-3.5) were used; stronger instruction followers might shift the balance between instructions and demos.
    • Budgets were fixed per task (20–50 full-evaluation trials) and the paper says budget effects were not explored. A larger joint search space can need more trials to pay off.
    • Falsifier: sweep the trial budget (for example 0.25×, 1× and 4×) and the task LM. If Bootstrap RS matches MIPRO at small budgets or with strong models, the best-default claim depends on budget and model.
  5. Design

    You must optimize a 4-module claim-verification program that runs on a frontier API model. Each program run costs about USD 0.05 and your total budget is USD 500. Choose among BootstrapFewShot, BootstrapFewShotWithRandomSearch, MIPROv2 and GEPA, and justify the choice with a rollout budget.

    What a strong answer covers
    • Budget: 500 / 0.05 = 10,000 program runs in total, including validation and the final test, which rules out large validation sets with many full evaluations.
    • Reference point: in the GEPA paper's comparison, MIPROv2 used between 2,270 (PUPA) and 6,926 (HoVer) rollouts, so one run fits but leaves little room for repeats.
    • BootstrapFewShot costs only enough runs to collect a few successful traces; run it first as the baseline.
    • Strong models follow instructions well, so instruction search (MIPROv2 or GEPA) is more likely to pay off than for an 8B model. Instruction-only prompts are also shorter, which lowers the cost of every later call.
    • GEPA needs a feedback function. For claim verification, the gold evidence documents not yet retrieved is a natural one, as in its HoVer setup.
    • Plan: hold out a test set, reserve budget for at least 2–3 repeated runs to measure variance, and report cost per point of improvement.
  6. Connect

    MIPROv2 and GEPA both search over instructions for multi-module programs but learn from different signals. Contrast what each uses to propose and to select candidates, and explain why GEPA reports larger gains with much shorter prompts.

    What a strong answer covers
    • MIPROv2 proposes from a dataset summary, a program summary, bootstrapped demos and a random tip, not from observed failures; it selects with a TPE surrogate over scalar minibatch scores.
    • GEPA proposes by reflecting on one module's trajectory, score and textual feedback, then rewriting that module's instruction; it selects from a Pareto front over validation instances.
    • GEPA's signal says why a run failed, so each proposal targets a specific error. MIPROv2 needs many trials to learn statistically which candidates help.
    • Reported on GPT-4.1 Mini: aggregate gains of +12.19 (GEPA) and +13.33 (GEPA+Merge) against +5.64 for MIPROv2, with GEPA prompts up to 9.2× shorter because they contain no demos.
    • Trade-off: GEPA depends on a well-designed feedback function, while MIPROv2 needs only a metric.

Done with this page?

Status