Skip to content

Commit a52e9f9

Browse files
authored
Merge pull request #1616 from stanfordnlp/new_dspy
MIPROv2 Refactor & Documentation Updates
2 parents 784a51b + be56860 commit a52e9f9

File tree

5 files changed

+752
-493
lines changed

5 files changed

+752
-493
lines changed

docs/docs/cheatsheet.md

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,15 @@ compiled_program_optimized_bayesian_signature = teleprompter.compile(your_dspy_p
392392
Note: detailed documentation can be found [here](/docs/deep-dive/optimizers/miprov2.md). `MIPROv2` is the latest extension of `MIPRO` which includes updates such as (1) improvements to instruction proposal and (2) more efficient search with minibatching.
393393

394394
#### Optimizing with MIPROv2
395+
This shows how to perform an easy out-of-the box run with `auto=light`, which configures many hyperparameters for you and performs a light optimization run. You can alternatively set `auto=medium` or `auto=heavy` to perform longer optimization runs. The more detailed `MIPROv2` documentation [here](/docs/deep-dive/optimizers/miprov2.md) also provides more information about how to set hyperparameters by hand.
395396
```python
396397
# Import the optimizer
397398
from dspy.teleprompt import MIPROv2
398399

399400
# Initialize optimizer
400401
teleprompter = MIPROv2(
401402
metric=gsm8k_metric,
402-
num_candidates=7,
403-
init_temperature=0.5,
404-
verbose=False,
405-
num_threads=4,
403+
auto="light", # Can choose between light, medium, and heavy optimization runs
406404
)
407405

408406
# Optimize program
@@ -412,10 +410,6 @@ optimized_program = teleprompter.compile(
412410
trainset=trainset,
413411
max_bootstrapped_demos=3,
414412
max_labeled_demos=4,
415-
num_trials=15,
416-
minibatch_size=25,
417-
minibatch_full_eval_steps=10,
418-
minibatch=True,
419413
requires_permission_to_run=False,
420414
)
421415

@@ -429,35 +423,31 @@ evaluate(optimized_program, devset=devset[:])
429423

430424
#### Optimizing instructions only with MIPROv2 (0-Shot)
431425
```python
432-
# Import optimizer
426+
# Import the optimizer
433427
from dspy.teleprompt import MIPROv2
434428

435-
# Initialize optimizer
429+
# Initialize optimizer
436430
teleprompter = MIPROv2(
437431
metric=gsm8k_metric,
438-
num_candidates=15,
439-
init_temperature=0.5,
440-
verbose=False,
441-
num_threads=4,
432+
auto="light", # Can choose between light, medium, and heavy optimization runs
442433
)
443434

444-
# Perform optimization
445-
print(f"Optimizing program with MIPRO (0-Shot)...")
446-
zeroshot_optimized_program = teleprompter.compile(
435+
# Optimize program
436+
print(f"Optimizing program with MIPRO...")
437+
optimized_program = teleprompter.compile(
447438
program.deepcopy(),
448439
trainset=trainset,
449-
max_bootstrapped_demos=0, # setting demos to 0 for 0-shot optimization
440+
max_bootstrapped_demos=0,
450441
max_labeled_demos=0,
451-
num_trials=15,
452-
minibatch=False,
453442
requires_permission_to_run=False,
454443
)
455444

445+
# Save optimize program for future use
446+
optimized_program.save(f"mipro_optimized")
456447

457-
zeroshot_optimized_program.save(f"mipro_0shot_optimized")
458-
459-
print(f"Evaluate optimized program...")
460-
evaluate(zeroshot_optimized_program, devset=devset[:])
448+
# Evaluate optimized program
449+
print(f"Evluate optimized program...")
450+
evaluate(optimized_program, devset=devset[:])
461451
```
462452
### Signature Optimizer with Types
463453

0 commit comments

Comments
 (0)