Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programs

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

arXiv:2406.11695 · 2026-07-27 공개 · arXiv · PDF

instruction-tuning few-shot-learning credit-assignment prompt-optimization llama-3 surrogate-model meta-optimization multi-stage

Abstract

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](http://dspy.ai).

한국어 요약

한 줄 요약

MIPRO 알고리즘은 다단계 언어 모델 프로그램에서 지시문과 샘플을 최적화하여 최대 13%의 정확도 향상을 달성한다.

핵심 기여도

핵심 아이디어

다단계 언어 모델 프로그램에서 각 모듈의 지시문과 few-shot 예시를 독립적으로 최적화하는 것은 기존 연구에서 다루어지지 않았던 문제였다. 본 연구는 이 문제를 해결하기 위해 두 가지 주요 도전 과제를 정의했다: (1) **proposal challenge** — 즉, 가능한 지시문의 공간이 너무 커서 효과적인 샘플링이 필요하다는 점, (2) **credit assignment challenge** — 여러 모듈의 파라미터를 동시에 최적화할 때 어떤 변수가 성능에 가장 큰 영향을 주는지를 효과적으로 파악해야 한다는 점. 이를 해결하기 위해 연구팀은 프로그램-데이터 인식적 기법, 스토캐스틱 미니배치 평가 함수, 메타 최적화 절차를 도입했다. 특히, MIPRO 알고리즘은 이러한 전략을 결합하여 지시문과 few-shot 예시를 동시에 최적화하는 데 성공했다.

기술적 접근법

주요 결과

의의 및 한계

본 연구는 다단계 언어 모델 프로그램에서 지시문과 few-shot 예시를 동시에 최적화하는 새로운 알고리즘 MIPRO를 제안함으로써, 기존 연구에서 다루지 못했던 문제를 해결했다. 특히, 모듈별 라벨이나 그라디언트 없이도 전체 프로그램의 성능을 최적화할 수 있다는 점에서 학술적·실용적 가치가 있다. 그러나 일부 작업에서는 지시문 최적화가 효과적이지 않거나, 최적화 예산에 따라 알고리즘의 성능이 달라질 수 있다는 한계가 있다. 또한, 현재의 최적화 알고리즘은 모든 작업의 규칙을 완벽히 학습하지 못하는 경우가 있어, 더 많은 연구가 필요하다.

실용적 활용

MIPRO 알고리즘은 복잡한 다단계 NLP 작업(예: 조건부 추론, 다중 모듈 파이프라인)에서 모델 성능을 향상시키는 데 활용될 수 있다. 특히, 학습 데이터가 제한적이거나, 모델의 내부 파라미터에 접근할 수 없는 상황에서 유용하다. DSPy 프레임워크를 통해 개발자와 연구자들이 이 최적화 기법을 직접 적용할 수 있도록 지원하고 있다.