Skip to content

Added optional hyperparameter sweep support using Optuna. - #40

Draft
TahaZahid05 wants to merge 5 commits into
mainfrom
hyperparam-sweep
Draft

Added optional hyperparameter sweep support using Optuna.#40
TahaZahid05 wants to merge 5 commits into
mainfrom
hyperparam-sweep

Conversation

@TahaZahid05

Copy link
Copy Markdown
Collaborator

What's New

  • Optuna Integration: Core sweep runner logic in sweep.py and sweep_utils.py supporting grid, random, and tpe search strategies.
  • CLI Updates: Added a --sweep flag to trainite init to generate a boilerplate sweep.yaml configuration, runner files, and add optuna dependency to pyproject.toml.
  • Validation: Added SweepConfig and ParameterRange Pydantic schemas to validate target parameters and their search spaces.
  • Tests: Added new tests for configuration validation, parameter overrides, and CLI execution in tests/config/base_test.py and tests/cli_test.py.

@aaishwarymishra

Copy link
Copy Markdown
Member

@TahaZahid05 can you tell me how generated code will look like?

Comment thread trainite/config/sweep.py
return self


class PruningConfig(BaseModel):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is super verbose, I think instead of us managing and handling every case, we could simply use a default pruning technique instead. If user wants he can edit the code.

Comment thread trainite/config/sweep.py

class ParameterRange(BaseModel):
model_config = ConfigDict(validate_assignment=True, extra="forbid")
type: Literal["int", "float"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

categorical can also be present

Comment thread trainite/config/sweep.py
n_trials: int | None = None
storage: str | None = None
pruning: PruningConfig = PruningConfig()
parameters: dict[str, list[Any] | ParameterRange]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dict config will be bad here I think because for every parameter, there will be an extra nested arguments.

I think we should use a list here, with target here being consistent with other configs.

- `trainer.py`: Defines the training and evaluation logic. You can override `train_step` or `eval_step` here.
- `config.py`: Contains Pydantic models for configuration validation. If you add new parameters to `config.yaml`, update the models here.
- `utils.py`: Shared utilities for configuration and logging.
{{sweep_project_structure}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweeping is a completly extra feature, so I think we should generate a separate readme for it entierely.

@aaishwarymishra

Copy link
Copy Markdown
Member

Also about the metric_name, and other parameters, they will be unique to use case to use case right? hmm, I am not sure how would we generate them for different setup.

I think you should consult victor about it, if we should even support sweeping or not as it was more of an prototype to check if it should be added or not.

@TahaZahid05

Copy link
Copy Markdown
Collaborator Author

@aaishwarymishra should SweepConfig also have only a default strategy or like three stratigies like grid, random, and tpe only and the rest can be defined by user if needed? Asking since you pointed out the verbosity in PruningConfig and this class also struggles with it a bit ig. thoughts? Also, I am thinking of keeping median as default for SweepConfig. does that sound fine?

@aaishwarymishra

Copy link
Copy Markdown
Member

@aaishwarymishra should SweepConfig also have only a default strategy or like three stratigies like grid, random, and tpe only and the rest can be defined by user if needed? Asking since you pointed out the verbosity in PruningConfig and this class also struggles with it a bit ig. thoughts? Also, I am thinking of keeping median as default for SweepConfig. does that sound fine?

yes, I think the main functionality the sweeper should provide is the easy way to run multiple experiments with different values. we should not try to handle every possible combination of parameter like strategy, we provide default, user can change it however they want. This keeps code and yaml clean.

@TahaZahid05
TahaZahid05 force-pushed the develop branch 2 times, most recently from 29b6131 to 25ef6d9 Compare June 16, 2026 13:59
@TahaZahid05
TahaZahid05 marked this pull request as draft June 19, 2026 20:19
Base automatically changed from develop to main June 23, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants