Hyperparameter Optimization with Optuna and Ray Tune — HPO Experience

The model shows unstable quality, while manual tuning of settings consumes weeks of team effort. We set up systematic parameter tuning as a turnkey service: define the search mode, automate the training and configuration selection loop. This reduces model preparation time many times over and makes the result reproducible.
Frequently Asked Questions

Hyperparameter Optimization: Where Exactly Model Quality Is Lost

Model quality is lost not at the architecture selection stage, but in the procedure of tuning model parameters.

When the search space is set by eye and the number of runs is limited by time, hyperparameter optimization degenerates into trying several plausible combinations — and the outcome depends on who tried them and in what order.

The first source of error is unstable metrics. On a small validation set, the spread between neighboring configurations is comparable to the effect of the parameter itself: a difference of a fraction of a percent is noise, not an improvement.

If you do not average the metric over several splits and do not fix the initial state of the random number generator, a random combination becomes the winner.

The second issue is implicit overfitting to validation. When the same set is used both to select the configuration and to decide when to stop training, it ceases to be an independent estimate.

The model looks good on validation and diverges from it on new data, and the divergence is discovered only after deployment to production.

Third, manual iterations. Each cycle of “changed a parameter, restarted training” leaves no history: it is unclear which configuration produced which result and on which split. Training reproducibility breaks, and reproducing a successful run a month later is no longer possible.

We treat tuning as an engineering procedure: fixed splits, a separate holdout set, a log of all runs with parameters and metrics, Bayesian search such as Optuna and Ray Tune instead of manual trial and error. Below is how this looks in practice.

What Systematic Hyperparameter Optimization During Training Provides

Systematic hyperparameter optimization begins with a verifiable criterion: how many runs are needed to reach the target model quality.

With manual trial and error, an engineer guesses the learning rate and regularization strength, wasting runs on configurations that are clearly worse than ones already tested.

Guided search builds a surrogate model from past runs and suggests the next point where improvement is expected — the path to the desired metric is shortened severalfold, not by percentages.

Model quality is assessed not by a single number but by the spread of the metric across several splits.

We fix random number generator seeds, stratify samples, and compute the metric on cross-validation — then it is clear that the improvement is real and not pulled out by a lucky split.

A narrow spread makes a settings change interpretable, and the decision to roll out the model is made based on data, not intuition.

Computational load is limited by early stopping: a configuration that loses to the leader in the first epochs does not occupy hardware until the end.

The remaining runs proceed in parallel, so the search fits within the same time budget as a single sequential sweep but covers a noticeably larger parameter space.

Experiment reproducibility rests on the log: parameters, data version, split, and resulting metric are saved for each run.

A month later, any study can be brought up, the best run repeated, and compared with a new hypothesis — the result does not depend on who obtained it or when.

It is worth checking along these axes: time to the target metric, quality stability on new data, computational volume, and repeatability — if at least one is not controlled, the search turns into a lottery.

Search Modes: Grid, Random Search, Bayesian Optimization

The search space is how many configurations exist in principle: number of layers, learning step, regularization coefficient, context length, and their allowable ranges. The search mode determines which points from this volume we actually train and in what order.

With ten parameters, a grid unfolds into thousands of runs, so the mode is chosen based on the dimensionality of the space and the smoothness of the target metric.

How to Choose a Mode for the Task

Option When It Fits Limitations
Grid search 2–3 parameters, ranges are known, a reproducible dependency map is needed Number of runs grows as the product of values along axes; with 6+ parameters the budget runs out before the grid does
Random search Wide space, some parameters have little effect Does not accumulate knowledge: promising regions are found by chance, the tail of the budget goes to clearly weak points
Bayesian optimization Expensive training, 5–15 parameters, metric is continuous Needs a reasonable start and correct ranges; on jagged and discrete metrics the gain drops
Random warm-up, then Bayes No prior knowledge about the metric landscape Harder to maintain: must monitor surrogate model quality

Early stopping works on top of any mode and does not replace it. Intermediate metrics are taken over part of the epochs, and an attempt lagging behind the best is stopped — resources go to promising configurations.

Schedulers such as Optuna and Ray Tune provide all three modes and pruning in one loop, so changing the mode is a matter of configuration, not rewriting the training.

Stages of Implementing the Model Parameter Tuning Cycle

The parameter tuning cycle breaks not on mathematics but on the lack of reproducibility: data is prepared manually, the target metric changes from run to run, results settle in scattered notebooks.

Below is the sequence of work after which parameter tuning becomes part of the training loop rather than a one-off action before release.

  1. Training loop audit. We review data preparation, fixing splits into samples, calculation of the target metric, and duration of one run. The output is a map of bottlenecks and an estimate of how many trials actually run in parallel.

  2. Experiment plan. We agree on the baseline, ranges and step for each parameter, the run budget, and the stopping rule. We separately note secondary metrics so the model is not selected by a single number.

  3. Search setup. We set up a scheduler (for example, Optuna), enable early stopping of clearly weak runs, and a trial log. Each run saves the configuration, split, and model artifact — the result is reproduced with one launch.

  4. Robustness check. We run the winning configuration on several splits and initial conditions, looking at the metric spread and behavior on rare classes. If the spread is comparable to the improvement, the configuration is not accepted.

  5. Solution handover. We provide the search space schema, working configuration, trial log, and launch procedure, and train the team on its own data.

  6. Support for the first cycles. We conduct several repeat tuning runs together with the team: refine ranges, analyze metric degradations. After that, the cycle lives without us — according to the procedure.

Output Artifacts: Configurations, Reports, Procedures

Artifacts are what distinguishes a handed-over solution from a one-off demonstration.

We deliver a set of files by which the model can be rebuilt and rechecked without the author: search parameters are not hardcoded but lie next to a description of the data on which they were obtained.

  • Training configurations — a separate file with the search space, value bounds, and fixed generator seed; a repeat run gives a comparable result, not “however it turned out.”
  • Experiment log — a table for each run: parameters, validation metric, duration, status. It shows which combinations were tested and why the final one was chosen.
  • Metrics report — comparison of the baseline and tuned model broken down by segments: where there is improvement, where there is none, and what produced the gain.
  • Launch procedure — the order of steps: data preparation, search, fixing the best configuration, validation on a holdout set. A new engineer repeats the cycle without the author.
  • Solution documentation — architecture, input and output data, dependencies, and limitations; answers the question of what to do if quality drops.
  • Acceptance checklist — the criteria by which tuning is considered complete: target metric achieved, spread between runs is normal, rollback to the previous configuration is possible.

We verify each item together with your team: we run the search on your side, check the log and metrics. If something does not reproduce, it is our area of responsibility, not a “question for the environment.”

Case Study: How We Cut Configuration Trial and Error Severalfold

In one document recognition project, model configuration tuning relied on manual trial and error: an engineer set values, started training, and used the log to decide where to go next.

One task took 40–60 runs, tuning stretched over a week, and the spread of final quality between runs on the same data reached eight percent — the result depended on who tried parameters and in what order.

We moved tuning into a single optimization loop on Optuna: the search space was described in a configuration file with parameter types and bounds, a logarithmic scale was set for some of them, early stopping by intermediate metric and repeat runs with a fixed random seed were enabled.

Each attempt goes into the log together with parameters and result, so the best configuration is reproduced with one command rather than reconstructed from someone else's memory.

After implementation, tuning takes 12–18 runs instead of 40–60: the loop itself prunes weak branches and does not spend training on them.

The quality spread between runs decreased from eight to two percent, tuning time — from a week to one day, and rollback to the previous configuration takes minutes because its parameters, metrics, and the data version on which they were obtained lie alongside.

Stability here is more important than peak metric: a model that gives a similar result on retraining can be put into operation and updated without surprises. It is this margin of reproducibility that we consider the main result of implementation.

How Bayesian Optimization Differs from Random Search

Random search takes values from specified distributions independently of one another — each next point is not connected to what previous runs showed.

In a space of a dozen parameters, where two or three actually matter, this gives uniform coverage and converges no worse than a grid, but without explosive growth in the number of combinations. There is no overhead: no model is built, runs are independent and go in parallel.

Bayesian optimization works with history. From all past runs, a surrogate model is built — a density estimate of the objective function, as in Optuna, or a Gaussian process — and it predicts where the metric is more likely to improve.

The next point is placed where the expected benefit is maximal: the search concentrates around promising regions and explores axes with different sensitivity differently. The price for this is rebuilding the model at each step and the sequential nature of suggestion.

The selection criterion is the ratio of costs. If one training run takes tens of minutes and the budget is limited to a couple hundred runs, Bayesian optimization pays off through fewer iterations to the target metric.

If there are more than twenty parameters, the objective function is discontinuous, or the budget is measured in dozens of points, random search is no worse: a surrogate model on such history does not train well and leads the search to a false optimum. When broad parallelism is needed, independent runs also win.

In practice, we combine them: an initial random sample provides data for the model, then Bayesian mode is enabled, and we compare methods by the number of runs to the desired quality at a fixed budget. This way, selection criteria stop being a matter of taste.

Limitations of the Method: Noisy Metrics, Expensive Runs, Overfitting

The method stops working predictably when there is no clear gap between configurations. The target metric on real data is almost always noisy, so the best result from one run may be a random spike and not reproduce on the next run.

We compare not by a single number but by several runs: we look at the median and spread, and discard options with a wide spread even if their peak value is higher. Result stability here is more important than a beautiful maximum.

The second boundary is the cost of a run: when training one configuration takes hours, a full sweep does not fit into a reasonable timeframe.

We work in a cascade — first a rough estimate on part of the data and a reduced number of steps, then refinement only for promising points, while the rest are interrupted by intermediate metrics without being counted to the end.

We separately monitor overfitting to validation: if we select a configuration on the same set on which we then measure, the metric grows, but quality on new data does not.

Therefore, we keep a holdout slice that does not participate in selection and limit the total number of attempts.

Configurations do not differ from each other within the spread — how to choose?

We take the simpler and more stable one, not the peak by metric: a difference within noise does not confirm a real advantage. Then we refine neighboring parameters to check whether this region of the search space has a stable optimum.

How to tell that selection has adapted to validation?

We compare the metric on validation and on an independent slice that did not participate in the search.

If the gap is consistently larger than the observed spread, we repeat part of the search on another split and reduce the number of attempts; otherwise, the advantage will remain only on paper.

Let's Discuss the Task: We Will Select a Search Mode for Your Model

To come back with an estimate and work plan rather than general words, we need project inputs: how training is set up now, by which metric you judge quality, and what constraints exist on run time.

Based on them, we select a search mode — from simple grid search to Bayesian search with early pruning of weak runs.

  • Quality metric: what exactly we optimize, whether it is computed on a holdout set, and whether there is a second metric that must not be degraded.
  • Current training loop: where experiments are launched, how long one run takes, and how many tasks can be run in parallel.
  • Parameter space: which parameters change, their ranges and types, which combinations have already been tested and turned out to be dead ends.
  • Time constraints: how much time is allotted for the entire search, whether there is a hard deadline, and whether it is acceptable to stop clearly weak runs early.
  • Expected result: what metric improvement we consider success — whether you need the best single model or a stable result independent of random initialization.
  • Access and storage: how to run experiments in your loop, where to put run history, and where to store configurations of the best options.

Describe the task within these boundaries — we will come back with an estimate and work plan: which search mode will fit, how many runs will be needed, and what you will get as output.

AI Development Areas

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1393
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1368
  • B2B Advance company logo design
    B2B Advance company logo design
    815
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1139
  • AIDER company logo development
    AIDER company logo development
    1057
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1152