optuna_tune ¶
Optuna tuning module.
Classes:
-
Objective
–Objective class for Optuna tuning.
Functions:
-
get_device
–Get the appropriate device (CPU/GPU) for computation.
-
tune_loop
–Run the tuning loop.
Objective ¶
Objective(
model_class: Module,
network_params: dict[
str, TunableParameter | VariableList
],
optimizer_params: dict[str, TunableParameter],
data_params: dict[str, TunableParameter],
loss_params: dict[str, TunableParameter],
train_torch_dataset: Dataset,
val_torch_dataset: Dataset,
artifact_store: Any,
max_batches: int = 1000,
compute_objective_every_n_batches: int = 50,
target_metric: str = "val_loss",
device: device | None = None,
)
Objective class for Optuna tuning.
Parameters:
-
model_class
(Module
) –The model class to be tuned.
-
network_params
(dict[str, TunableParameter | VariableList]
) –The network parameters to be tuned.
-
optimizer_params
(dict[str, TunableParameter]
) –The optimizer parameters to be tuned.
-
data_params
(dict[str, TunableParameter]
) –The data parameters to be tuned.
-
loss_params
(dict[str, TunableParameter]
) –The loss parameters to be tuned.
-
train_torch_dataset
(Dataset
) –The training dataset.
-
val_torch_dataset
(Dataset
) –The validation dataset.
-
artifact_store
(Any
) –The artifact store to save the model and optimizer.
-
max_batches
(int
, default:1000
) –The maximum number of batches to train.
-
compute_objective_every_n_batches
(int
, default:50
) –The number of batches to compute the objective.
-
target_metric
(str
, default:'val_loss'
) –The target metric to optimize.
-
device
(device | None
, default:None
) –The device to run the training on.
Methods:
-
objective
–Compute the objective metric(s) for the tuning process.
-
save_checkpoint
–Save the model and optimizer to the trial.
Source code in src/stimulus/learner/optuna_tune.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
objective ¶
objective(
model: Module,
train_loader: DataLoader,
val_loader: DataLoader,
loss_dict: dict[str, Module],
) -> dict[str, float]
Compute the objective metric(s) for the tuning process.
Source code in src/stimulus/learner/optuna_tune.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
save_checkpoint ¶
save_checkpoint(
trial: Trial,
model_instance: Module,
optimizer: Optimizer,
) -> None
Save the model and optimizer to the trial.
Source code in src/stimulus/learner/optuna_tune.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
get_device ¶
get_device() -> device
Get the appropriate device (CPU/GPU) for computation.
Returns:
-
device
–torch.device: The selected computation device
Source code in src/stimulus/learner/optuna_tune.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
tune_loop ¶
tune_loop(
objective: Objective,
pruner: BasePruner,
sampler: BaseSampler,
n_trials: int,
direction: str,
storage: BaseStorage | None = None,
) -> Study
Run the tuning loop.
Parameters:
-
objective
(Objective
) –The objective function to optimize.
-
pruner
(BasePruner
) –The pruner to use.
-
sampler
(BaseSampler
) –The sampler to use.
-
n_trials
(int
) –The number of trials to run.
-
direction
(str
) –The direction to optimize.
-
storage
(BaseStorage | None
, default:None
) –The storage to use.
Returns:
-
Study
–The study object.
Source code in src/stimulus/learner/optuna_tune.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|