HPO Optimizers API¶
GAM Optimizer¶
GAMOptimizer ¶
GAMOptimizer(
objective_function: Callable[[dict], float],
search_space: SearchSpace,
settings: GAMOptSettings,
known_observations: list[dict] | None = None,
)
Bases: BaseOptimizer
Optimizer based on Generalized Additive Models. Trained model is used to suggest next node in the search space for evaluation.
Parameters:
-
objective_function(Callable[[dict], float]) –Target function that will be used in every evaluation. Output of this function should be 'float', as this is the value for which algorithms try to optimize solution. Function should take dict filled with 'key: value' pairs that are 'argument: corresponding value'.
-
search_space(SearchSpace) –Instance containing information about nodes in the solutions space that will be evaluated during the optimization.
-
settings(GAMOptSettings) –Instance with settings required for configuring the optimization process.
Attributes:
-
evaluations(list[dict]) –Already evaluated hyperparameters combinations with corresponding score.
-
max_iterations(int) –Validated maximum number of iterations during HPO.
Source code in ai4rag/core/hpo/gam_opt.py
Attributes¶
max_iterations property writable ¶
Get max possible number of iterations for the HPO.
Functions¶
search ¶
Actual function performing hyperparameter optimization for the selected objective function.
Returns:
-
dict[str, Any]–The best set of parameters with achieved score.
Raises:
-
OptimizationError–When there were no successful evaluations for given constraints.
Source code in ai4rag/core/hpo/gam_opt.py
evaluate_initial_random_nodes ¶
Perform evaluation of randomly chosen n nodes from the solutions space. Evaluations are performed until desired number of successful evaluations is reached or maximum number of evaluations is reached.
When the optimizer has been warm-started with known observations, already-successful evaluations count toward the n_random_nodes target and already-evaluated combinations are excluded from candidates.
Source code in ai4rag/core/hpo/gam_opt.py
GAMOptSettings dataclass ¶
GAMOptSettings(max_evals: int, n_random_nodes: int = 4, evals_per_trial: int = 1, random_state: int = 64)
Bases: OptimizerSettings
Settings for the GAMOptimizer. For the detailed description of parameters for Generalized Additive Models, please see pygam documentation.
Random Optimizer¶
RandomOptimizer ¶
RandomOptimizer(objective_function: Callable[[dict], float], search_space: SearchSpace, settings: RandomOptSettings)
Bases: BaseOptimizer
Optimizer running random search on the given search space.
Source code in ai4rag/core/hpo/random_opt.py
Functions¶
search ¶
Actual function performing hyperparameter optimization for the selected objective function.
Returns:
-
dict[str, Any]–The best set of parameters with achieved score.
Raises:
-
OptimizationError–When there were no successful evaluations for given constraints.
Source code in ai4rag/core/hpo/random_opt.py
RandomOptSettings dataclass ¶
Bases: OptimizerSettings
Settings for random optimizer.