Pytorch ValueError optimizer got an empty parameter list
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
ValueError: optimizer got an empty parameter list means PyTorch did not find any trainable parameters in the object you passed to the optimizer. The optimizer is not broken; it is telling you that your model is not exposing parameters the way PyTorch expects.
Why PyTorch thinks there are no parameters
Optimizers usually receive model.parameters(). That iterator contains parameters registered on nn.Module objects, such as nn.Linear, nn.Conv2d, and explicit nn.Parameter fields. If your layers are not registered, the iterator is empty and the optimizer raises the error.
One of the most common mistakes is storing layers in a plain Python list instead of nn.ModuleList.
The layers exist, but PyTorch does not know they are part of the module because a plain list does not register them.
Register modules the PyTorch way
Use nn.ModuleList, nn.Sequential, or named module attributes so PyTorch can discover the parameters.
Now the optimizer can see the trainable weights because the modules are properly registered.
Other common causes
Another frequent mistake is forgetting super().__init__() in a custom module. Without it, the internal machinery that tracks submodules and parameters is not set up correctly.
It can also happen if you accidentally exhaust the parameter iterator before passing it to the optimizer. For example, converting model.parameters() to a list for debugging is fine, but storing the original iterator and reusing it later can lead to surprises.
Finally, some models genuinely have no trainable parameters. A module made only of activation functions, reshapes, or fixed operations will produce an empty parameter list by design. In that case, you do not need an optimizer for that object.
Another easy trap is storing trainable tensors as plain attributes instead of nn.Parameter. A raw tensor on the module is just data unless you wrap it so PyTorch knows it should participate in optimization.
A quick debugging checklist
When this error appears, inspect list(model.named_parameters()). If the list is empty, the problem is almost always module registration. If the list contains parameters but the optimizer still complains, check what object you actually passed to the optimizer and whether you accidentally consumed the iterator earlier.
This check is faster than guessing. It immediately tells you whether the model structure or the optimizer call site is the real issue.
Common Pitfalls
- Storing layers in a plain Python list or dict instead of
ModuleList,ModuleDict, or named attributes. - Forgetting to call
super().__init__()in a customnn.Module. - Passing the wrong object to the optimizer, such as a wrapper that has no parameters of its own.
- Consuming a parameter iterator during debugging and then reusing it.
- Assuming every module needs an optimizer even when it has no trainable weights.
Summary
- The error means the optimizer received no registered trainable parameters.
- PyTorch only tracks parameters that belong to properly registered
nn.Moduleornn.Parameterfields. - '
ModuleList,Sequential, and named attributes are the usual fixes for unregistered layers.' - Check
list(model.named_parameters())before debugging anything more complicated. - If the model truly has no trainable weights, an optimizer is unnecessary.

