{"slug": "how-do-you-run-hyperparameter-sweeps-on-cloud-gpus", "title": "How do you run hyperparameter sweeps on cloud GPUs?", "summary": "A developer at Nodus Compute benchmarked hyperparameter sweep strategies on cloud GPUs, running 36 trials of a scikit-learn MLPClassifier on the 1,797-image digits dataset across grid, random, and Optuna TPE samplers with and without pruning. TPE reached 98% validation accuracy in 31.7% of trials versus 12.8% for grid search, while successive halving pruning cut epochs used from 1,080 to 386.8 and wall time from about 95 to 35 seconds, though it dropped the share of successful trials to 11.7%. The writeup recommends running each trial as its own GPU job with per-trial and sweep-wide spending caps, priced as trials times GPU-hours times hourly rate.", "body_md": "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.\n\nThis 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](https://www.nodus-compute.ai/blog/llm-training-cost-calculator/) instead.\n\nA 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.\n\nThree common tools handle the search side. [Weights & Biases Sweeps](https://docs.wandb.ai/guides/sweeps/) offers `grid`, `random` and `bayes` search methods. [Optuna](https://optuna.readthedocs.io/en/stable/tutorial/10_key_features/004_distributed.html) runs many worker processes against one shared storage backend. [Ray Tune](https://docs.ray.io/en/latest/tune/api/doc/ray.tune.schedulers.ASHAScheduler.html) ships an ASHA scheduler that stops weak trials early.\n\nNone 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.\n\nRandom 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.\n\nEach 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](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.pruners.MedianPruner.html), and with its [successive halving pruner](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.pruners.SuccessiveHalvingPruner.html).\n\nWe kept the script and the raw per-trial results, so every number below traces to a logged trial.\n\n| Method | Trials clearing 98% val. accuracy | Epochs used (of 1,080) | Wall time per search (1 CPU core) | \n|---|---|---|---|\n| Grid | 12.8% | 1,080 | 105.4 s | \n| Random | 20.0% | 1,080 | 88.5 s | \n| TPE (Optuna) | 31.7% | 1,080 | 95.5 s | \n| TPE + median pruning | 26.1% | 647.6 | 58.9 s | \n| TPE + successive halving | 11.7% | 386.8 | 34.7 s | \n\n*Means over 5 search seeds. Optuna 5.1.0, scikit-learn 1.9.1, run November 27, 2026.*\n\n*Grid search spent the most trials on settings that were never going to work.*\n\nThe 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](https://www.jmlr.org/papers/v13/bergstra12a.html) that randomly chosen trials are more efficient than trials on a grid.\n\nMostly 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.\n\n*Pruning, not the search method, is what shrinks the bill.*\n\nMedian 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.\n\nNot 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.\n\nWrite 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](https://www.nodus-compute.ai/docs/guides/sweeps/)'s manifest shape with a 36-trial random search:\n\n```\napiVersion: nodus.dev/v1\nkind: Sweep\nmetadata:\n  name: lr-search\nspec:\n  maxCostUSD: \"216\"        # 36 trials x $6.00 per-trial cap\n  maxParallel: 12\n  matrix:\n    gpu: [H100]\n    params:\n      TRIAL: [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"11\",\n              \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\",\n              \"24\", \"25\", \"26\", \"27\", \"28\", \"29\", \"30\", \"31\", \"32\", \"33\", \"34\", \"35\"]\n  template:\n    kind: Job\n    spec:\n      image: nodus/pytorch\n      timeout: 3h\n      maxCostUSD: \"6.00\"   # per-trial cap\n      command: [python, train.py]\n      outputs:\n        - name: metrics\n          path: /nodus/outputs/metrics.json\n```\n\nThe 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:\n\n``` python\nimport json, os, random\n\ntrial = int(os.environ[\"NODUS_PARAM_TRIAL\"])\nrng = random.Random(trial)                      # same TRIAL, same settings\ncfg = {\n    \"lr\": 10 ** rng.uniform(-5, -3),            # log scale\n    \"weight_decay\": 10 ** rng.uniform(-4, -1),\n    \"batch_size\": rng.choice([16, 32, 64]),\n}\nval = train_and_evaluate(cfg)                   # your training loop\nwith open(\"/nodus/outputs/metrics.json\", \"w\") as f:\n    json.dump({\"trial\": trial, **cfg, \"val\": val}, f)\n```\n\nSubmit 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.\n\nThe per-trial cap stops one bad trial; the Sweep cap stops the whole search. Our [Budgets and spending caps](https://www.nodus-compute.ai/docs/guides/billing/budgets/) 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.\n\nSet 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](https://www.nodus-compute.ai/blog/ai-agent-gpu-spending-limits/).\n\nMultiply 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.\n\n| GPU (rate on the Nodus pricing page) | Full search | Median pruning (60.0%) | Successive halving (35.8%) | \n|---|---|---|---|\n| L4, $0.43/hr | $30.96 | $18.58 | $11.08 | \n| A100 80 GB, $1.09/hr | $78.48 | $47.09 | $28.10 | \n| H100 SXM, $2.60/hr | $187.20 | $112.32 | $67.02 | \n\n*Prices checked November 27, 2026 on the [Nodus pricing page](https://www.nodus-compute.ai/pricing/), which lists the L4 at $0.43/hr, the A100 80 GB at $1.09/hr and the H100 SXM at $2.60/hr.*\n\n*Pruning cut the bill by 40% to 64% on every GPU; the hourly rate only sets the scale.*\n\nElapsed 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.\n\nRun 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.\n\nAt 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](https://www.nodus-compute.ai/blog/resume-training-after-spot-preemption/) keeps it from starting over.\n\n`maxParallel` when you need results sooner; it does not change the bill.\nThere 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.\n\nTune 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.\n\nThe 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.\n\nIt 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.\n\n*Originally published on the [Nodus blog](https://www.nodus-compute.ai/blog/hyperparameter-sweeps-on-cloud-gpus/).*", "url": "https://wpnews.pro/news/how-do-you-run-hyperparameter-sweeps-on-cloud-gpus", "canonical_source": "https://dev.to/viswaretas_kotra/how-do-you-run-hyperparameter-sweeps-on-cloud-gpus-2ebl", "published_at": "2026-11-27 22:10:16+00:00", "updated_at": "2026-11-27 22:14:10.816841+00:00", "lang": "en", "topics": ["machine-learning", "ai-infrastructure", "mlops", "ai-tools"], "entities": ["Nodus Compute", "Optuna", "Weights & Biases", "Ray Tune", "scikit-learn", "Bergstra", "Bengio"], "also_reported_by": [], "takeaway": "On a 36-trial sweep, Optuna TPE cleared 98% validation accuracy in 31.7% of trials versus 12.8% for grid search, and successive halving pruning cut epochs from 1,080 to 386.8 at the cost of fewer successful trials.", "recommendation": {"advice": "Run each sweep trial as its own parallel GPU job with per-trial and sweep-wide spend caps, and prefer random or TPE sampling over grid search to avoid repeating bad hyperparameter values.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/how-do-you-run-hyperparameter-sweeps-on-cloud-gpus", "markdown": "https://wpnews.pro/news/how-do-you-run-hyperparameter-sweeps-on-cloud-gpus.md", "text": "https://wpnews.pro/news/how-do-you-run-hyperparameter-sweeps-on-cloud-gpus.txt", "jsonld": "https://wpnews.pro/news/how-do-you-run-hyperparameter-sweeps-on-cloud-gpus.jsonld"}}