Composing Policy Gradients and Prompt Optimization for Language Model Programs
Read first: DSPy: compiling declarative LM calls into self-improving pipelines · DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models
TL;DR. An LM program, such as a DSPy pipeline with a query writer, a retriever and a note taker, makes several LM calls per input and gets one reward at the end. mmGRPO (multi-module GRPO; GRPO samples a group of outputs for the same input and scores each against the group’s mean reward, with no learned critic) trains the shared LM weights for such programs. It forms GRPO groups from calls to the same module at the same relative position across rollouts, gives each call the program-level reward, and pads groups to a fixed size. Alone it beats untuned chain-of-thought by about 7% relative. Run after MIPROv2 prompt optimisation, the BetterTogether recipe, it gives the best average: about 11% relative over untuned and 5% over prompt optimisation alone.
Why it matters now. Many retrieval systems are already modular programs: rewrite the query, retrieve, read, take notes, repeat. mmGRPO is the policy-gradient method that fits that structure without flattening it into one long chat. One of its three tasks is a four-hop retrieval program over ColBERTv2 scored by Recall@100, which is a retrieval experiment in all but name.
Key idea
Section titled “Key idea”LM programs as policies. A program Φ has modules ; each module has a prompt template and weights . Running Φ on input x gives an output y and a trajectory of traces : which module was called, its fully rendered prompt, and its output (Eqs. 3–5). Control flow can differ between runs, so the number and order of module calls vary. The goal (Eq. 6) is to maximise the expected metric
where m is metadata such as gold labels. Prompt optimisation (for example MIPROv2) changes the templates Π; mmGRPO changes the weights Θ. In the experiments all modules share one base model with a single LoRA adapter.
Module-level groups. For each input, sample G rollouts and score each with the program-level reward r. Then (Algorithm 2, FormModuleLevelGroups):
- For each trace in each trajectory, add the triple (q, o, r) to the group keyed by (module, k), where k counts how many times that module has already been called in this trajectory (Eq. 7).
- The number of groups is
where is how many times module runs in trajectory . 3. PadGroups fills groups that some trajectories never reached by repeating existing elements with their rewards. SelectKDiverseElements trims groups to size G. Incomplete or crashed trajectories get a fallback reward, such as a format penalty. 4. Apply the usual GRPO objective inside each group, with the advantage from the group-normalised reward.
Unlike single-turn GRPO, the prompts inside a group differ: the second query-writer call in two rollouts sees different retrieved notes. A trajectory-level variant instead groups whole program runs and normalises by total trajectory length (Eq. 9).
BetterTogether(PO, mmGRPO). First run prompt optimisation (MIPROv2) to find good prompts for every module. Then freeze those prompts and run mmGRPO on the weights. Better prompts produce better early rollouts, which gives GRPO more informative groups.
Key results
Section titled “Key results”All numbers are paper-reported (§5, Table 1), on llama3.1-8b-instruct and qwen3-8b with one shared LoRA adapter (r = 16, α = 64). Training uses TRL’s GRPO trainer, 750 steps, 4 examples per step and 12 rollouts each.
The three tasks:
- Banking77: a single chain-of-thought module, scored by accuracy, with reward only from rollouts. It is a sanity check where mmGRPO reduces to GRPO.
- PAPILLON: privacy-conscious delegation to gpt-4.1-mini, with two modules scored by an LLM judge.
- HoVer 4-HOP: a query writer and a note taker over four hops of ColBERTv2 retrieval, scored by Recall@100.
| Method (llama / qwen) | Banking77 | PAPILLON | HoVer 4-HOP | Avg |
|---|---|---|---|---|
| Vanilla CoT | 58.4 / 64.6 | 76.2 / 78.3 | 59.5 / 60.6 | 66.3 |
| MIPROv2 | 59.4 / 65.9 | 83.9 / 78.1 | 63.4 / 69.3 | 70.0 |
| mmGRPO | 63.7 / 64.9 | 83.9 / 83.3 | 60.2 / 71.0 | 71.2 |
| BetterTogether | 63.7 / 69.1 | 86.5 / 81.1 | 68.3 / 71.5 | 73.4 |
Each cell is a mean over 3 seeds. The paper also reports standard deviations, which range from 0.4 to 5.6 points.
How to read the headline gains. The abstract’s “11%” and “5%” are relative gains on the average: 73.4/66.3 and 73.4/70.0. In absolute terms they are +7.1 and +3.4 points.
Cost. mmGRPO runs averaged 18.7 hours on 2 H100s; MIPROv2 averaged 1.4 hours on 1 H100.
A later variant. Trajectory-level grouping with the CISPO loss and extra tuning reached 75.3 Recall@100 on HoVer with qwen, against 71.0 for the module-level run (§5.4).
What the queries looked like. In qualitative case studies (§5.5), trained HoVer queries became short, entity-dense keyword queries that suit ColBERTv2, and notes tracked what had been verified.
Limitations & open questions
Section titled “Limitations & open questions”- Small scale. The study uses only 8B models, LoRA rather than full fine-tuning, and two grouping variants (the authors list all three as limitations).
- Banking77 is a weak RL testbed. Rewards come only from bootstrapped rollouts, not labels. The authors note that current methods do not yet reach strong performance from reward alone.
- Comparability of grouped calls is assumed. Calls in the same group have different prompts, and every call gets the same final reward, so per-module credit is coarse.
- Noise versus gaps. Table 1 averages 3 seeds per cell, and standard deviations reach 4–5.6 points on PAPILLON (for example MIPROv2 83.9 ± 5.6, BetterTogether 86.5 ± 5.0), so several per-task gaps are within run-to-run variation.
- Prompt optimisers keep improving. The authors point to newer reflective optimisers such as GEPA as candidates for the prompt half of the composition.
Connections
Section titled “Connections”- The programming model: DSPy, DSP, MIPROv2.
- The composition idea: BetterTogether, the earlier recipe that alternated prompt optimisation with fine-tuning. GEPA is a newer reflective prompt optimiser.
- The RL side: GRPO, Dr. GRPO (length normalisation), RLOO.
- Other ways to split agent runs into training examples: Agent Lightning.
- The retriever in HoVer: ColBERTv2. For the benchmark lineage see classic multi-hop QA.
- Map: the agentic RL survey.
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.
- Derive / compute
Table 1 gives average scores of 66.3 (vanilla chain-of-thought), 70.0 (MIPROv2), 71.2 (mmGRPO) and 73.4 (BetterTogether: MIPROv2 then mmGRPO). Compute the absolute (point) and relative (percent) gains behind the paper's "11%", "5%", "7%" and "3%" headlines, and say which form you would report in an IR paper and why.
What a strong answer covers
- BetterTogether vs vanilla: +7.1 points, 73.4/66.3 ≈ 1.107, so +10.7% relative ("11%").
- BetterTogether vs MIPROv2: +3.4 points, 73.4/70.0 ≈ 1.049, so +4.9% relative ("5%").
- mmGRPO vs vanilla: +4.9 points, 71.2/66.3 ≈ 1.074, so +7.4% relative ("7%"). BetterTogether vs mmGRPO: +2.2 points, about +3.1% relative ("3%").
- The headlines are relative gains on an average of different metrics (accuracy, a judge score, Recall@100). Reporting absolute points per task, with the metric named, avoids inflating gains on low baselines and avoids averaging incomparable scales.
- Mechanism
A two-module HoVer-style program (generate_query, append_notes) is sampled three times for one claim. Trajectory 1 calls each module 2 times, trajectory 2 calls each once, and trajectory 3 calls each 3 times. Using FormModuleLevelGroups, list the group keys, count the groups with the formula, describe what each group element contains, and explain what padding does to the group for the third generate_query call.
What a strong answer covers
- Keys are (module, relative invocation index k): (generate_query, 0), (generate_query, 1), (generate_query, 2), and the same three for append_notes.
- Number of groups = Σ over modules of max over trajectories of K = 3 + 3 = 6.
- Each element is a triple (q, o, r): the module's actual prompt in that trajectory, its output, and the program-level reward of the whole trajectory. Prompts differ across elements because earlier hops retrieved different documents.
- The k = 2 groups contain only trajectory 3's calls. PadGroups repeats existing elements (with their rewards) to reach group size G; with one real element every reward is identical, so the group-relative advantage is zero and the group contributes no learning signal.
- What if…
Read Table 1 per task rather than on average. Where does mmGRPO alone beat MIPROv2, where does it lose, and what does the cost comparison (18.7 hours on 2 H100s against 1.4 hours on 1 H100) imply for a lab choosing between prompt optimisation and RL?
What a strong answer covers
- mmGRPO beats MIPROv2 on Banking77 with llama (63.7 vs 59.4), PAPILLON with qwen (83.3 vs 78.1) and HoVer with qwen (71.0 vs 69.3); it ties on PAPILLON with llama (83.9) and loses on Banking77 with qwen (64.9 vs 65.9) and HoVer with llama (60.2 vs 63.4).
- BetterTogether is best or tied-best in five of six task–model cells (all except PAPILLON with qwen, where mmGRPO alone scores 83.3 against 81.1).
- mmGRPO costs roughly 27 times the GPU-hours of MIPROv2 (2 × 18.7 = 37.4 against 1.4) for a 1.2-point average gain over it.
- Several gaps are within noise: each cell averages 3 seeds, and PAPILLON standard deviations reach about 5 points, so the PAPILLON comparisons in particular are not decisive.
- Implication: run prompt optimisation first; add RL when the extra compute is affordable and the task benefits, and expect the largest gains from composing the two rather than from RL alone.
- Design
You maintain a multi-hop retrieval program (query writer → ColBERTv2 retrieval → note taker, four hops) evaluated by Recall@100 against judged supporting documents. Design an mmGRPO training run: the reward, the group structure, what to share across modules, the starting prompts, and one retrieval-specific check on what the policy learns.
What a strong answer covers
- Reward: Recall@100 of the final passage set against gold supporting documents (the paper's HoVer metric), with a fallback penalty for crashed or malformed trajectories.
- Groups: module-level, keyed by (module, hop index), so the hop-1 query writer is compared with other hop-1 query writers; consider the trajectory-level variant, which the paper found strong on HoVer with CISPO (75.3 vs 71.0).
- Sharing: one LoRA adapter over a shared base model for both modules, as in the paper; starting prompts from MIPROv2 (BetterTogether) so early rollouts are higher quality.
- Check: inspect how queries change. The paper found queries became short, keyword-style and entity-heavy, which suits ColBERTv2; with a different retriever (BM25 or a dense model) the learned query style may differ, so retrain or re-evaluate when swapping the index.
- Critique
Module-level grouping assumes that "the k-th call to module M" is a comparable decision across rollouts. Critique this assumption and the decision to give every call the same program-level reward. When does the grouping compare unlike things, and what are the alternatives?
What a strong answer covers
- Calls at the same index see different prompts: by hop 3, different trajectories have retrieved different documents and written different notes, so the group compares responses to different situations, unlike single-turn GRPO where the prompt is shared.
- Every call in a trajectory receives the same final reward, so a good query in a trajectory ruined by a later bad note is penalised. Credit assignment between modules comes only from averaging over many rollouts.
- Variable control flow makes late-index groups sparse; padding makes their size uniform but adds no information.
- Alternatives: trajectory-level grouping (the paper's second variant), learned per-module value functions or process rewards (for example retrieval recall after each hop), or resampling from a shared prefix so the compared calls truly share their context.
- Connect
Compare how mmGRPO and Agent Lightning turn a multi-call agent run into training data. What do they share, where do they differ in how calls are grouped and weighted, and which of Agent Lightning v1.0's weighting concerns also apply to mmGRPO's trajectory-level variant?
What a strong answer covers
- Shared: both treat each LLM call as its own (prompt, output) example with its own context, give it the run's final reward, and apply a GRPO-style group baseline.
- Grouping: Agent Lightning's 2025 LightningRL groups transitions by task; mmGRPO groups by task, module and invocation index, so a query writer is compared with query writers, not with summarisers.
- Weighting: mmGRPO's trajectory-level variant normalises by the total length of the trajectory; Agent Lightning v1.0 argues for rollout-level baselines and rollout-level token means so that runs which produce more samples do not get more weight.
- Both frameworks work above the trainer: mmGRPO is part of DSPy's optimiser API (with TRL's GRPO trainer in the paper's experiments), while Agent Lightning wraps verl.