Tune one part of a model pipeline by its own score, and the whole pipeline can get worse. In this session's paper, DSPy cut one pipeline's accuracy by 14.3%. Optimas gives each part a learned reward that ranks outputs the way the whole system does, and it improved all five test pipelines.
Pick how to tune the reranker, then press Play. Watch the reranker's own score and the system's score, round by round. Then we build, piece by piece, the system as a graph, the alignment rule, the reward that learns it and the loop that uses it.
You need a little Python and what a probability is. We build the rest from zero.
Session 11 of Georgia Tech CS 8803, LLM seminar. It rests on one paper: Wu, Sarthi, Zhao, Lee, Shandilya, Mladenic Grobelnik, Choudhary, Huang, Subbian, Zhang, Yang, Zou and Leskovec, Optimas: Optimizing Compound AI Systems with Globally Aligned Local Rewards (ICLR 2026). Every idea is re-taught here in our own words and devices.
Toy, run live: one reranker knob, a made-up keyword score and a made-up system score. The paper's real case (Table 2): DSPy took the Amazon pipeline from 21.21% to 18.18% accuracy, and Optimas took it to 24.24%.
Chapter 0
See how one part can improve by its own score while the system it serves gets worse
You run a support assistant built from four parts. A retriever pulls candidate documents from a knowledge base. A reranker puts the best ones first. A generator, an LLM, writes the answer. A verifier checks the answer against the documents.
A system built from several such parts is a compound AI system. Each part can be an LLM, a tool or a classic machine learning model. One part's output is the next part's input.
Say the reranker looks weak. You tune it against a score it can compute alone: how many words each document shares with the question. That score climbs every week, and the answers get worse. The hero shows this on a toy.
Why does one part matter so much? An early error passes to every later part. The paper's example: an LLM misreads the query, so it retrieves the wrong documents, so every later tool works on wrong inputs.
Each box is one part, clean on a share of questions. The bar is the share of questions that pass every part without an error. Add parts or lower their quality.
Toy: it assumes each part fails on its own, apart from the others. Real failures are often linked, which this simple product does not capture.
With made-up numbers: four parts that are each clean on 95% of questions give 0.95 × 0.95 × 0.95 × 0.95 = 0.81. The chain is clean on 81% of questions. A fifth such part brings it to 77%.
Failure. A part's own score rises while the system's score falls. Measure: score the whole system on held-out questions after every change, not the part alone. Fix: the rest of this session builds a part score that cannot drift away from the system score.
Chapter 1
Write the pipeline as a graph of parts, each with its own knob, and one score for the end result
The paper writes a compound system as a directed acyclic graph: boxes joined by one-way arrows, with no loops. Each box is a component Ck, for k from 1 to K. The user's input is a source box, C0. An arrow from Ci to Cj sends Ci's output into Cj.
Each component takes an input xk and gives an output yk. A configuration vk sets its behaviour: it is the knob you may turn. The arrows in use can change with the input. A verifier's rejection might send one question back to retrieval and not another.
| Knob type | Example | In the paper |
|---|---|---|
| Text | a prompt | HotpotQA's four GPT-4o-mini modules |
| Discrete choice | which LLM to call; how many passages | PubMedQA picks from 7 LLMs; HotpotQA's k in {1, 5, 10, 25} |
| Weights | a model's parameters | Amazon's two Qwen 2.5 1.5B models, trained with PPO |
| Numbers | weights that merge two scores | STaRK's two weights, each in {0.1, 1.0} |
| Empty | a fixed tool | nothing to tune |
Pick a step. The box shows what goes in, what comes out and which knob that module has. Look at how the data changes shape at each arrow.
The five modules and the k values are the paper's HotpotQA system (Appendix D, Table 5). We made up the question and every text shown.
To run the system, call the components in order. Each one reads its parents' outputs. Call the final output f(x; v): what the system gives for input x under the full set of knobs v = (v1, …, vK).
What should the knobs be? Call the set of example inputs D. Call the user's score for a final answer R(x, y), the global reward; for HotpotQA it is F1 against the true answer.
v-star equals the arg max over v of the expected value, for x drawn from D, of R of x and f of x given v.
Fix a full set of knobs v. Run the system on every input x in D. Score each answer with R and average the scores. The v with the highest average is v-star.
With made-up numbers: setting a scores F1 0.3, 0.5 and 0.4 on three questions, an average of 0.40. Setting b scores 0.6, 0.2 and 0.7, an average of 0.50. So v-star is b, even though b loses on question 2.
Failure. You score each component on its own test data and never run the graph. Measure: R on the full system. Fix: keep R as the only final judge. Every local score must answer to it.
Chapter 2
Meet the three obstacles that rule out gradient descent and brute force
A neural network trains end to end: one loss, and gradients flow back through every layer. The paper names three reasons this fails for a compound system.
| Obstacle | What it means | Example |
|---|---|---|
| No gradient | most knobs are not smooth numbers | a prompt is text; k is one of four values |
| Mixed types | no single update moves every knob | a prompt edit, a PPO step and a model swap share no unit |
| Costly runs | each trial runs the whole pipeline | one score needs every component on every input |
Even trainable weights hit the first wall. Amazon's Qwen model writes text, and the next component reads that text. The model samples one sequence of tokens, and no gradient flows back through a sampled word.
So try brute force: list candidate settings for each knob and run every combination on the training questions.
Choose how many candidate prompts to try for each of HotpotQA's four prompt modules. The bars use a log scale: each grid line is ten times the one before.
Our estimate, not the paper's: c prompts for each of 4 modules, all 4 values of k, on the 1,000 training questions (Appendix C). The 2,020 is Optimas's measured cost on HotpotQA (Table 3). It searches in another way, so this compares budgets, not methods.
With 5 prompts per module, the grid has 2,500 settings. Each needs the whole pipeline on all 1,000 questions: 2.5 million runs. Optimas spent about 2,020 equivalent runs on this system, about 1,240 times fewer. With 8 prompts per module, the grid needs 16.4 million runs.
Prior work goes around the walls by tuning one knob type at a time. DSPy and TextGrad tune prompts, LLMSelector picks models, and reinforcement learning tunes weights. Each judges a part on its own, without running the rest. That is cheap. Chapter 3 shows what it costs.
Failure. The budget covers a few settings, and the best one wins by noise. Measure: count full-system runs per setting tried. Fix: score candidates with something cheap that still tracks R.
Chapter 3
Watch a sensible local score pick the wrong passage on every question
The cheap fix gives each part its own score and tunes the part to raise it. The paper names the flaw: an upstream part cannot see which of its outputs help the parts downstream.
Here is the smallest case. A retriever hands one of two passages, A or B, to a fixed generator. Its local score is keyword overlap: the share of the question's words that a passage repeats. The global reward is the generator's F1.
Choose the score that picks. Press Next to answer one more question. Grey bars are overlap; purple bars are the F1 the generator gets from that passage.
Toy: four made-up questions. Passage A repeats the question's words. Passage B states the answer with different words.
Overlap picks A every time: (0.20 + 0.30 + 0.45 + 0.10) / 4 = 0.26 average F1. Picking by downstream F1 takes B every time: (0.90 + 0.85 + 0.70 + 0.95) / 4 = 0.85. The generator and the questions did not change. Only the score that chose changed.
This is Goodhart's law: when a measure becomes a target, it stops being a good measure. An optimizer pushes hard on whatever score you give it.
The paper's baselines show it on real pipelines. Relative change is (new − old) / old: for DSPy on Amazon, (18.18 − 21.21) / 21.21 = −14.3%.
| Method | Pipeline | Unoptimized → after | Change |
|---|---|---|---|
| DSPy | Amazon, accuracy % | 21.21 → 18.18 | −14.3% |
| DSPy | HotpotQA, F1 | 33.80 → 44.90 | +32.8% |
| TextGrad | HotpotQA, F1 | 33.80 → 24.86 | −26.4% |
| HBC | HotpotQA, F1 | 33.80 → 21.16 | −37.4% |
The same DSPy helps one pipeline and hurts another. In the paper's runs it tunes only each module's instruction text. HBC (hierarchical behaviour cloning) scores an output by how close its embedding is to a known good output. Nobody checks either score against R.
Failure. A strong optimizer leaves the system worse than no tuning. Measure: compare against the unoptimized pipeline on held-out data. Fix: check that the local score ranks outputs the way R does before you optimize it.
Chapter 4
State exactly when a part's own reward is safe to maximize
Optimas gives every tunable component a local reward function (LRF): a function that scores the component's output given its input. The paper trains it; nobody picks it by hand.
All LRFs share one model. A shared LLM φ (the backbone) reads the input and output as one text, [xk, yk], and turns it into an embedding. A small linear layer hk (the head), one per component, turns that embedding into one number rk.
r-k of x-k and y-k equals h-k of phi of the text x-k joined with y-k.
Join the input x-k and the output y-k into one text. Pass it through phi to get an embedding. Multiply by the weights of h-k and add its bias. The result is r-k.
With made-up numbers: phi gives the embedding (0.2, −0.1, 0.5, 0.3). The head h-k has weights (1, 0, 2, −1) and bias 0.1. So r-k = 0.2 + 0 + 1.0 − 0.3 + 0.1 = 1.0.
What must rk get right? Not R's value, only its order. Take two candidate outputs of component k for the same input, y+ and y−. A candidate's true worth is the global reward you expect after the later components run on it, averaged over their randomness.
If r-k of y-plus is at least r-k of y-minus, then the downstream expected R given y-plus is at least the downstream expected R given y-minus.
Take any two candidates. If r-k ranks y-plus at least as high as y-minus, then y-plus must also lead to at least as much expected global reward. An LRF that passes this for every pair is aligned.
With made-up numbers: r-k gives 1.4 to y-plus and 0.6 to y-minus. Their downstream expected F1 is 0.7 and 0.3. The order agrees, so the pair passes. If the F1s were 0.3 and 0.7, the pair would fail.
Eight candidate outputs. Across: each one's true downstream reward. Up: what the LRF gives it. Slide training up and count the pairs it ranks the right way.
Synthetic points. Measured agreement on real held-out pairs: 77.96% for Optimas's LRFs and 49.52% for a GPT-4o judge (Table 4).
Why is order enough? The paper's Theorem 4.1 answers it. Take an aligned rk. The vk that maximizes rk also maximizes the system's expected R. So you can tune one component with a cheap score.
Failure. An LRF ranks pairs at chance, so tuning against it is a coin flip. Measure: pairwise ranking accuracy, the share of held-out pairs ranked the right way. Fix: train it on downstream labels (Chapters 5 and 6).
Chapter 5
Estimate a candidate's downstream reward by running the rest of the system several times
The alignment rule needs the downstream expected reward of each candidate. Nobody hands you that number. The paper estimates it by Monte Carlo sampling: run the later components on the candidate several times and average the scores.
Fix the input x and every upstream output. Feed candidate y to the downstream components and run them n times. Run j gives a final answer with score Rj. Call the estimate Ĝ(y).
G-hat of y equals one over n times the sum, over j from 1 to n, of R-j of x and y.
Run the rest of the system n times from candidate y. Score each final answer with R. Add the scores and divide by n. That is G-hat.
With made-up numbers: four runs from passage B score F1 0.9, 0.8, 1.0 and 0.7. G-hat = 3.4 / 4 = 0.85.
Each dot is one downstream run: filled if the final answer was right. The bar is the running average, the dashed line the true value. Run a few, then many.
Toy: each run is right or wrong. From A the answer is right 60% of the time, from B 45%. We compute the chance of a right label exactly. The paper does not report its number of runs.
Comparing two estimates gives a preference pair. The paper builds pairs for component k in three steps:
With the toy's numbers, one run each gives the right label 57.5% of the time. Ten runs each give about 75%. Close candidates need many runs before the label is reliable.
Failure. Too few runs, so close pairs get the wrong label and the LRF learns noise. Measure: re-estimate a sample of pairs with more runs and count the labels that flip. Fix: more runs for close pairs, or drop pairs whose gap is inside the noise.
Chapter 6
Fit the local reward to preference pairs with a pairwise loss, and see why its answer is aligned
Each pair says only which output was better. The paper trains rk with a pairwise log-sigmoid loss, the same form as reward models in RLHF. The sigmoid σ(u) = 1/(1 + e−u) squashes any number into the range 0 to 1.
Call the preference data for component k Dk: triples of an input, a better output y+ and a worse output y−. Call d the gap: the reward of y+ minus the reward of y−.
L-k equals minus the expected value, over triples drawn from D-k, of log sigma of r-k of y-plus minus r-k of y-minus.
For each pair, take the gap d. Squash it with sigma and take the log. Average over all pairs and flip the sign. A right order with a wide gap costs little; a wrong order costs a lot.
With made-up numbers: r-k gives 2.1 to y-plus and 0.4 to y-minus, so d = 1.7. Sigma of 1.7 is 0.846, and the loss is −log 0.846 = 0.17. Swap the two scores: d = −1.7, sigma is 0.154, and the loss is 1.87, eleven times more.
Slide the gap d between the better and the worse output. The dot shows that pair's loss. The yellow bar is how hard one training step pushes the gap up.
Exact curve of −log σ(d) and its push σ(−d). We made up the gap values.
Why does this loss give an aligned reward? Say each label comes from the true downstream rewards through a sigmoid with a sharpness α > 0. A bigger gap in expected R makes the right label likelier. The paper's Lemma B.1 shows the loss is lowest when rk equals α times the expected downstream R. Multiplying by a positive number never flips an order, so that rk is aligned.
The learned rewards 0.6 and 1.4 predict the same label chance, 0.69, as the true rewards. The data cannot tell them apart, and their order is the same.
How much data does it take? On HotpotQA, 12.5% of the preference data gives 65.46% pairwise accuracy, 92.7% of the full-data score; 25% gives 95.1% (Figure 7). Backbones of 1B, 3B and 8B parameters score 72.58%, 70.04% and 71.20%. A bigger backbone did not help.
Failure. The LRF fits its training pairs but ranks new outputs at chance. Measure: pairwise accuracy on held-out pairs. Fix: more varied candidates and early stopping; the paper stops when the held-out loss stalls for 512 steps.
Chapter 7
Pick one component, improve it against its reward, and keep the change only if the system agrees
The paper's Algorithm 1 starts from the first knobs and from LRFs trained once on offline pairs. Then it repeats:
| Knob | Local method | Role of the LRF |
|---|---|---|
| Prompt | OPRO-style search over candidate prompts | the score that ranks them |
| Weights | PPO, a reinforcement learning method | the critic |
| Discrete choice | sample one candidate by its score | sets the chances |
For a discrete knob, such as which LLM to call, score each candidate c with the LRF to get rc. Turn the scores into chances pc, then sample one.
p-c equals e to the r-c, divided by the sum over j of e to the r-j.
Raise e to each candidate's score r-c. Divide each by the total. Sample one candidate with those chances p-c. A higher score is likelier, not certain.
With made-up numbers: three LLMs score 0.62, 0.58 and 0.51. e to those gives 1.859, 1.786 and 1.665, a total of 5.310. The chances are 35.0%, 33.6% and 31.4%.
Step 5 is the validation gate. Call the validation inputs Dv, the current knobs vt and the candidate knobs ṽ.
The sum over x in D-v of R of x and f of x given v-tilde is greater than the same sum given v-t.
Run the system with v-tilde and with v-t on every validation input. Add each set of scores. Keep v-tilde only if its total is strictly higher. Otherwise keep v-t and skip the LRF refresh.
With made-up numbers: on 20 inputs, v-tilde totals 14.3 and v-t totals 14.1, so the gate keeps v-tilde. A total of 14.1 against 14.1 is a tie, and the gate rejects it.
Each step picks one component (pink), proposes a change that its LRF likes, then runs the gate. Green dots are kept changes, red crosses are rejected ones.
Toy run, scripted. A real kept step: on STaRK, a new Text Scorer prompt at iteration 9 raised the validation reward from 0.49 to 0.56 (Section 5.1).
Why refresh the LRFs? A kept change makes them stale in two ways. A changed component alters what its upstream parts' outputs are worth. And its downstream parts now get inputs their LRFs never saw. So after each kept change, the paper samples 20 fresh inputs, builds a few new pairs and takes a few loss steps. It mixes in a buffer of older pairs, so the LRF does not forget.
Failure. A stale LRF approves a change that hurts. Measure: count rejections at the gate. Fix: the gate stops the change, and the refresh after each kept change keeps the LRFs current.
Chapter 8
Read the paper's tables for accuracy, cost and how well the rewards rank
The paper tests five pipelines, each with a different mix of knobs (Appendices C and D).
| Pipeline | Task and metric | Components and knobs | Train / val / test |
|---|---|---|---|
| Amazon | next product a user picks; accuracy | two Qwen 2.5 1.5B models (weights, PPO), then a GPT-4o-mini decider (prompt) | 335 / 60 / 99 |
| PubMedQA | yes, no or maybe on medical abstracts; accuracy | two model selectors (7 LLMs), an analyst and a solver (prompts) | 475 / 25 / 500 |
| STaRK-Prime | biomedical retrieval; MRR | two Claude 3 Haiku scorers (prompts), an aggregator (two weights) | 495 / 51 / 96 |
| HotpotQA | two-step questions; F1 | four GPT-4o-mini modules (prompts) and a retriever (k) | 1,000 / 250 / 100 |
| BigCodeBench | code that passes tests; pass rate | three Claude 3 Haiku modules (prompts) | 500 / 25 / 70 |
Pick a method. Each bar is its relative change against the unoptimized pipeline. Bars right of the line are gains; bars left of it are losses.
All scores from Table 2; the change is against its Unoptimized row. Each method had a similar budget of system runs (Table 3).
Optimas is the only method that beats Unoptimized on all five. It also used the fewest system runs on average: 0.71 thousand, against 0.79 for DSPy and 0.80 for TextGrad (Table 3).
One correction to the headline. The paper reports an 11.92% average gain over the best baseline: the mean of Table 2's last row. Two entries use another comparison. Amazon's 14.3% is against Unoptimized; against REINFORCE (21.89) it is 10.7%. BigCodeBench's 9.0% is against TextGrad; against Unoptimized (36.67) it is 6.1%. Against the best baseline in every column, the average is 10.6%.
Did the LRFs learn the alignment rule? Count. Take held-out pairs where one output has the higher downstream reward. Call the set of pairs P and the reward being tested r.
acc equals one over the size of P, times the sum over pairs in P of one if r of y-plus is greater than r of y-minus.
For each pair in P, check whether r puts the truly better output y-plus on top. Count the hits. Divide by the number of pairs. That is acc.
Table 4: Optimas's LRFs score 84.93, 65.28, 76.64, 72.40 and 90.57% on the five pipelines, an average acc of 77.96%. A GPT-4o judge given 20 examples averages 49.52%: chance.
Better ranking bought a better system in a controlled test (Figure 5). On HotpotQA, the LRF prefers short answers, and the tuned prompt asks for no more than 10 words (Figure 6). Local reward rose from 0.17 to 0.22 and global reward from 0.32 to 0.36. Short answers suit F1, which counts extra words against you.
Failure. An average hides a pipeline that got worse. Measure: report every pipeline against Unoptimized. Fix: ship a change only if it beats no tuning on each system you care about.
Chapter 9
Check the guarantee against a real sweep, and list what the paper does not promise
Theorem 4.1 holds at the loss's minimum. Real LRFs are trained on a finite set of pairs. The paper checks how close they get: it sweeps HotpotQA's retriever k and records both rewards at each value (Table 8).
Teal is the LRF of the retriever. Purple is the system's global reward. Slide through the seven values of k and compare where each one ranks.
Real numbers from Table 8 (Appendix G.1). The two rewards are on different scales, so each line has its own axis.
The local reward peaks at k = 5 and the global reward at k = 10. The top three, {5, 10, 15}, match as a set; only the top two swap. The local gap between 5 and 10 is 0.0007, the global gap 0.0047. Alignment holds roughly, not exactly.
| Limit | What it means |
|---|---|
| Best one part at a time | Theorem 4.2: the loop is coordinate maximization. It reaches a point where no single component can improve. A change to two components together can still be better. |
| No global optimum promised | The paper says that needs extra conditions on the shape of the objective (Polyak–Łojasiewicz or Kurdyka–Łojasiewicz). |
| Needs a score R | No preference labels without a reward you can compute. All five tests have automatic metrics. |
| Equal turns | The scheduler picks components at random, even ones that are already at their best. |
| A small gate | 20 validation inputs. On Amazon, Table 2's run-to-run spread reaches ±3.78 points. |
| Extra compute | PPO on Amazon took about 6 GPU-hours (Appendix G.4). |
Failure. The loop stops where each part is at its own best, but a joint change would score higher. Measure: try a few paired changes by hand at the end. Fix: none is built in; the authors name larger systems as future work.
Chapter 10
Keep the terms, the numbers, the code and the open questions in one place
A compound system cannot be trained end to end, and tuning each part by a convenient score can make it worse. Optimas trains one local reward per part on downstream preference pairs, so each reward ranks outputs the way the system does. It tunes one part at a time and keeps a change only if a validation run agrees.
| Term | Meaning | Number to remember |
|---|---|---|
| Compound AI system | a graph of LLMs, tools and models | 5 test pipelines, 3 to 5 components each |
| Global reward R | the user's score for the final answer | accuracy, MRR, F1 or pass rate |
| LRF rk | a learned score for one component's output | one Llama 3 8B backbone, one head per component |
| Alignment | rk ranks pairs as downstream R does | 77.96% pairwise accuracy, judge 49.52% |
| Pairwise loss | −log σ of the gap | gap 1.7: 0.17; gap −1.7: 1.87 |
| Validation gate | keep a change only if total R rises | 20 validation inputs |
| Local search | small, conservative steps | 3 prompt candidates, 3 steps, 20 fresh inputs |
| Headline | mean of Table 2's last row | 11.92% reported; 10.6% against the best baseline |
| Cost | equivalent full-system runs | 0.71k average, against 0.79k (DSPy) |
pythonimport math, random def pair_loss(r_plus, r_minus): # -log sigma(gap) return math.log1p(math.exp(-(r_plus - r_minus))) def optimas(comps, v, lrf, R, val_set, T): for t in range(T): k = random.choice(list(comps)) # uniform scheduler cand = local_optimize(comps[k], v[k], lrf[k]) # prompt search, PPO or sampling v_new = {**v, k: cand} # change ONE slot new = sum(R(x, run(comps, v_new, x)) for x in val_set) old = sum(R(x, run(comps, v, x)) for x in val_set) if new > old: # strict: a tie is rejected v = v_new lrf = refresh(lrf, new_pairs(comps, v, n_inputs=20)) # plus a buffer return v print(round(pair_loss(2.1, 0.4), 2), round(pair_loss(0.4, 2.1), 2)) # 0.17 1.87
The convergence result reaches a point where no single component can improve, not a global best. The tests all use automatic metrics, so a learned or human-judged R is untested. The authors name larger systems, and the reward modelling they need, as future work.
Credit: Session 11 of Georgia Tech CS 8803, LLM seminar. Paper: Optimas: Optimizing Compound AI Systems with Globally Aligned Local Rewards (Wu, Sarthi, Zhao et al., ICLR 2026, arXiv 2507.03041). The toy pipelines and all made-up numbers are ours.
Teach it back: open Present or Teach and explain the alignment rule and the validation gate to a friend. Then go back to the reranker and predict both curves before you press Play.