3128e13109c8766eafb413f2428bba976701e929,beginner_source/transformer_tutorial.py,,,#,295

Before Change


    print("-" * 89)
    print("| end of epoch {:3d} | time: {:5.2f}s | valid loss {:5.2f} | "
          "valid ppl {:8.2f}".format(epoch, (time.time() - epoch_start_time),
                                     val_loss, math.exp(val_loss)))
    print("-" * 89)

    if val_loss < best_val_loss:

After Change


nlayers = 2 // the number of nn.TransformerEncoderLayer in nn.TransformerEncoder
nhead = 2 // the number of heads in the multiheadattention models
dropout = 0.2 // the dropout value
model = TransformerModel(ntokens, emsize, nhead, nhid, nlayers, dropout).to(device)


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Run the model
// -------------
//


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// `CrossEntropyLoss <https://pytorch.org/docs/master/nn.html?highlight=crossentropyloss//torch.nn.CrossEntropyLoss>`__
// is applied to track the loss and
// `SGD <https://pytorch.org/docs/master/optim.html?highlight=sgd//torch.optim.SGD>`__
// implements stochastic gradient descent method as the optimizer. The initial
// learning rate is set to 5.0. `StepLR <https://pytorch.org/docs/master/optim.html?highlight=steplr//torch.optim.lr_scheduler.StepLR>`__ is
// applied to adjust the learn rate through epochs. During the
// training, we use
// `nn.utils.clip_grad_norm\_ <https://pytorch.org/docs/master/nn.html?highlight=nn%20utils%20clip_grad_norm//torch.nn.utils.clip_grad_norm_>`__
// function to scale all the gradient together to prevent exploding.
//

criterion = nn.CrossEntropyLoss()
lr = 5.0 // learning rate
optimizer = torch.optim.SGD(model.parameters(), lr=lr)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, 1.0, gamma=0.95)

import time
def train():
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: pytorch/tutorials
Commit Name: 3128e13109c8766eafb413f2428bba976701e929
Time: 2020-12-02
Author: 6156351+zhangguanheng66@users.noreply.github.com
File Name: beginner_source/transformer_tutorial.py
Class Name:
Method Name:


Project Name: Scitator/catalyst
Commit Name: 43df540b512c616a882df1f35c8862fa332b9317
Time: 2019-01-20
Author: grinchuk.alexey@gmail.com
File Name: rl/agents/actor.py
Class Name: GaussActor
Method Name: forward


Project Name: rusty1s/pytorch_geometric
Commit Name: 075a7a98d0dd84aeee8eca0e199697d0f4729f3c
Time: 2019-11-22
Author: klicpera@in.tum.de
File Name: torch_geometric/transforms/gdc.py
Class Name: GDC
Method Name: _expm