Exercises — Hyperparameter tuning for deep nets
Before we start, three tiny reminders so no symbol is unearned:
Level 1 — Recognition
L1.1
Classify each of the following as a parameter (learned by gradient descent) or a hyperparameter (set before training): (a) a weight in layer 2, (b) the learning rate , (c) the number of layers , (d) a bias , (e) the dropout probability .
Recall Solution
A parameter is anything gradient descent updates by minimizing the training loss; a hyperparameter is a knob you fix before that loop and tune on validation.
- (a) weight → parameter
- (b) → hyperparameter (it acts outside the loss; the loss isn't usefully differentiable in it)
- (c) → hyperparameter (and discrete — you can't take a gradient in "3.5 layers")
- (d) bias → parameter
- (e) dropout → hyperparameter
L1.2
The parent note ranks learning rate as #1 in impact. State in one sentence why it outranks everything else, referring to the update rule.
Recall Solution
Because the update is : the factor multiplies every gradient of every parameter at every step, so it alone decides whether training converges, crawls, or diverges. Every other knob is a refinement that only matters once is roughly right.
Level 2 — Application
L2.1
You want to search learning rate log-uniformly over . You draw a uniform random number on . Map it to the exponent range and compute the sampled .
Recall Solution
WHAT: we sample the exponent uniformly, then raise 10 to it — that is what makes decades equally likely (see the figure below). The exponent range is , width . Map into it: .

Look at the figure: on the linear axis (top) the tick is crammed against zero and almost never gets sampled; on the log axis (bottom) it sits a full quarter of the way along, exactly matching .
L2.2
Apply the linear scaling rule. You trained well with batch size and learning rate . You now switch to . What learning rate should you start from?
Recall Solution
WHY this rule: doubling the batch halves the gradient noise but also means one big step now covers what several small steps used to; to keep the expected parameter displacement the same, scale by the same factor as the batch. Factor . (In practice you'd add warmup, because the linear rule frays for very large .)
L2.3
An L2 penalty gives the update . With and , by what fraction does a weight shrink each step before the gradient is applied? If the gradient were exactly zero, what would become after 2 steps starting from ?
Recall Solution
The decay factor is , so it shrinks by each step. With , .
Level 3 — Analysis
L3.1
You run a grid search (125 trainings) over three hyperparameters, but only one of the three actually affects the loss. How many distinct values of the important hyperparameter does the grid test? How many would random search with the same 125-run budget test (in expectation, all distinct)? Explain the difference in one sentence.
Recall Solution
Grid: the important knob only takes its 5 grid values; the other two dimensions just repeat those 5 values 25 times each — so you get 5 distinct settings of what matters and 120 wasted duplicates. Random: each of the 125 runs draws an independent value of the important knob, so you test it at 125 distinct values. One sentence: grid search wastes budget re-testing along dimensions that don't matter, while random search automatically spends its whole budget resolving whichever dimension does matter.

The figure shows both: on the grid (left) the projection onto the important axis lands on only 5 columns; on random (right) the projection spreads across the whole axis.
L3.2
In an LR range test the loss-vs- curve is flat, then drops steeply over , then shoots up past . The steepest descent is around . Why do we pick below the point of minimum loss, e.g. , rather than at it?
Recall Solution
WHAT the three regions mean: flat = too small (negligible progress); steep = the productive band; rising = too large, updates overshoot and the loss diverges. The minimum-loss point on this curve sits right next to the divergence region — training there is on the edge of instability, and a slightly noisier batch can tip it into blow-up. Choosing roughly one decade below () gives a margin of safety: still deep in the productive band, but far from the cliff.
Level 4 — Synthesis
L4.1
You have a compute budget of 240 GPU-hours. Each full training takes 2 hours. You must tune 5 hyperparameters. (a) If you used a full grid with 5 values per hyperparameter, how many GPU-hours would it need — is it feasible? (b) How many random-search trials fit in your budget? (c) Suppose ASHA early-stopping kills 3 out of every 4 trials after just 0.5 h (only the surviving 1/4 run the full 2 h). Roughly how many trials can you now start within 240 h?
Recall Solution
(a) Grid: trainings GPU-hours. Budget is 240 h → grid needs your budget → infeasible. (b) Random full-length trials: trials. (c) With ASHA, average cost per started trial . Trials you can start → about 274 trials (vs 120), because most die cheaply. Early stopping lets you sample far more configurations for the same budget.
L4.2
Combine the log-uniform rule with the linear scaling rule. You sample log-uniformly on and independently pick a batch size from . A trial draws exponent-fraction and batch , while your reference setup that this was calibrated for used . What final learning rate does this trial run with?
Recall Solution
Step 1 — draw . Range , width . Exponent , so . Step 2 — scale for batch. , so . The two rules compose cleanly: log-uniform decides the order of magnitude, linear scaling corrects for the batch size on top of it.
Level 5 — Mastery
L5.1
Design a complete tuning procedure for a new deep net, and justify the order of steps. You get to touch the test set exactly once. List the steps and, for each, say what it protects against.
Recall Solution
A defensible order (matches the parent's 80/20 recipe), each step earning its place:
- Overfit a tiny batch (10 samples) to ~0 loss. Protects against: silent bugs — if the net can't memorize 10 points, the code/architecture is broken; tune nothing yet.
- LR range test to find . Protects against: wasting the whole budget with a bad learning rate. This is the highest-impact single move ( is rank #1).
- Pick a schedule (warmup + cosine decay). Protects against: instability early (warmup) and slow crawling late (decay); see Learning Rate Schedules and Warmup.
- Random search , , dropout together — log scale for and . Protects against: grid's combinatorial explosion and against poor resolution on the important axis.
- Early stopping / ASHA. Protects against: spending full budget on doomed runs; buys breadth (L4.1).
- Tune architecture (depth/width) last, as a validation-scored hyperparameter. Protects against: overfitting from blindly maxing capacity (bigger ≠ better without regularization).
- Touch the test set once. Protects against: optimistic bias — any choice made using the test set leaks into the model. See Cross-Validation and Data Splits.
L5.2
Prove the log-uniform density claim from scratch: show that if and , then the density of is proportional to , and therefore each decade inside carries equal probability.
Recall Solution
WHY change of variables: is flat, but we care about the spread of ; to move a density from to we multiply by (the change-of-variable rule for probability densities — it keeps total probability at 1). Since , The density of is the flat on . Therefore
\ \propto\ \frac{1}{\eta}.$$ **Equal-per-decade:** the probability inside a decade $[10^k,10^{k+1}]$ is $$\int_{10^k}^{10^{k+1}} \frac{1}{(b-a)\,\eta\,\ln 10}\,d\eta = \frac{1}{(b-a)\ln 10}\Big[\ln\eta\Big]_{10^k}^{10^{k+1}} = \frac{\ln 10^{k+1}-\ln 10^{k}}{(b-a)\ln 10} = \frac{\ln 10}{(b-a)\ln 10} = \frac{1}{\,b-a\,}.$$ This is **the same value for every $k$** — it depends only on the decade *width* being 1, not on which decade. Hence each decade is sampled with equal probability. $\blacksquare$See also: Gradient Descent and SGD, Adam and Momentum Optimizers, Regularization - L2 and Dropout, Bias-Variance Tradeoff, Batch Normalization.