Performance Optimization in Python
Keep the target visible throughout the process: the parameters are being adjusted because their values determine the cost function, and optimization seeks parameter values associated with a lower cost.
Optimization as a Search
In this chapter, performance optimization has a specific meaning: finding the parameters θ of a neural network that significantly reduce its cost function J(θ). The aim is not simply to make a program run faster. It is to search through possible parameter values for settings that produce a smaller measure of cost.
Performance optimization in this context is the process of finding neural-network parameters θ that significantly reduce J(θ), where J(θ) typically combines a performance measure evaluated on the entire training set with additional regularization terms.
Keep the target visible throughout the process: the parameters are being adjusted because their values determine the cost function, and optimization seeks parameter values associated with a lower cost.
Tracking Parameter Changes
Optimization can be understood as a sequence of parameter states. At one step, the network has a current set of parameters. A later step produces another set. The search is successful when these changes move the network toward parameter values that significantly reduce J(θ). The source describes standard gradient descent as sequential: the gradient at step t is a function of the parameters produced by step t−1.
What Makes Up the Cost
The cost function J(θ) typically combines more than one concern. One component is a performance measure evaluated across the entire training set. Additional regularization terms are also included. Therefore, reducing J(θ) means optimizing the combined objective rather than considering only the training-set performance measure in isolation.
Reading an Optimization Objective
Suppose an optimization discussion refers to a cost function J(θ) that includes a training-set performance measure and additional regularization terms. What should you understand the optimizer to be reducing?
- 1Identify the parameter object
θ represents the neural-network parameters whose values are being searched for.
- 2Identify the combined objective
J(θ) is not described as only the training-set performance measure. It typically includes that measure together with regularization terms.
- 3Interpret the goal
The optimization process seeks parameter values that significantly reduce the combined cost J(θ).
The target is a lower value of the combined cost function, not merely an isolated training-set performance term.
When evaluating an optimization method, ask what objective it is actually minimizing. In this topic, the objective is J(θ), a cost that typically contains both a whole-training-set performance measure and regularization terms.
Sequential and Parallel Progress
Optimization performance is also affected by how computation is organized. During training, data parallelism is somewhat harder than simply enlarging the minibatch used for one stochastic gradient descent step. Increasing the minibatch size usually gives less than linear returns in optimization performance.
A more attractive possibility would be to let multiple machines compute multiple gradient-descent steps in parallel. However, standard gradient descent is defined as a completely sequential algorithm: the gradient at step t depends on the parameters produced by step t−1. That dependency makes unrestricted parallel computation of successive steps difficult.
| Approach | What the source says | Optimization implication |
|---|---|---|
| Increase minibatch size | Usually produces less than linear returns in optimization performance | A larger minibatch is not a guarantee of proportionally better optimization |
| Compute successive gradient-descent steps in parallel | Would be desirable, but standard gradient descent is completely sequential | The dependency between consecutive parameter states makes this difficult |
Two ways of thinking about increasing training computation
Common Reasoning Mistakes
Common mistake Treating performance optimization as only a matter of making Python code execute faster.
What it looks likeDescribing the topic without mentioning neural-network parameters θ or the cost function J(θ).
Why it failsThe source defines this chapter's particular optimization case as finding neural-network parameters that reduce J(θ).
Do this insteadFrame the discussion around searching for parameter values that significantly reduce the neural-network cost.
Common mistake Assuming that J(θ) measures only performance on the training set.
What it looks likeIgnoring regularization terms when explaining the objective.
Why it failsThe cost function typically includes the training-set performance measure as well as additional regularization terms.
Do this insteadDescribe J(θ) as a combined objective containing both parts.
Common mistake Assuming that every optimization step must reduce the cost.
What it looks likeInterpreting the sequence of parameter states as proof that each individual step has a smaller J(θ).
Why it failsThe source describes the search goal and the sequential dependency, but does not state that every step is guaranteed to reduce the cost.
Do this insteadSay that the process seeks parameter values that significantly reduce the cost, while preserving the stated step-to-step dependency.
Common mistake Assuming that doubling a minibatch produces a proportional optimization improvement.
What it looks likePredicting linear optimization returns solely because more examples are included in one stochastic gradient descent step.
Why it failsThe source says that larger minibatches usually produce less than linear returns in optimization performance.
Do this insteadTreat minibatch enlargement as a change whose optimization benefit may be less than linear.
Practice Check
Explain, in your own words, why standard gradient descent makes parallel computation of successive steps difficult. Your answer should mention the relationship between the gradient at step t and the parameters produced at step t−1.
Hints
- Start with the fact that standard gradient descent is sequential.
- Identify which earlier parameter state the current gradient depends on.
- Connect that dependency to the difficulty of computing multiple successive steps independently.
A Complete Explanation
Give a concise but complete explanation of what is being optimized and why the sequence of steps matters.
- 1State the target
The target is to find neural-network parameters θ that significantly reduce J(θ).
- 2Describe the objective
J(θ) typically combines a performance measure evaluated on the entire training set with additional regularization terms.
- 3Describe the sequence
In standard gradient descent, the gradient at step t depends on the parameters produced at step t−1.
- 4Explain the practical consequence
Because successive steps depend on earlier parameter states, computing multiple successive gradient-descent steps in parallel is difficult.
Performance optimization is a sequential search for parameter values that reduce a combined neural-network cost function.
Key Takeaways
- 1In this chapter, performance optimization means finding neural-network parameters θ that significantly reduce J(θ).
- 2The cost function typically combines a performance measure evaluated on the entire training set with additional regularization terms.
- 3Standard gradient descent is sequential because the gradient at step t depends on parameters produced at step t−1.
- 4Increasing minibatch size usually gives less than linear returns in optimization performance.
- 5Theoretical limits exist for optimization algorithms, although the source notes that these limits typically have little bearing on practical neural-network use.
At a glance
- Performance optimization here is a search for neural-network parameters θ that reduce J(θ).
- J(θ) typically includes both whole-training-set performance and regularization terms.
- Gradient descent uses a sequential dependency from parameters at step t−1 to the gradient at step t.
- Larger minibatches usually do not provide linear returns in optimization performance.
- Optimization has theoretical limits, but those limits typically have little practical impact according to the source.