Sectionย 2. Chapterย 4
single
Challenge: Implement Custom Optimizer Step
Swipe to show menu
Task
Swipe to start coding
You will implement a custom optimizer step (manual SGD update) using PyTorch autograd.
You are given a learnable weight w and a small dataset. The code already computes predictions and loss.
Your goal is to manually perform one gradient descent step without using torch.optim.
Complete the missing parts:
- Compute gradients of
losswith respect tow. - Update
wusing SGD: wโwโlrโ โwโloss - Reset the gradient stored in
w.gradto avoid accumulation.
After the update, the code prints the updated weight and the loss value.
Solution
Everything was clear?
Thanks for your feedback!
Sectionย 2. Chapterย 4
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat