[Python] Steps for Machine Learning in Pytorch

Discussão em 'Python' iniciado por Stack, Junho 23, 2025.

  1. Stack

    Stack Membro Participativo

    When we define our model in PyTorch. We run through different #epochs. I want to know that in the iteration of epochs. What is the difference between the two following snippets of code in which the order is different? These two snippet versions are:

    1. I found over tutorials
    2. The code provided by my supervisor for the project.

    Tutorial Version

    for i in range(epochs):
    logits = model(x)
    loss = loss_fcn(logits,lables)
    loss.backward()
    optimizer.step()
    optimizer.zero_grad()


    Supervisor Version

    for i in range(epochs):
    logits = model(x)
    loss = loss_fcn(logits,lables)
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

    Continue reading...

Compartilhe esta Página