dspy-finetune-bootstrap

Solid

This skill should be used when the user asks to "fine-tune a DSPy model", "distill a program into weights", "use BootstrapFinetune", "create a student model", "reduce inference costs with fine-tuning", mentions "model distillation", "teacher-student training", or wants to deploy a DSPy program as fine-tuned weights for production efficiency.

AI & Automation 78 stars 10 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 90/100

Stars 20%
63
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# DSPy BootstrapFinetune Optimizer ## Goal Distill a DSPy program into fine-tuned model weights for efficient production deployment. ## When to Use - You have a working DSPy program with a large model - Need to reduce inference costs - Want faster responses (smaller model) - Deploying to resource-constrained environments ## Inputs | Input | Type | Description | |-------|------|-------------| | `program` | `dspy.Module` | Teacher program to distill | | `trainset` | `list[dspy.Example]` | Training examples | | `metric` | `callable` | Validation metric (optional) | | `train_kwargs` | `dict` | Training hyperparameters | ## Outputs | Output | Type | Description | |--------|------|-------------| | `finetuned_program` | `dspy.Module` | Program with fine-tuned weights | | `model_path` | `str` | Path to saved model | ## Workflow ### Phase 1: Prepare Teacher Program ```python import dspy # Configure with strong teacher model dspy.configure(lm=dspy.LM("openai/gpt-4o")) class TeacherQA(dspy.Module): def __init__(self): self.cot = dspy.ChainOfThought("question -> answer") def forward(self, question): return self.cot(question=question) ``` ### Phase 2: Configure Fine-Tuning Assign the LM directly to predictors before fine-tuning: ```python import dspy from dspy.teleprompt import BootstrapFinetune optimizer = BootstrapFinetune( metric=lambda gold, pred, trace=None: gold.answer.lower() in pred.answer.lower(), train_kwargs={ 'learn...

Details

Author
OmidZamani
Repository
OmidZamani/dspy-skills
Created
5 months ago
Last Updated
1 weeks ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category