Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Implement Custom Optimizer Step | Optimization Algorithms in Practice
Optimization and Regularization in Neural Networks with Python

bookChallenge: Implement Custom Optimizer Step

Aufgabe

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:

  1. Compute gradients of loss with respect to w.
  2. Update w using SGD: wwlrwlossw \leftarrow w - lr \cdot \nabla_w loss
  3. Reset the gradient stored in w.grad to avoid accumulation.

After the update, the code prints the updated weight and the loss value.

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 4
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you explain this in simpler terms?

What are the main benefits or drawbacks?

Can you give me a real-world example?

close

bookChallenge: Implement Custom Optimizer Step

Swipe um das Menü anzuzeigen

Aufgabe

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:

  1. Compute gradients of loss with respect to w.
  2. Update w using SGD: wwlrwlossw \leftarrow w - lr \cdot \nabla_w loss
  3. Reset the gradient stored in w.grad to avoid accumulation.

After the update, the code prints the updated weight and the loss value.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 4
single

single

some-alt