Build the universal four-step pattern
The best way to internalize GradientTape is to build linear regression with no Keras — just raw TF and manual gradient descent. The four-step pattern you write here is the same pattern model.fit runs internally.
Linear regression: find W and b minimizing the mean squared error of y_pred = W*x + b.
The four steps inside every training loop, ever:
- Forward pass — compute predictions under the tape so TF records the ops.
- Loss — compute the scalar loss, also under the tape.
- Backward pass —
tape.gradient(loss, [W, b])applies chain rule automatically. - Update — subtract
learning_rate × gradientfrom each parameter viaassign_sub.