Hi!
There are some issues with your first script:

you need to define linear1 and linear2 as nn.Parameter instead of Variable, if not model.parameters() won’t see them
just for information, nn.Linear implements it as torch.mm(input, weight.t() 59, as in torch7 BTW
you might want to divide the loss by the batch size, that’s what’s the default in pytorch

At a first sight, the second example looks fine to me. But note that you can do y.size(0) instead of y.size()[0]