The FrugalGPT.LLMCascade class is used to train a strategy that optimizes for a specific budget. The training process involves learning which models to call in a cascade to maximize accuracy while staying under a cost threshold.
Key Parameters for LLMCascade.train:
train_data: The dataset used for training.budget: The target cost budget.service_names: A list of available LLM services (e.g., ['provider/model']).no_scorer_train: Boolean. If True, skips training the scorer (used for subsequent budget evaluations).prefix: Prompt prefix.cascade_depth: The maximum number of models in the cascade.score_test_size: The fraction of data used for scoring during training.
Workflow:
- Initialize
LLMCascade with db_path and batch_build=True. - Call
.train() to optimize the cascade for a specific budget. - Call
.save() to persist the trained strategy. - Use
.load(loadpath=..., budget=...) to load a specific strategy for evaluation.
MyCascade = FrugalGPT.LLMCascade(db_path=f"db/{dataname}.sqlite", batch_build=True)
# Training the cascade for a specific budget
MyCascade.train(
train_data=train_data,
budget=0.00017,
service_names=service_names_train,
no_scorer_train=False,
prefix=prefix,
cascade_depth=3,
score_test_size=0.45
)
# Save the trained strategy
MyCascade.save(savepath=f"strategy/{name}/")