There is no way to detect this automatically with nn.Linear at the moment.
If you use the functional interface: http://pytorch.org/docs/nn.html#torch.nn.functional.linear 26 then you can initialize the weights in the constructor to some size:
linear_weight = nn.Parameter(torch.randn(1, 1), requires_grad=True) # resize this in the forward function

And in the forward function:
# some stuff before, where x is the input to linear
if self.linear_weight.data.nelement() == 1:
   self.linear.weight.data.resize_(1, x.size(1)) # output_features x input_features)
   # initialize weights randomly
   self.linear.weight.data.normal_(-0.1, 0.1)
x = nn.functional.linear(x, self.linear_weight)