Concepts / Optimizers in Model Training

Optimizers in Model Training

Knowing how much memory a model needs is what lets you choose the right hardware, and often the practical question is whether a setup you already own can afford to run a particular model.

  • Programming

Why Hardware Limits Come First

Before you can run a model, you need to know whether the hardware you have can hold it. Knowing how much memory a model needs is what lets you choose the right hardware, and often the practical question is whether a setup you already own can afford to run a particular model. Training a model is more demanding than running it, and a large part of that extra demand comes from one idea: which parameters are allowed to change. This article builds that idea up step by step, starting from what a parameter is and ending with why the number of trainable parameters shapes memory use during finetuning.

What do you think happens?

During a training step, do frozen parameters get updated along with the trainable ones?

  • Yes, every parameter in the model is always updated

  • No, frozen parameters are kept unchanged

  • Only the first frozen parameter is updated

Reveal answer
Answer:

No, frozen parameters are kept unchanged

A trainable parameter is one that can be updated during finetuning, while frozen parameters are kept unchanged. The rest of this article explains what that split does to the training process and to memory.

Three Situations, Three Different Sets of Changing Parameters

The source describes three situations that differ in which parameters change. During pre-training, all model parameters are updated. During inference, no model parameters are updated. During finetuning, some or all model parameters may be updated. Of the three, finetuning is the case where the split between trainable and frozen parameters matters most, because the parameters you leave frozen are exactly the ones that do not need to be updated.

This is the first clue about where extra work comes from. Every parameter that is allowed to change has to be handled during training. Every parameter that is frozen can be left alone. Keep this distinction in mind, because the rest of the article depends on it.

Trainable Versus Frozen Parameters

Definition

A trainable parameter is a parameter that can be updated during finetuning. A frozen parameter is a parameter that is kept unchanged. Both kinds belong to the same model; the difference lies only in whether training is allowed to change them.

PropertyTrainable parameterFrozen parameter
Can it be updated during finetuning?YesNo
Does it receive a gradient during the backward pass?Yes, it gets its own gradientIt does not receive this treatment because it is not updated
Does it carry optimizer states?YesNo, because it is not updated
Effect on memory during finetuningAdds gradient and optimizer state storageDoes not add this extra storage

Trainable and frozen parameters compared during finetuning

One Training Step: Forward and Backward Pass

As of this writing, neural networks are typically trained using a mechanism called backpropagation. With backpropagation, each training step consists of two phases. The first is the forward pass, which is the process of computing the output from the input. The second is the backward pass, which is the process of updating the model's weights using aggregated signals from the forward pass. Read that carefully: the backward pass does not simply reverse the forward pass. It uses signals gathered during the forward pass to decide how the weights should change.

The order of events within one step is the thing to hold on to. The forward pass runs from the input through the model to a computed output. The backward pass then starts from the comparison between that computed output and the expected output, and works backward to adjust the trainable parameters. The diagram below traces that order across the actors involved.

InputModelExpected outputTrainable parameters1. forward pass: input enters the model2. computed output compared with expected output3. backward pass: signals flow back to trainable parameters4. trainable parameters are updated
In what order do the forward pass, loss comparison, backward pass, and parameter update happen within one training step, and which direction does data flow in each?

Whether both phases run depends on what you are doing with the model. During inference, only the forward pass is executed. During training, both passes are executed. This is the core reason inference and training have different memory needs: training carries the extra work of the backward pass.

Tracing the Loss, Gradient, and Optimizer

At a high level, the backward pass works in three stages, and each stage produces something the next stage needs. First, the backward pass computes the loss, which is the measured gap between what the model produced and what was expected. Second, it computes a gradient for each trainable parameter. Third, it uses the optimizer to decide how to adjust each parameter. The loss is the starting signal, the gradient is the per-parameter signal derived from it, and the optimizer turns those signals into an actual adjustment.

Computed outputLossGradient pertrainable parameterOptimizerAdjusted trainableparameterscompared with expected outputproduces a gradient for eachdecides adjustmentapplies adjustment
How does the loss produce gradients, and how does the optimizer use those gradients to decide how each trainable parameter changes?

Notice what the diagram does not contain: frozen parameters. Only trainable parameters get a gradient and pass through the optimizer. This is why the split between the two kinds matters for what training computes, not just for what it is allowed to change.

Trainable Parameters and Memory Use

The reason the number of trainable parameters matters is what the backward pass needs to keep around. During the backward pass, each trainable parameter comes with additional values: its gradient and its optimizer states. Each trainable parameter therefore brings gradient and optimizer state storage with it, and the more trainable parameters there are, the more memory is needed to store these additional values. This is why one key factor that determines a model's memory footprint during finetuning is its number of trainable parameters.

Trainable parameterupdated during finetuningGradientextra value per trainableparameterOptimizer statesextra value per trainableparameterFrozen parameterkept unchangedcomes withcomes with
What memory is needed for each trainable parameter, and how does that grow when more parameters are trainable versus frozen?

The source frames memory use in general terms. A model's memory footprint depends on the model, the workload, and the optimization techniques used to reduce memory usage. Because it is impossible to account for every optimization technique and workload, the source outlines only approximate calculations that give a rough idea of how much memory is needed to operate a model during inference and training. The useful takeaway for this article is directional: adding trainable parameters adds the per-parameter gradient and optimizer state burden, and freezing parameters avoids it for those parameters.

Parameter Values Before and After an Update

Consider a small model with two groups of parameters: some are trainable and some are frozen. Before the update, every parameter holds its current value. After one training step, the optimizer has adjusted the trainable parameters based on their gradients, so their values have moved. The frozen parameters still hold the values they started with. The change is selective, and the selection is determined entirely by the trainable and frozen split.

Worked Example: Hardware Check Before Running a Model

Worked example

Can this chip hold this model?

The source makes the hardware question concrete: a model requires 30 GB of memory to do inference, and the available chip has 24 GB of memory. Will the chip be sufficient?

  1. 1
    Identify the requirement

    The model needs 30 GB of memory to do inference.

  2. 2
    Identify the available memory

    The chip provides 24 GB of memory.

  3. 3
    Compare the two

    24 GB is less than 30 GB, so the memory available is smaller than the memory the model requires.

  4. 4
    Draw the conclusion

    The chip will not be sufficient for this model at inference time.

Result

A 24 GB chip will not be sufficient for a model that requires 30 GB to do inference.

This example is about inference, where only the forward pass runs. Finetuning adds the backward pass and the per-trainable-parameter storage described earlier, so the same kind of memory check becomes more involved when training is on the table.

Mistakes Beginners Make with Trainable Parameters

  • Common mistake

    Assuming every parameter changes during finetuning

    What it looks like

    Believing that finetuning always updates the whole model.

    Why it fails

    The source says that during finetuning some or all model parameters may be updated. Frozen parameters are kept unchanged.

    Do this instead

    Check which parameters are trainable and which are frozen before estimating what training will change.

  • Common mistake

    Thinking a frozen parameter is removed from the model

    What it looks like

    Reasoning that freezing a parameter means it no longer takes part in the model.

    Why it fails

    Freezing only means the parameter is not updated. It is still part of the model.

    Do this instead

    Treat frozen as unchanged during training, not as absent.

  • Common mistake

    Believing training and inference need the same memory

    What it looks like

    Using an inference memory estimate as the training memory estimate.

    Why it fails

    Inference executes only the forward pass, while training executes both passes, and the backward pass adds per-trainable-parameter storage.

    Do this instead

    Estimate training memory separately, paying attention to the number of trainable parameters.

  • Common mistake

    Treating the backward pass as a simple reversal of the forward pass

    What it looks like

    Assuming the backward pass just retraces the forward computation step by step.

    Why it fails

    The backward pass updates the weights using aggregated signals from the forward pass, after computing the loss and a gradient per trainable parameter.

    Do this instead

    Describe the backward pass as loss, then gradients, then optimizer-driven adjustment.

Practice: Predicting Memory Pressure

MEDIUM

Two finetuning setups use the same model. In setup A, most parameters are trainable. In setup B, most parameters are frozen and only a small group is trainable. Which setup carries more gradient and optimizer state storage during training, and why? Explain your answer in terms of the trainable and frozen definitions.

Hints
  • Look at which parameters get a gradient and optimizer states during the backward pass.
  • Frozen parameters are kept unchanged, so they do not receive this extra treatment.
EASY

Name the three stages of the backward pass in order, and state in one sentence what each stage produces for the next one.

Hints
  • The first stage produces the loss.
  • The last stage uses the optimizer to adjust trainable parameters.

Key Takeaways

  • A trainable parameter can be updated during finetuning, while a frozen parameter is kept unchanged. Frozen parameters remain part of the model.
  • Backpropagation has two phases: the forward pass computes the output from the input, and the backward pass updates the weights using aggregated signals from the forward pass.
  • The backward pass computes the loss, then a gradient for each trainable parameter, then uses the optimizer to decide how to adjust each one.
  • Each trainable parameter comes with a gradient and optimizer states, so more trainable parameters means more memory is needed during finetuning.

Related concepts

More concepts starting with O