Parameter Optimizer: Bayesian Parameter Tuning
Parameter Optimizer: Bayesian Parameter Tuning
Optimize LLM parameters like temperature and top_p with Bayesian techniques.
Parameter Optimizer: Bayesian Parameter Tuning
Optimize LLM parameters like temperature and top_p with Bayesian techniques.
The ParameterOptimizer uses Bayesian optimization to tune LLM call parameters such as temperature, top_p, frequency_penalty, and other sampling parameters. Unlike other optimizers that modify the prompt itself, this optimizer keeps your prompt unchanged and focuses solely on finding the best parameter configuration for your specific task.
When to Use: Optimize LLM parameters (temperature, top_p) without changing your prompt. Best when you have a good prompt but need to tune model behavior.
Key Trade-offs: Requires defining parameter search space; doesn’t modify prompt text; uses two-phase Bayesian search.
Have questions about ParameterOptimizer? Our Optimizer & SDK FAQ
answers common questions, including when to use this optimizer, how parameters like default_n_trials and local_search_ratio
work, and how to define custom parameter search spaces.
This optimizer uses Optuna, a hyperparameter optimization framework, to search for the best LLM parameters:
Baseline Evaluation: First evaluates your prompt with its current parameters (or default parameters) to establish a baseline score.
Parameter Space Definition: You define which parameters to optimize and their valid ranges using a ParameterSearchSpace. For example:
temperature: float between 0.0 and 2.0top_p: float between 0.0 and 1.0frequency_penalty: float between -2.0 and 2.0Global Search Phase:
Local Search Phase (optional):
local_search_ratio and local_search_scale.Parameter Importance Analysis:
Result: Returns the best parameter configuration found, along with detailed optimization history and parameter importance rankings.
The optimizer intelligently balances exploration (trying diverse parameters) with exploitation (refining promising configurations) to efficiently find optimal settings.
The core of this optimizer relies on robust evaluation where each parameter configuration is assessed using your metric against the dataset. Understanding Opik’s evaluation platform is key to effective use:
The key parameters are:
model: The LLM used for evaluation with different parameter configurations.default_n_trials: Default number of optimization trials (can be overridden in optimize_parameter).n_threads: Number of parallel threads for evaluation (balance with API rate limits).local_search_ratio: Ratio of trials dedicated to local search around best parameters (0.0-1.0).local_search_scale: Scale factor for local search range (0.0 = no local search, higher = wider range).seed: Random seed for reproducibility.verbose: Logging level (0=warnings only, 1=info, 2=debug).The ParameterSearchSpace defines which parameters to optimize and their valid ranges. It supports:
You can optimize nested parameters in model_parameters:
The ParameterOptimizer supports all models available through LiteLLM. This provides broad compatibility with providers like OpenAI, Azure OpenAI, Anthropic, Google, and many others, including locally hosted models.
Start Simple
Define Reasonable Ranges
Trial Budget
Local Search
local_search_ratio=0.3 (default) for refinementParallel Evaluation
n_threads based on API rate limitsParameter Importance
parameter_importance in resultsValidation
validation_dataset parameter, it doesn’t improve performance due to the optimizer’s internal implementation and we don’t recommend using itevaluate_prompt() on a held-out test dataset after optimization completes