Skip to content

Instantly share code, notes, and snippets.

@wayofnumbers
Last active November 1, 2019 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayofnumbers/84488ea9760753efa57e406cfb186deb to your computer and use it in GitHub Desktop.
Save wayofnumbers/84488ea9760753efa57e406cfb186deb to your computer and use it in GitHub Desktop.
Iteration 1 of myLinear model
class myLinear(nn.Module):
def __init__(self, in_features, out_features, bias=True):
super().__init__()
self.in_features = in_features
self.out_features = out_features
self.bias = bias
self.weight = torch.nn.Parameter(torch.randn(out_features, in_features))
self.bias = torch.nn.Parameter(torch.randn(out_features))
def forward(self, input):
x, y = input.shape
if y != self.in_features:
sys.exit(f'Wrong Input Features. Please use tensor with {self.in_features} Input Features')
output = input @ self.weight.t() + self.bias
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment