Skip to content

Instantly share code, notes, and snippets.

@lanpa
Last active February 15, 2018 03:45
Show Gist options
  • Save lanpa/53ff053d1c76129fbdd54655efeee548 to your computer and use it in GitHub Desktop.
Save lanpa/53ff053d1c76129fbdd54655efeee548 to your computer and use it in GitHub Desktop.
pytorch 0.3.1 trace
class Net1(nn.Module):
def __init__(self):
super(Net1, self).__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.conv2_drop = nn.Dropout2d()
self.fc1 = nn.Linear(320, 50)
self.fc2 = nn.Linear(50, 10)
self.bn = nn.BatchNorm2d(20)
def forward(self, x):
x = F.max_pool2d(self.conv1(x), 2)
x = F.relu(x) + F.relu(-x)
x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))
x = self.bn(x)
x = x.view(-1, 320)
x = F.relu(self.fc1(x))
x = F.dropout(x, training=self.training)
x = self.fc2(x)
x = F.softmax(x, dim=1)
return x
graph(%1 : Float(13, 1, 28, 28)
%2 : Float(10, 1, 5, 5)
%3 : Float(10)
%4 : Float(20, 10, 5, 5)
%5 : Float(20)
%6 : Float(50, 320)
%7 : Float(50)
%8 : Float(10, 50)
%9 : Float(10)
%10 : Float(20)
%11 : Float(20)
%12 : Float(20)
%13 : Float(20)) {
%15 : Float(13, 10, 24, 24), %16 : Handle = CppOp[ConvForward](%1, %2, %3), uses = [[%17.i0], []], scope: Net1/Conv2d[conv1];
%18 : Float(13, 10, 12, 12), %19 : Long(13, 10, 12, 12) = max_pool2d[kernel_size=[2, 2], stride=[], padding=[0, 0], dilation=[1, 1], ceil_mode=0](%15), uses = [[%20.i0, %21.i0], []], scope: Net1;
%20 : Float(13, 10, 12, 12) = threshold[threshold={0}, value={0}, inplace=0](%18), uses = [%23.i0], scope: Net1;
%21 : Float(13, 10, 12, 12) = neg(%18), uses = [%22.i0], scope: Net1;
%22 : Float(13, 10, 12, 12) = threshold[threshold={0}, value={0}, inplace=0](%21), uses = [%23.i1], scope: Net1;
%23 : Float(13, 10, 12, 12) = add[alpha={1}](%20, %22), uses = [%24.i0], scope: Net1;
%25 : Float(13, 20, 8, 8), %26 : Handle = CppOp[ConvForward](%23, %4, %5), uses = [[%27.i0], []], scope: Net1/Conv2d[conv2];
%28 : Float(13, 20, 8, 8), %29 : Handle = ^FeatureDropout(0.5, False, False)(%25), uses = [[%30.i0], []], scope: Net1/Dropout2d[conv2_drop];
%31 : Float(13, 20, 4, 4), %32 : Long(13, 20, 4, 4) = max_pool2d[kernel_size=[2, 2], stride=[], padding=[0, 0], dilation=[1, 1], ceil_mode=0](%28), uses = [[%33.i0], []], scope: Net1;
%33 : Float(13, 20, 4, 4) = threshold[threshold={0}, value={0}, inplace=0](%31), uses = [%34.i0], scope: Net1;
%35 : Float(13, 20, 4, 4), %36 : Handle = CppOp[N5torch8autograd16BatchNormForwardE](%33, %10, %11), uses = [[%37.i0], []], scope: Net1/BatchNorm2d[bn];
%37 : Float(13, 320) = view[size=[-1, 320]](%35), uses = [%40.i1], scope: Net1;
%38 : Float(320!, 50!) = t(%6), uses = [%40.i2], scope: Net1/Linear[fc1];
%39 : Float(13!, 50) = expand[size=[13, 50]](%7), uses = [%40.i0], scope: Net1/Linear[fc1];
%40 : Float(13, 50) = addmm[beta={1}, alpha={1}](%39, %37, %38), uses = [%41.i0], scope: Net1/Linear[fc1];
%41 : Float(13, 50) = threshold[threshold={0}, value={0}, inplace=0](%40), uses = [%42.i0], scope: Net1;
%43 : Float(13, 50), %44 : Handle = ^Dropout(0.5, False, False)(%41), uses = [[%47.i1], []], scope: Net1;
%45 : Float(50!, 10!) = t(%8), uses = [%47.i2], scope: Net1/Linear[fc2];
%46 : Float(13!, 10) = expand[size=[13, 10]](%9), uses = [%47.i0], scope: Net1/Linear[fc2];
%47 : Float(13, 10) = addmm[beta={1}, alpha={1}](%46, %43, %45), uses = [%48.i0], scope: Net1/Linear[fc2];
%48 : Float(13, 10) = softmax[dim=1](%47), uses = [%0.i0], scope: Net1;
return (%48);
}
==after optimize==
graph(%1 : Float(13, 1, 28, 28)
%2 : Float(10, 1, 5, 5)
%3 : Float(10)
%4 : Float(20, 10, 5, 5)
%5 : Float(20)
%6 : Float(50, 320)
%7 : Float(50)
%8 : Float(10, 50)
%9 : Float(10)
%10 : Float(20)
%11 : Float(20)
%12 : Float(20)
%13 : Float(20)) {
%15 : UNKNOWN_TYPE = Conv[kernel_shape=[5, 5], strides=[1, 1], pads=[0, 0, 0, 0], dilations=[1, 1], group=1](%1, %2), uses = [[%16.i0]], scope: Net1/Conv2d[conv1];
%16 : Float(13, 10, 24, 24) = Add[broadcast=1, axis=1](%15, %3), uses = [%17.i0], scope: Net1/Conv2d[conv1];
%17 : Float(13, 10, 12, 12) = MaxPool[kernel_shape=[2, 2], pads=[0, 0], strides=[2, 2]](%16), uses = [%18.i0, %19.i0], scope: Net1;
%18 : Float(13, 10, 12, 12) = Relu(%17), uses = [%21.i0], scope: Net1;
%19 : Float(13, 10, 12, 12) = Neg(%17), uses = [%20.i0], scope: Net1;
%20 : Float(13, 10, 12, 12) = Relu(%19), uses = [%21.i1], scope: Net1;
%21 : Float(13, 10, 12, 12) = Add(%18, %20), uses = [%22.i0], scope: Net1;
%23 : UNKNOWN_TYPE = Conv[kernel_shape=[5, 5], strides=[1, 1], pads=[0, 0, 0, 0], dilations=[1, 1], group=1](%21, %4), uses = [[%24.i0]], scope: Net1/Conv2d[conv2];
%24 : Float(13, 20, 8, 8) = Add[broadcast=1, axis=1](%23, %5), uses = [%25.i0], scope: Net1/Conv2d[conv2];
%25 : Float(13, 20, 4, 4) = MaxPool[kernel_shape=[2, 2], pads=[0, 0], strides=[2, 2]](%24), uses = [%26.i0], scope: Net1;
%26 : Float(13, 20, 4, 4) = Relu(%25), uses = [%27.i0], scope: Net1;
%28 : Float(13, 20, 4, 4) = BatchNormalization[is_test=1, epsilon=1e-05, momentum=0.9, consumed_inputs=[0, 0, 0, 1, 1]](%26, %10, %11, %12, %13), uses = [[%29.i0]], scope: Net1/BatchNorm2d[bn];
%29 : Float(13, 320) = Reshape[shape=[-1, 320]](%28), uses = [%32.i0], scope: Net1;
%32 : Float(13, 50) = Gemm[alpha=1, beta=1, broadcast=1, transB=1](%29, %6, %7), uses = [%33.i0], scope: Net1/Linear[fc1];
%33 : Float(13, 50) = Relu(%32), uses = [%34.i0], scope: Net1;
%35 : Float(13, 50), %36 : UNKNOWN_TYPE = Dropout[is_test=1, ratio=0.5](%33), uses = [[%39.i0], []], scope: Net1;
%39 : Float(13, 10) = Gemm[alpha=1, beta=1, broadcast=1, transB=1](%35, %8, %9), uses = [%40.i0], scope: Net1/Linear[fc2];
%40 : Float(13, 10) = Softmax[axis=1](%39), uses = [%0.i0], scope: Net1;
return (%40);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment