Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Apply torch functions to weight parameters
import torch
import torch.nn as nn
from torch.autograd import Variable
affine = nn.Linear(10, 10)
# A linear mapping to a random vector... just for quick demo purposes
x = Variable(torch.randn(100, 10))
y = Variable(torch.randn(100, 10))
weird_loss = torch.mean(torch.exp(affine.weight))
mse_loss = nn.MSELoss()
pred_loss = mse_loss(affine(x), y)
net_loss = pred_loss + weird_loss
# should work just fine!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.