Assuming you don’t want double precision this should work on PyTorch 0.4:
import torch
import torch.nn as nn
from torch.autograd import Variable
import pandas as pd
import numpy as np
class Linear_Regress(nn.Module):
    def __init__(self, input_sz, output_sz):
        super(Linear_Regress, self).__init__()
        self.linear = nn.Linear(input_sz, output_sz)

    def forward(self, x):
        out = self.linear(x)
        return out

model = Linear_Regress(1,1)

criterion = nn.MSELoss()
lrn_rt = 0.01
optm = torch.optim.SGD(model.parameters(), lr = lrn_rt)

# using numpy to generate random input and output
train_x = np.random.rand((1))
train_y = np.random.rand((1))

# the trick is to cast input and label manually to float as torch.from_numpy() for some reasons returns them as DoubleTensors
inputs = torch.from_numpy(train_x).to(torch.float)
outs = torch.from_numpy(train_y).to(torch.float)
epochs = 100
model(inputs)
for e in range(epochs):
    e += 1
    optm.zero_grad()

    outputs = model.forward(inputs)
    loss = criterion(outputs, outs)
    loss.backward()
    optm.step()
    print('epoch {}, loss {}'.format(e, loss.data[0]))