Chapter 5

Optimizers

Learn how DSPy optimizers systematically improve your prompts and modules.

🚀 Chapter Overview

Optimizers are the heart of DSPy. They take your declarative modules and systematically improve them by tuning prompts and updating weights. In this chapter, we'll explore the full range of DSPy optimizers, from basic few-shot selectors to advanced evolutionary algorithms and fine-tuning strategies.

You'll learn how to treat prompt engineering as a programmatic optimization problem, allowing you to achieve higher performance with less manual effort.

📚 What You'll Learn

🔧

Core Optimizers

Master BootstrapFewShot, COPRO, and MiPRO for automatic prompt improvement.

🧠

Model Tuning

Learn how to fine-tune small language models to perform like larger ones.

🔬

Advanced Techniques

Explore cutting-edge methods like Bayesian Optimization, Monte Carlo methods, and Genetic Algorithms.

📐

Theoretical Foundations

Understand the theory behind multi-stage optimization and complex pipeline architectures.

📋 Chapter Structure

This chapter is organized into several key areas:

  • Getting Started: Compilation Concept, BootstrapFewShot
  • Instruction Optimization: COPRO, MiPRO, Automatic Prompt Optimization
  • Example Selection: KnnFewShot, Demonstration Optimization
  • Model Optimization: Fine-tuning, Joint Optimization
  • Advanced Methods: Monte Carlo, Bayesian, Genetic Algorithms (GEPA), Reflective Prompt Evolution
  • Architectures & Frameworks: CoPA, Multistage Theory, Instruction Tuning Frameworks