optuna_tune ¶
Optuna tuning module.
Classes:
-
Objective–Objective class for Optuna tuning.
Functions:
-
tune_loop–Run the tuning loop.
Objective ¶
Objective(
model_class: type[StimulusModel],
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_samples: int = 1000,
compute_objective_every_n_samples: int = 50,
target_metric: str = "val_loss",
device: device | None = None,
)
Objective class for Optuna tuning.
Parameters:
-
model_class(type[StimulusModel]) –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_samples(int, default:1000) –The maximum number of samples to train.
-
compute_objective_every_n_samples(int, default:50) –The number of samples 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:
-
get_metrics–Compute the objective metric(s) for the tuning process.
-
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
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
get_metrics ¶
get_metrics(
model_instance: StimulusModel,
data_loader: DataLoader,
loss_dict: dict[str, Module],
device: device,
) -> dict[str, float]
Compute the objective metric(s) for the tuning process.
Source code in src/stimulus/learner/optuna_tune.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
objective ¶
objective(
model_instance: StimulusModel,
train_loader: DataLoader,
val_loader: DataLoader,
loss_dict: dict[str, Module],
device: device,
) -> dict[str, float]
Compute the objective metric(s) for the tuning process.
The objectives are outputed by the model's batch function in the form of loss, metric_dictionary.
Source code in src/stimulus/learner/optuna_tune.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
save_checkpoint ¶
save_checkpoint(
trial: Trial,
model_instance: StimulusModel,
optimizer: Optimizer,
complete_suggestions: dict,
) -> None
Save the model and optimizer to the trial.
Source code in src/stimulus/learner/optuna_tune.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
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
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |