Skip to main content
Version: v2603

intelligence.zenith_tune.presets.base

Base classes for tuning presets.

This module defines the parameter types and the TuningPreset abstract base class that are used to define hyperparameter search spaces for different frameworks.

IntParameter Objects

@dataclass
class IntParameter()

Integer parameter definition.

Arguments:

  • low - Lower bound (inclusive)
  • high - Upper bound (inclusive)
  • step - Step size for discrete values (optional)
  • default - Default value for the first trial (optional)

FloatParameter Objects

@dataclass
class FloatParameter()

Float parameter definition.

Arguments:

  • low - Lower bound (inclusive)
  • high - Upper bound (inclusive)
  • log - Whether to use log scale for sampling
  • default - Default value for the first trial (optional)

CategoricalParameter Objects

@dataclass
class CategoricalParameter()

Categorical parameter definition.

Arguments:

  • choices - List of possible values
  • default - Default value for the first trial (optional)

BoolParameter Objects

@dataclass
class BoolParameter()

Boolean parameter definition.

Arguments:

  • default - Default value for the first trial (optional)

TuningPreset Objects

class TuningPreset(ABC)

Abstract base class for tuning presets.

A preset defines the hyperparameter search space for a specific framework or use case, and provides methods to apply suggested parameters to the execution target (command line, config file, etc.).

get_search_space

@abstractmethod
def get_search_space() -> Dict[str, Parameter]

Return the search space as a dict of parameter name to definition.

Returns:

Dictionary mapping parameter names to Parameter objects.

apply_parameters

@abstractmethod
def apply_parameters(command: str, params: Dict[str, Any]) -> str

Apply the suggested parameters to the command.

Arguments:

  • command - The base command string to modify.
  • params - Dictionary of parameter name to suggested value.

Returns:

The modified command string with parameters applied.

get_default_params

def get_default_params() -> Dict[str, Any] | None

Return default parameter values from the search space.

Returns default values only when ALL parameters have defaults defined. If any parameter is missing a default, returns None.

Returns:

Dictionary of parameter name to default value, or None if not all parameters have defaults.

prune

def prune(params: Dict[str, Any]) -> bool

Check if the given parameters should be pruned (skipped).

Override this method to define constraints between parameters. When this returns True, the trial is skipped without execution.

Arguments:

  • params - Dictionary of parameter name to suggested value.

Returns:

True to prune (skip) the trial, False to execute it.

@abstractmethod
def get_recommended_strategy() -> TuningStrategy

Return the default strategy for this preset.

Returns:

Configured TuningStrategy instance.

Example:

return RandomStrategy(seed=42)

@abstractmethod
def get_recommended_evaluator() -> TuningEvaluator

Return the recommended evaluator for this preset.

Returns:

Configured TuningEvaluator instance.

Example:

return RegexEvaluator(pattern=r"loss:\s*([\d.]+)")