Hi, I’ve gone through the PyTorch tutorials, and looked at a couple examples, and I’m still having trouble getting started – I’m just trying to make a basic MLP for now.   What I have below is my (existing) Keras version, and then an attempt at a PyTorch version, cobbled together from trying to read the docs and posts on this forum…still not finished because I’m not sure I’m doing this right.
Can someone tell me if I’m on the right track?
This MLP is intended to take, as input, a vector that’s 3 elements long (X.shape[1]=3) go through two hidden layers with n_hidden neurons each, with different activations, and then output a single number.  (It is a regression problem.)
def make_model(X, n_hidden, weights_file="weights.hdf5"):

    if ('keras' == library): 
            model = Sequential()
            model.add(Dense(n_hidden, input_shape=(X.shape[1],), activation='relu', init='he_uniform'))
            model.add(Dense(n_hidden,activation='tanh'))
            model.add(Dense(1))
            model.compile(loss='mse', optimizer='adam', lr=0.001) 
    elif ('pytorch' == library):
        class Net(nn.Module):
            def __init__(self):
                super(Net, self).__init__()
                self.hidden = nn.Linear(n_hidden, X.shape[1])
                self.hidden2 = nn.Linear(n_hidden, X.shape[1])
                self.out   = nn.Linear(1)

            def forward(self, x):
                x = F.relu(self.hidden(x))
                x = F.tanh(self.hidden2(x))
                x = self.out(x)
            return x

        model = Net()
    else:
        raise ValueError('Invalid library selection')
    return model

…And then for training,
   if ('keras' == library):
        model.fit(X_train, Y_train, nb_epoch=1, batch_size=batch_size, verbose=1, validation_data=(X_test, Y_test), 
            callbacks =[ProgbarLogger(),ModelCheckpoint(filepath=weights_file, verbose=1, save_best_only=True)])
    elif ('pytorch' == library):
        input = Variable(X_train, requires_grad=True)
        result = model(input)
        result.backward(torch.randn(result.size()))

…I don’t see where I actually feed my “Y_train” (target, true) data to PyTorch, with which to compute a loss function.
And then for predicting…
        if ('keras' == library):
            Y_pred = model.predict(X_test)
        elif ('pytorch' == library):
            input = Variable(X_train, requires_grad=True)
            Y_pred = model(input).numpy
       # after which I plot Y_pred along with Y_test using matplotlib

?