create the weights as self.weight = nn.Parameter(torch.randn(...)) and then use the torch.bmm function to do batch matrix multiplies.
This is probably a much better approach than doing a 10000-element for-loop in python.
Here’s an example of manually speficying nn.Parameter weights and using the functional interface, rather than using nn Modules.

  
      github.com
  
  
    szagoruyko/diracnets/blob/master/diracconv.py 30
import torch
from torch import nn
from torch.autograd import Variable
import torch.nn.functional as F
from torch.nn.init import dirac



def dirac_delta(ni, no, k):
    n = min(ni, no)
    size = (n, n) + k
    repeats = (max(no // ni, 1), max(ni // no, 1)) + (1,) * len(k)
    return dirac(torch.Tensor(*size)).repeat(*repeats)


def normalize(w):
    """Normalizes weight tensor over full filter."""
    return F.normalize(w.view(w.size(0), -1)).view_as(w)




  This file has been truncated. show original