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

bookChallenge: Implement Custom Optimizer Step

Compito

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.

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 4
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

close

bookChallenge: Implement Custom Optimizer Step

Scorri per mostrare il menu

Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 4
single

single

some-alt