0ad33d606682537466f3430fc6d6ac7d47460f1a,beginner_source/examples_tensor/two_layer_net_tensor.py,,,#,24

Before Change



// Create random input and output data
x = torch.randn(N, D_in).type(dtype)
y = torch.randn(N, D_out).type(dtype)

// Randomly initialize weights
w1 = torch.randn(D_in, H).type(dtype)
w2 = torch.randn(H, D_out).type(dtype)

After Change




dtype = torch.float
device = torch.device("cpu")
// dtype = torch.device("cuda:0") // Uncomment this to run on GPU

// N is batch size; D_in is input dimension;
// H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

// Create random input and output data
x = torch.randn(N, D_in, device=device, dtype=dtype)
y = torch.randn(N, D_out, device=device, dtype=dtype)

// Randomly initialize weights
w1 = torch.randn(D_in, H, device=device, dtype=dtype)
w2 = torch.randn(H, D_out, device=device, dtype=dtype)

learning_rate = 1e-6
for t in range(500):
    // Forward pass: compute predicted y
    h = x.mm(w1)
    h_relu = h.clamp(min=0)
    y_pred = h_relu.mm(w2)

    // Compute and print loss
    loss = (y_pred - y).pow(2).sum().item()
    print(t, loss)

    // Backprop to compute gradients of w1 and w2 with respect to loss
    grad_y_pred = 2.0 * (y_pred - y)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 6

Instances


Project Name: pytorch/tutorials
Commit Name: 0ad33d606682537466f3430fc6d6ac7d47460f1a
Time: 2018-04-24
Author: soumith@gmail.com
File Name: beginner_source/examples_tensor/two_layer_net_tensor.py
Class Name:
Method Name:


Project Name: pytorch/tutorials
Commit Name: 0ad33d606682537466f3430fc6d6ac7d47460f1a
Time: 2018-04-24
Author: soumith@gmail.com
File Name: beginner_source/examples_autograd/two_layer_net_autograd.py
Class Name:
Method Name:


Project Name: pytorch/tutorials
Commit Name: 0ad33d606682537466f3430fc6d6ac7d47460f1a
Time: 2018-04-24
Author: soumith@gmail.com
File Name: beginner_source/examples_autograd/two_layer_net_custom_function.py
Class Name:
Method Name: