Skip to content

Commit 87148a0

Browse files
authored
Merge pull request algorithmicsuperintelligence#178 from codelion/fix-llm-optimization
Fix llm optimization
2 parents 715667c + 7822d97 commit 87148a0

25 files changed

+1205
-995
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,72 @@ prompt:
288288
num_top_programs: 3 # Performance examples
289289
num_diverse_programs: 2 # Creative inspiration
290290
include_artifacts: true # Execution feedback
291+
292+
# Template customization
293+
template_dir: null # Directory for custom prompt templates
294+
use_template_stochasticity: true # Enable random variations in prompts
295+
template_variations: {} # Define variation placeholders
291296
```
292297

293298
Sample configuration files are available in the `configs/` directory:
294299
- `default_config.yaml`: Comprehensive configuration with all available options
295300
- `island_config_example.yaml`: Advanced island-based evolution setup
296301

302+
### Template Customization
303+
304+
OpenEvolve supports advanced prompt template customization to increase diversity in code evolution:
305+
306+
#### Custom Templates with `template_dir`
307+
308+
You can override the default prompt templates by providing custom ones:
309+
310+
```yaml
311+
prompt:
312+
template_dir: "path/to/your/templates"
313+
```
314+
315+
Create `.txt` files in your template directory with these names:
316+
- `diff_user.txt` - Template for diff-based evolution
317+
- `full_rewrite_user.txt` - Template for full code rewrites
318+
- `evolution_history.txt` - Format for presenting evolution history
319+
- `top_program.txt` - Format for top-performing programs
320+
- `previous_attempt.txt` - Format for previous attempts
321+
322+
See these directories for complete examples of custom templates:
323+
- `examples/lm_eval/prompts/` - Custom templates for evaluation tasks
324+
- `examples/llm_prompt_optimization/templates/` - Templates for evolving prompts instead of code
325+
326+
#### Template Variations with Stochasticity
327+
328+
To add randomness to your prompts and prevent getting stuck in local optima:
329+
330+
1. **Enable stochasticity** in your config:
331+
```yaml
332+
prompt:
333+
use_template_stochasticity: true
334+
template_variations:
335+
greeting:
336+
- "Let's improve this code."
337+
- "Time to enhance this program."
338+
- "Here's how we can optimize:"
339+
analysis_intro:
340+
- "Current metrics show"
341+
- "Performance analysis indicates"
342+
- "The evaluation reveals"
343+
```
344+
345+
2. **Use variation placeholders** in your custom templates:
346+
```
347+
# custom_template.txt
348+
{greeting}
349+
{analysis_intro} the following results:
350+
{metrics}
351+
```
352+
353+
The system will randomly select one variation for each placeholder during prompt generation, creating diverse prompts that can lead to more creative code evolutions.
354+
355+
**Note**: The default templates don't include variation placeholders, so you'll need to create custom templates to use this feature effectively.
356+
297357
### Feature Dimensions in MAP-Elites
298358

299359
Feature dimensions control how programs are organized in the MAP-Elites quality-diversity grid:
@@ -425,8 +485,12 @@ Demonstrates integration with [optillm](https://github.com/codelion/optillm) for
425485
- **Mixture of Agents (MoA)**: Multi-response synthesis for improved accuracy
426486
- **Local model optimization**: Enhanced reasoning with smaller models
427487

428-
#### [LLM Prompt Optimization](examples/llm_prompt_optimazation/)
429-
Evolving prompts themselves for better LLM performance, demonstrating self-improving AI systems.
488+
#### [LLM Prompt Optimization](examples/llm_prompt_optimization/)
489+
Evolving prompts for better LLM performance on HuggingFace datasets. Features:
490+
- Custom templates for evolving prompts instead of code
491+
- Two-stage cascading evaluation for efficiency
492+
- Support for any HuggingFace dataset
493+
- Automatic prompt improvement through evolution
430494

431495
### Systems & Performance Optimization
432496

examples/llm_prompt_optimazation/README.md

Lines changed: 0 additions & 184 deletions
This file was deleted.

examples/llm_prompt_optimazation/best_program.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/llm_prompt_optimazation/config.yaml

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)