Example of code in PyTorch.
class Network(torch.nn.Module):
def __init__(self, hidden):
super().__init__()
self.layer1 = torch.nn.Linear(2, hidden)
self.layer2 = torch.nn.Linear(hidden, hidden)
self.layer3 = torch.nn.Linear(hidden, 1)
def forward(self, x):
h = self.layer1.forward(x).relu()
h = self.layer2.forward(h).relu()
return self.layer3.forward(h).sigmoid()
Let's build PyTorch.
How are you going to build PyTorch?
class ReLU:
@staticmethod
def forward(ctx, a):
# TODO: Implement for Task 1.2.
raise NotImplementedError('Need to implement for Task 1.2')
@staticmethod
def backward(ctx, d_output):
# TODO: Implement for Task 1.4.
raise NotImplementedError('Need to implement for Task 1.4')