How do you run hyperparameter sweeps on cloud GPUs?
DEV Community

How do you run hyperparameter sweeps on cloud GPUs?

Run each trial as its own GPU job, launch them in parallel, and put a spending cap on every trial and on the sweep as a whole. On Nodus, a Sweep runs one Job template for every combination of the values you list, caps the combined spend with maxCostUSD, and reports what each trial cost.

Price it as trials x GPU-hours per trial x hourly rate, then cut it with early stopping, which used 36% to 60% of the full compute in our test. This post shows the setup, a small sweep we ran ourselves, and the cost math for sizing a real one.

If you are pricing a single training run, start with our LLM training cost calculator instead.

What does a hyperparameter sweep on cloud GPUs look like?

A sweep is the same training script run many times with different settings, such as learning rate, weight decay and batch size. Each run is a trial. Grid and random trials don't depend on each other, so they parallelize perfectly: 36 trials on 12 GPUs finish in a third of the time of 36 trials on 4 GPUs, and cost the same.

Three common tools handle the search side. Weights & Biases Sweeps offers grid, random and bayes search methods. Optuna runs many worker processes against one shared storage backend. Ray Tune ships an ASHA scheduler that stops weak trials early.

None of them decides where trials run or how much they may spend. That part is the compute platform's job, and it is where sweep bills go wrong: one diverging trial with no time limit, or 200 trials launched when you meant 20.

Which search method wastes the least compute?

Random search wasted fewer trials than grid search in our test, and pruning cut compute far more than the choice of sampler. We ran it on CPU, on a sandbox, in about 6 minutes.

The task was a small neural network (scikit-learn's MLPClassifier) on the 1,797-image digits dataset, tuning learning rate, L2 penalty, hidden size and batch size. Each method got 36 trials of up to 30 epochs, repeated over 5 search seeds. The grid was 3 x 3 x 2 x 2 = 36 cells. Random search and TPE drew learning rate and L2 penalty from log-scale ranges covering the grid's values, and hidden and batch size from four choices each.

We also ran Optuna's TPE sampler alone, with its median pruner, and with its successive halving pruner. We kept the script and the raw per-trial results, so every number below traces to a logged trial.

Method Trials clearing 98% val. accuracy Epochs used (of 1,080) Wall time per search (1 CPU core)
Grid 12.8% 1,080 105.4 s
Random 20.0% 1,080 88.5 s
TPE (Optuna) 31.7% 1,080 95.5 s
TPE + median pruning 26.1% 647.6 58.9 s
TPE + successive halving 11.7% 386.8 34.7 s

Means over 5 search seeds. Optuna 5.1.0, scikit-learn 1.9.1, run November 27, 2026.

Grid search spent the most trials on settings that were never going to work. The grid's problem was one axis. A third of its cells used a learning rate of 0.0001, which averaged 76% validation accuracy and never reached 97.5%. Random search doesn't repeat a bad value 12 times. That matches the finding in Bergstra and Bengio's paper that randomly chosen trials are more efficient than trials on a grid.

Does early stopping lose the best model?

Mostly no, but aggressive pruning makes the search less reliable. Every method found a best configuration around 98.5% to 98.6% validation accuracy. With 359 validation images, that spread is about one image.

Pruning, not the search method, is what shrinks the bill. Median pruning used 60.0% of the compute and reached 98% validation accuracy in a median of 4 trials, the same as TPE without pruning. Successive halving used 35.8%, but needed a median of 13 trials to reach 98%, and one of the 5 seeds never reached 98.3%.

Pick median pruning when you want savings without much risk. Pick successive halving when trials are expensive and you can afford more of them.

Can you trust the winning trial?

Not when it wins by one validation image. The grid's pick for one seed scored 98.6% on validation. Retrained for the full 30 epochs with 5 different random seeds, the same settings scored between 95.3% and 98.1% on the test set. Differences that small are noise, so re-run your top 3 configurations with 2 or 3 seeds each before you commit a long training run to one of them.

How do you run a sweep as parallel Nodus jobs?

Write one Sweep manifest, give each trial a number, and let the script turn that number into hyperparameters. A Nodus Sweep runs one Job for every combination of the values you list, and each parameter reaches your code as an environment variable: TRIAL arrives as NODUS_PARAM_TRIAL.

This is the Sweeps guide's manifest shape with a 36-trial random search:

apiVersion: nodus.dev/v1
kind: Sweep
metadata:
  name: lr-search
spec:
  maxCostUSD: "216" # 36 trials x $6.00 per-trial cap
  maxParallel: 12
  matrix:
    gpu: [H100]
    params:
      TRIAL: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35"]
  template:
    kind: Job
    spec:
      image: nodus/pytorch
      timeout: 3h
      maxCostUSD: "6.00" # per-trial cap
      command: [python, train.py]
      outputs:
        - name: metrics
          path: /nodus/outputs/metrics.json

The docs' own example inlines its script with python -c; for a real project, use an image that contains your code.

Inside train.py, seed a random generator with the trial number so each trial gets fixed, reproducible settings:

import json, os, random
trial = int(os.environ["NODUS_PARAM_TRIAL"])
rng = random.Random(trial) # same TRIAL, same settings
cfg = {
  "lr": 10 ** rng.uniform(-5, -3), # log scale
  "weight_decay": 10 ** rng.uniform(-4, -1),
  "batch_size": rng.choice([16, 32, 64]),
}
val = train_and_evaluate(cfg) # your training loop
with open("/nodus/outputs/metrics.json", "w") as f:
  json.dump({"trial": trial, **cfg, "val": val}, f)

Submit it with nodus apply -f sweep.yaml and watch it with nodus get sweep/lr-search -w. Each cell runs as a Job named lr-search-<index>, so nodus cp job/lr-search-7:outputs/metrics metrics-7.json copies one trial's result, checked against its SHA-256 digest.

How do the two spending caps work?

The per-trial cap stops one bad trial; the Sweep cap stops the whole search. Our Budgets and spending caps docs say a cap on a Sweep is shared by every run it creates, and each child Job must fit both its own cap and the Sweep's remaining cap.

At the cap, work saves its state and suspends with reason MaxCostReached instead of failing, and raising the cap resumes it. Set the trial cap a little above what one trial should cost. Here a 2-hour H100 trial costs $5.20 at $2.60/hr, so $6.00 leaves 15% headroom. Set the Sweep cap to trials x trial cap, $216, so the per-trial caps bind first.

For agents launching sweeps for you, wrap a monthly Budget around all of it, as in our guide to GPU spending limits for AI agents.

How much does a hyperparameter sweep cost?

Multiply trials by GPU-hours per trial by the hourly rate, then by the share of compute you expect pruning to leave. Parallelism changes how long you wait, not what you pay. The table prices 36 trials of 2 GPU-hours each, 72 GPU-hours in all, using the pruning shares we measured above.

GPU (rate on the Nodus pricing page) Full search Median pruning (60.0%) Successive halving (35.8%)
L4, $0.43/hr $30.96 $18.58 $11.08
A100 80 GB, $1.09/hr $78.48 $47.09 $28.10
H100 SXM, $2.60/hr $187.20 $112.32 $67.02

Prices checked November 27, 2026 on the Nodus pricing page, which lists the L4 at $0.43/hr, the A100 80 GB at $1.09/hr and the H100 SXM at $2.60/hr. Pruning cut the bill by 40% to 64% on every GPU; the hourly rate only sets the scale.

Elapsed time is the other dial. The same 72 GPU-hours take 18 hours at maxParallel: 4, 6 hours at 12 and 2 hours at 36. Pruning shares from a tiny CPU task won't transfer exactly to your model, so treat 60.0% and 35.8% as a starting estimate and measure your own after the first round.

How do you prune trials when each one is a separate job?

Run successive halving by hand in two rounds, which needs no shared state between jobs. In round one, run all 36 trials for a third of the training steps. Download the 36 metrics.json files, keep the best 12, and launch a second Sweep that lists only those 12 TRIAL values at full length.

At 2 hours per full trial, round one costs 36 x 0.67 hours and round two 12 x 2 hours, about 48 GPU-hours instead of 72. That is $124.80 instead of $187.20 on an H100.

For a final check, add a SEED parameter with three values to a third Sweep holding your top 3 trials. If a trial gets reclaimed mid-run, checkpointing keeps it from starting over.

What is the decision rule?

  • Use a grid only for 1 or 2 hyperparameters with a few known-good values. Otherwise use random search, or TPE once you have 20 or more trials.
  • Budget trials x GPU-hours per trial x hourly rate, and set the trial cap about 15% above one trial's cost.
  • Add median pruning when a trial takes more than about an hour and its early validation curve predicts its final score.
  • Use successive halving only if you can afford extra trials.
  • Raise maxParallel when you need results sooner; it does not change the bill.
  • Re-run the top 3 with 2 or 3 seeds before you call a winner.

FAQ

How many trials does a hyperparameter sweep need?

There is no fixed number, so measure how fast good trials appear. In our test of 4 hyperparameters, random search first reached 98% validation accuracy within 8 trials in all 5 seeds, and TPE within 5.

Should I tune on a small GPU and train on a big one?

Tune batch size and throughput settings on the GPU you will train on, because they depend on its memory and speed. Learning rate interacts with batch size, so keep the batch size fixed if you search it on a smaller GPU.

What is the most a Nodus Sweep can run?

The Sweeps docs set a limit of 256 cells, 16 GPU entries and 16 parameter names with 64 values each. A failed cell doesn't stop the others, and the Sweep still reports the results of the cells that succeeded.

Does pruning work for LLM fine-tuning?

It works only when the early evaluation loss ranks trials the same way the final loss does. Check that before trusting it: run 3 or 4 trials to completion and compare their early and final rankings.

Originally published on the Nodus blog.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.