You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2019/10/02 02:51:51 UTC

[incubator-singa] branch master updated: SINGA-491 Python Code Cleaning

This is an automated email from the ASF dual-hosted git repository.

wangwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-singa.git


The following commit(s) were added to refs/heads/master by this push:
     new 810f0a8  SINGA-491 Python Code Cleaning
     new 7172b5b  Merge pull request #539 from chrishkchris/SINGA-491_2
810f0a8 is described below

commit 810f0a8873e1a245aa6b7ef05a7873e4926a58dc
Author: chrishkchris <ch...@yahoo.com.hk>
AuthorDate: Mon Sep 30 09:04:13 2019 +0000

    SINGA-491 Python Code Cleaning
---
 examples/autograd/resnet.py                 |  11 +--
 examples/autograd/xceptionnet.py            |   6 +-
 examples/cifar10/train.py                   |   1 -
 examples/imagenet/densenet/model.py         |   2 -
 examples/imagenet/densenet/serve.py         |   9 ++-
 examples/imagenet/googlenet/serve.py        |  22 +++---
 examples/imagenet/inception/README.md       |   2 +-
 examples/imagenet/inception/inception_v3.py | 118 +++++++++++++---------------
 examples/imagenet/inception/inception_v4.py |  44 +++++------
 examples/imagenet/inception/serve.py        |   8 +-
 examples/imagenet/resnet/serve.py           |   9 ++-
 examples/imagenet/vgg/serve.py              |   9 ++-
 python/singa/autograd.py                    |  21 ++---
 python/singa/sonnx.py                       |   2 +-
 tool/opencl/clsrc_to_str.py                 |   2 +-
 15 files changed, 128 insertions(+), 138 deletions(-)

diff --git a/examples/autograd/resnet.py b/examples/autograd/resnet.py
index da58a89..1755212 100755
--- a/examples/autograd/resnet.py
+++ b/examples/autograd/resnet.py
@@ -115,6 +115,9 @@ class Bottleneck(autograd.Layer):
         return out
 
 
+__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152']
+
+
 class ResNet(autograd.Layer):
     def __init__(self, block, layers, num_classes=1000):
         self.inplanes = 64
@@ -231,14 +234,6 @@ def resnet152(pretrained=False, **kwargs):
 
     return model
 
-__all__ = [
-    'ResNet',
-    'resnet18',
-    'resnet34',
-    'resnet50',
-    'resnet101',
-    'resnet152',
-]
 
 if __name__ == "__main__":
     model = resnet50()
diff --git a/examples/autograd/xceptionnet.py b/examples/autograd/xceptionnet.py
index 4bd31ce..933921b 100755
--- a/examples/autograd/xceptionnet.py
+++ b/examples/autograd/xceptionnet.py
@@ -85,6 +85,9 @@ class Block(autograd.Layer):
         return y
 
 
+__all__ = ['Xception']
+
+
 class Xception(autograd.Layer):
     """
     Xception optimized for the ImageNet dataset, as specified in
@@ -186,7 +189,6 @@ class Xception(autograd.Layer):
         x = self.logits(x)
         return x
 
-__all__ = ['xception']
 
 if __name__ == '__main__':
     model = Xception(num_classes=1000)
@@ -212,6 +214,4 @@ if __name__ == '__main__':
             x = model(tx)
             loss = autograd.softmax_cross_entropy(x, ty)
             for p, g in autograd.backward(loss):
-                # print(p.shape, g.shape)
                 sgd.update(p, g)
-                # pass
diff --git a/examples/cifar10/train.py b/examples/cifar10/train.py
index 7657026..ecf36da 100644
--- a/examples/cifar10/train.py
+++ b/examples/cifar10/train.py
@@ -32,7 +32,6 @@ import os
 import argparse
 from tqdm import trange
 
-from singa import utils
 from singa import optimizer
 from singa import device
 from singa import tensor
diff --git a/examples/imagenet/densenet/model.py b/examples/imagenet/densenet/model.py
index 6ffaf00..14912a8 100644
--- a/examples/imagenet/densenet/model.py
+++ b/examples/imagenet/densenet/model.py
@@ -21,8 +21,6 @@ https://github.com/pytorch/vision/blob/master/torchvision/models/densenet.py
 from singa import initializer
 from singa import layer
 from singa import net as ffnet
-from singa import loss
-from singa import metric
 from singa.layer import Conv2D, Activation, MaxPooling2D,\
     AvgPooling2D, Split, Concat, Flatten, BatchNormalization
 
diff --git a/examples/imagenet/densenet/serve.py b/examples/imagenet/densenet/serve.py
index 2e401b9..2668066 100644
--- a/examples/imagenet/densenet/serve.py
+++ b/examples/imagenet/densenet/serve.py
@@ -75,9 +75,12 @@ def serve(net, label_map, dev, agent, topk=5):
                 for i in range(topk):
                     response += "%s:%f <br/>" % (label_map[idx[i]],
                                                  prob[idx[i]])
-            except:
+            except Exception:
                 traceback.print_exc()
-                response = "sorry, system error during prediction."
+                response = "Sorry, system error during prediction."
+            except SystemExit:
+                traceback.print_exc()
+                response = "Sorry, error triggered sys.exit() during prediction."
             agent.push(MsgType.kResponse, response)
         elif msg.is_command():
             if MsgType.kCommandStop.equal(msg):
@@ -134,7 +137,7 @@ def main():
 
     except SystemExit:
         return
-    except:
+    except Exception:
         traceback.print_exc()
         sys.stderr.write("  for help use --help \n\n")
         return 2
diff --git a/examples/imagenet/googlenet/serve.py b/examples/imagenet/googlenet/serve.py
index b3e6a90..b0a609a 100644
--- a/examples/imagenet/googlenet/serve.py
+++ b/examples/imagenet/googlenet/serve.py
@@ -116,10 +116,10 @@ def create_net(shape, weight_path='bvlc_googlenet.pickle'):
     net = ffnet.FeedForwardNet()
     net.add(Conv2D('conv1/7x7_s2', 64, 7, 2, pad=3, input_sample_shape=shape))
     c1 = net.add(Activation('conv1/relu_7x7'))
-    pool1 = pool(net, c1, 'pool1/3x3_s2', 3, 2)
+    pool(net, c1, 'pool1/3x3_s2', 3, 2)
     norm1 = net.add(LRN('pool1/norm1', 5, 0.0001, 0.75))
     c3x3r = conv(net, norm1 , 'conv2', 64, 1, suffix='3x3_reduce')
-    c3x3 = conv(net, c3x3r, 'conv2', 192, 3, pad=1, suffix='3x3')
+    conv(net, c3x3r, 'conv2', 192, 3, pad=1, suffix='3x3')
     norm2 = net.add(LRN('conv2/norm2', 5, 0.0001, 0.75))
     pool2 = pool(net, norm2, 'pool2/3x3_s2', 3, 2)
 
@@ -133,11 +133,11 @@ def create_net(shape, weight_path='bvlc_googlenet.pickle'):
     i4e=inception(net, i4d, 'inception_4e', 256, 160, 320, 32, 128, 128)
     pool4=pool(net, i4e,'pool4/3x3_s2', 3, 2)
     i5a=inception(net, pool4, 'inception_5a', 256, 160, 320, 32, 128, 128)
-    i5b=inception(net, i5a, 'inception_5b', 384, 192, 384, 48, 128, 128)
-    pool5=net.add(AvgPooling2D('pool5/7x7_s1', 7, 1, pad=0))
-    drop5=net.add(Dropout('drop', 0.4))
-    flat=net.add(Flatten('flat'))
-    dense=net.add(Dense('loss3/classifier', 1000))
+    inception(net, i5a, 'inception_5b', 384, 192, 384, 48, 128, 128)
+    net.add(AvgPooling2D('pool5/7x7_s1', 7, 1, pad=0))
+    net.add(Dropout('drop', 0.4))
+    net.add(Flatten('flat'))
+    net.add(Dense('loss3/classifier', 1000))
     # prob=net.add(Softmax('softmax'))
 
     net.load(weight_path, use_pickle=True)
@@ -161,7 +161,6 @@ def serve(agent, use_cpu, parameter_file, topk=5):
     else:
         print("runing with gpu")
         dev = device.create_cuda_gpu()
-    agent = agent
 
     print('Start intialization............')
     net = create_net((3, 224, 224), parameter_file)
@@ -197,9 +196,12 @@ def serve(agent, use_cpu, parameter_file, topk=5):
                 idx = np.argsort(-prob)[0:topk]
                 for i in idx:
                     response += "%s:%s<br/>" % (labels[i], prob[i])
-            except:
+            except Exception:
                 traceback.print_exc()
                 response = "Sorry, system error during prediction."
+            except SystemExit:
+                traceback.print_exc()
+                response = "Sorry, error triggered sys.exit() during prediction."
             agent.push(MsgType.kResponse, response)
         elif MsgType.kCommandStop.equal(msg_type):
                 print('get stop command')
@@ -233,7 +235,7 @@ def main():
 
     except SystemExit:
         return
-    except:
+    except Exception:
         traceback.print_exc()
         sys.stderr.write("  for help use --help \n\n")
         return 2
diff --git a/examples/imagenet/inception/README.md b/examples/imagenet/inception/README.md
index 54aaaa1..1c564a4 100644
--- a/examples/imagenet/inception/README.md
+++ b/examples/imagenet/inception/README.md
@@ -25,7 +25,7 @@ In this example, we convert Inception V4 trained on Tensorflow to SINGA for imag
 
 * Download the parameter checkpoint file
 
-        $ wget
+        $ wget https://s3-ap-southeast-1.amazonaws.com/dlfile/inception_v4.tar.gz
         $ tar xvf inception_v4.tar.gz
 
 * Download [synset_word.txt](https://github.com/BVLC/caffe/blob/master/data/ilsvrc12/get_ilsvrc_aux.sh) file.
diff --git a/examples/imagenet/inception/inception_v3.py b/examples/imagenet/inception/inception_v3.py
index 421343b..58b01c6 100644
--- a/examples/imagenet/inception/inception_v3.py
+++ b/examples/imagenet/inception/inception_v3.py
@@ -101,10 +101,10 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     blk = V3 + '/Mixed_5b'
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(48), 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(48), 1, src=s)
     br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_5x5' % blk, depth(64), 5)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(96), 3)
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(96), 3)
     br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_3x3' % blk, depth(96), 3)
     net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(32), 1)
@@ -117,12 +117,12 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     blk = V3 + '/Mixed_5c'
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x1' % blk, depth(48), 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x1' % blk, depth(48), 1, src=s)
     br1 = conv2d(net, '%s/Branch_1/Conv_1_0c_5x5' % blk, depth(64), 5)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(96), 3)
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(96), 3)
     br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_3x3' % blk, depth(96), 3)
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), src=s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), src=s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(64), 1)
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1),
                               [br0, br1, br2, br3])
@@ -133,12 +133,12 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     blk = V3 + '/Mixed_5d'
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(48), 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(48), 1, src=s)
     br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_5x5' % blk, depth(64), 5)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(96), 3)
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(96), 3)
     br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_3x3' % blk, depth(96), 3)
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk,  3, 1), s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk,  3, 1), s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(64), 1)
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1),
                               [br0, br1, br2, br3])
@@ -150,8 +150,8 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     s = net.add(Split('%s/Split' % blk, 3))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_1a_1x1' % blk, depth(384), 3, 2,
                  border_mode='VALID', src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_3x3' % blk, depth(96), 3)
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(64), 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_3x3' % blk, depth(96), 3)
     br1 = conv2d(net, '%s/Branch_1/Conv2d_1a_1x1' % blk, depth(96), 3, 2,
                  border_mode='VALID')
     br2 = net.add(MaxPooling2D('%s/Branch_2/MaxPool_1a_3x3' % blk, 3, 2,
@@ -164,16 +164,15 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     blk = V3 + '/Mixed_6b'
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(192), 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(128), 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(128), [1, 7])
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(128), 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(128), [1, 7])
     br1 = conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, depth(192), [7, 1])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(128), [1, 1],
-                 src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, depth(128), [7, 1])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, depth(128), [1, 7])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, depth(128), [7, 1])
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(128), [1, 1], src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, depth(128), [7, 1])
+    conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, depth(128), [1, 7])
+    conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, depth(128), [7, 1])
     br2 = conv2d(net, '%s/Branch_2/Conv2d_0e_1x7' % blk, depth(192), [1, 7])
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(192), [1, 1])
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1),
                               [br0, br1, br2, br3])
@@ -185,17 +184,15 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(192), [1, 1],
                  src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(160), [1, 1],
-                 src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(160), [1, 7])
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(160), [1, 1], src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(160), [1, 7])
     br1 = conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, depth(192), [7, 1])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(160), [1, 1],
-                 src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, depth(160), [7, 1])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, depth(160), [1, 7])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, depth(160), [7, 1])
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(160), [1, 1], src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, depth(160), [7, 1])
+    conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, depth(160), [1, 7])
+    conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, depth(160), [7, 1])
     br2 = conv2d(net, '%s/Branch_2/Conv2d_0e_1x7' % blk, depth(192), [1, 7])
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(192), [1, 1])
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1),
                               [br0, br1, br2, br3])
@@ -207,17 +204,15 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(192), [1, 1],
                  src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(160), [1, 1],
-                 src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(160), [1, 7])
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(160), [1, 1], src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(160), [1, 7])
     br1 = conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, depth(192), [7, 1])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(160), [1, 1],
-                 src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, depth(160), [7, 1])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, depth(160), [1, 7])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, depth(160), [7, 1])
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(160), [1, 1], src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, depth(160), [7, 1])
+    conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, depth(160), [1, 7])
+    conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, depth(160), [7, 1])
     br2 = conv2d(net, '%s/Branch_2/Conv2d_0e_1x7' % blk, depth(192), [1, 7])
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(192), [1, 1])
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1),
                               [br0, br1, br2, br3])
@@ -228,17 +223,15 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(192), [1, 1],
                  src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(192), [1, 1],
-                 src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(192), [1, 7])
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(192), [1, 1], src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(192), [1, 7])
     br1 = conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, depth(192), [7, 1])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(192), [1, 1],
-                 src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, depth(192), [7, 1])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, depth(192), [1, 7])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, depth(192), [7, 1])
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(192), [1, 1], src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, depth(192), [7, 1])
+    conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, depth(192), [1, 7])
+    conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, depth(192), [7, 1])
     br2 = conv2d(net, '%s/Branch_2/Conv2d_0e_1x7' % blk, depth(192), [1, 7])
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(192), [1, 1])
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1),
                               [br0, br1, br2, br3])
@@ -248,14 +241,12 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     # mixed_8: 8 x 8 x 1280.
     blk = V3 + '/Mixed_7a'
     s = net.add(Split('%s/Split' % blk, 3))
-    br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(192), [1, 1],
-                 src=s)
+    conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(192), [1, 1], src=s)
     br0 = conv2d(net, '%s/Branch_0/Conv2d_1a_3x3' % blk, depth(320), [3, 3], 2,
                  border_mode='VALID')
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(192), [1, 1],
-                 src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(192), [1, 7])
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, depth(192), [7, 1])
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(192), [1, 1], src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, depth(192), [1, 7])
+    conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, depth(192), [7, 1])
     br1 = conv2d(net, '%s/Branch_1/Conv2d_1a_3x3' % blk, depth(192), [3, 3], 2,
                  border_mode='VALID')
     br2 = net.add(MaxPooling2D('%s/Branch_2/MaxPool_1a_3x3' % blk, 3, 2,
@@ -268,22 +259,22 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     blk = V3 + '/Mixed_7b'
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(320), 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(384), 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(384), 1, src=s)
     s1 = net.add(Split('%s/Branch_1/Split1' % blk, 2))
     br11 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x3' % blk, depth(384), [1, 3],
                   src=s1)
     br12 = conv2d(net, '%s/Branch_1/Conv2d_0b_3x1' % blk, depth(384), [3, 1],
                   src=s1)
     br1 = net.add(Concat('%s/Branch_1/Concat1' % blk, 1),  [br11, br12])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(448), 1, src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(384), 3)
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(448), 1, src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(384), 3)
     s2 = net.add(Split('%s/Branch_2/Split2' % blk, 2))
     br21 = conv2d(net, '%s/Branch_2/Conv2d_0c_1x3' % blk, depth(384), [1, 3],
                   src=s2)
     br22 = conv2d(net, '%s/Branch_2/Conv2d_0d_3x1' % blk, depth(384), [3, 1],
                   src=s2)
     br2 = net.add(Concat('%s/Branch_2/Concat2' % blk, 1),  [br21, br22])
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), src=s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), src=s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(192), [1, 1])
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1),
                               [br0, br1, br2, br3])
@@ -294,23 +285,23 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     blk = V3 + '/Mixed_7c'
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, depth(320), 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(384), 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, depth(384), 1, src=s)
     s1 = net.add(Split('%s/Branch_1/Split1' % blk, 2))
     br11 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x3' % blk, depth(384), [1, 3],
                   src=s1)
     br12 = conv2d(net, '%s/Branch_1/Conv2d_0c_3x1' % blk, depth(384), [3, 1],
                   src=s1)
     br1 = net.add(Concat('%s/Branch_1/Concat1' % blk, 1),  [br11, br12])
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(448), [1, 1],
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, depth(448), [1, 1],
                  src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(384), [3, 3])
+    conv2d(net, '%s/Branch_2/Conv2d_0b_3x3' % blk, depth(384), [3, 3])
     s2 = net.add(Split('%s/Branch_2/Split2' % blk, 2))
     br21 = conv2d(net, '%s/Branch_2/Conv2d_0c_1x3' % blk, depth(384), [1, 3],
                   src=s2)
     br22 = conv2d(net, '%s/Branch_2/Conv2d_0d_3x1' % blk, depth(384), [3, 1],
                   src=s2)
     br2 = net.add(Concat('%s/Branch_2/Concat2' % blk, 1),  [br21, br22])
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), src=s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), src=s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, depth(192), [1, 1])
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1),
                               [br0, br1, br2, br3])
@@ -319,7 +310,7 @@ def inception_v3_base(name, sample_shape, final_endpoint, aux_endpoint,
     return net, end_points
 
 
-def create_net(num_classes=1001, sample_shape=(3, 299, 299),
+def create_net(num_classes=1001, sample_shape=(3, 299, 299), is_training=True,
                final_endpoint='InceptionV3/Mixed_7c',
                aux_endpoint='InceptionV3/Mixed_6e',
                dropout_keep_prob=0.8):
@@ -327,6 +318,7 @@ def create_net(num_classes=1001, sample_shape=(3, 299, 299),
 
     Args:
         num_classes: number of predicted classes.
+        is_training: whether is training or not.
         dropout_keep_prob: float, the fraction to keep before final layer.
         final_endpoint: 'InceptionV3/Mixed_7d',
         aux_endpoint:
diff --git a/examples/imagenet/inception/inception_v4.py b/examples/imagenet/inception/inception_v4.py
index 9c5883f..feabde3 100644
--- a/examples/imagenet/inception/inception_v4.py
+++ b/examples/imagenet/inception/inception_v4.py
@@ -68,8 +68,8 @@ def block_reduction_a(blk, net):
     s = net.add(Split('%s/Split' % blk, 3))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_1a_3x3' % blk, 384, 3, 2,
                  border_mode='VALID', src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 192, 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_3x3' % blk, 224, 3)
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 192, 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_3x3' % blk, 224, 3)
     br1 = conv2d(net, '%s/Branch_1/Conv2d_1a_3x3' % blk, 256, 3, 2,
                  border_mode='VALID')
     br2 = net.add(MaxPooling2D('%s/Branch_2/MaxPool_1a_3x3' % blk, 3, 2,
@@ -82,15 +82,15 @@ def block_inception_b(blk, net):
     # By default use stride=1 and SAME padding
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, 384, 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 192, 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, 224, (1, 7))
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 192, 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, 224, (1, 7))
     br1 = conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, 256, (7, 1))
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, 192, 1, src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, 192, (7, 1))
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, 224, (1, 7))
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, 224, (7, 1))
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, 192, 1, src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_7x1' % blk, 192, (7, 1))
+    conv2d(net, '%s/Branch_2/Conv2d_0c_1x7' % blk, 224, (1, 7))
+    conv2d(net, '%s/Branch_2/Conv2d_0d_7x1' % blk, 224, (7, 1))
     br2 = conv2d(net, '%s/Branch_2/Conv2d_0e_1x7' % blk, 256, (1, 7))
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, 128, 1)
     return net.add(Concat('%s/Concat' % blk, 1), [br0, br1, br2, br3])
 
@@ -99,12 +99,12 @@ def block_reduction_b(blk, net):
     """Builds Reduction-B block for Inception v4 network."""
     # By default use stride=1 and SAME padding
     s = net.add(Split('%s/Split' % blk, 3))
-    br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, 192, 1, src=s)
+    conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, 192, 1, src=s)
     br0 = conv2d(net, '%s/Branch_0/Conv2d_1a_3x3' % blk, 192, 3, 2,
                  border_mode='VALID')
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 256, 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, 256, (1, 7))
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, 320, (7, 1))
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 256, 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, 256, (1, 7))
+    conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, 320, (7, 1))
     br1 = conv2d(net, '%s/Branch_1/Conv2d_1a_3x3' % blk, 320, 3, 2,
                  border_mode='VALID')
     br2 = net.add(MaxPooling2D('%s/Branch_2/MaxPool_1a_3x3' % blk, 3, 2,
@@ -118,21 +118,21 @@ def block_inception_c(blk, net):
     s = net.add(Split('%s/Split' % blk, 4))
     br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, 256, 1, src=s)
 
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 384, 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 384, 1, src=s)
     br1 = net.add(Split('%s/Branch_1/Split' % blk, 2))
     br10 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x3' % blk, 256, (1, 3), src=br1)
     br11 = conv2d(net, '%s/Branch_1/Conv2d_0c_3x1' % blk, 256, (3, 1), src=br1)
     br1 = net.add(Concat('%s/Branch_1/Concat' % blk, 1), [br10, br11])
 
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, 384, 1, src=s)
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0b_3x1' % blk, 448, (3, 1))
-    br2 = conv2d(net, '%s/Branch_2/Conv2d_0c_1x3' % blk, 512, (1, 3))
+    conv2d(net, '%s/Branch_2/Conv2d_0a_1x1' % blk, 384, 1, src=s)
+    conv2d(net, '%s/Branch_2/Conv2d_0b_3x1' % blk, 448, (3, 1))
+    conv2d(net, '%s/Branch_2/Conv2d_0c_1x3' % blk, 512, (1, 3))
     br2 = net.add(Split('%s/Branch_2/Split' % blk, 2))
     br20 = conv2d(net, '%s/Branch_2/Conv2d_0d_1x3' % blk, 256, (1, 3), src=br2)
     br21 = conv2d(net, '%s/Branch_2/Conv2d_0e_3x1' % blk, 256, (3, 1), src=br2)
     br2 = net.add(Concat('%s/Branch_2/Concat' % blk, 1), [br20, br21])
 
-    br3 = net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
+    net.add(AvgPooling2D('%s/Branch_3/AvgPool_0a_3x3' % blk, 3, 1), s)
     br3 = conv2d(net, '%s/Branch_3/Conv2d_0b_1x1' % blk, 256, 1)
     return net.add(Concat('%s/Concat' % blk, 1), [br0, br1, br2, br3])
 
@@ -204,12 +204,12 @@ def inception_v4_base(sample_shape, final_endpoint='Inception/Mixed_7d',
     # 73 x 73 x 160
     blk = name + '/Mixed_4a'
     s = net.add(Split('%s/Split' % blk, 2))
-    br0 = conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, 64, 1, src=s)
+    conv2d(net, '%s/Branch_0/Conv2d_0a_1x1' % blk, 64, 1, src=s)
     br0 = conv2d(net, '%s/Branch_0/Conv2d_1a_3x3' % blk, 96, 3,
                  border_mode='VALID')
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 64, 1, src=s)
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, 64, (1, 7))
-    br1 = conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, 64, (7, 1))
+    conv2d(net, '%s/Branch_1/Conv2d_0a_1x1' % blk, 64, 1, src=s)
+    conv2d(net, '%s/Branch_1/Conv2d_0b_1x7' % blk, 64, (1, 7))
+    conv2d(net, '%s/Branch_1/Conv2d_0c_7x1' % blk, 64, (7, 1))
     br1 = conv2d(net, '%s/Branch_1/Conv2d_1a_3x3' % blk, 96, 3,
                  border_mode='VALID')
     end_points[blk] = net.add(Concat('%s/Concat' % blk, 1), [br0, br1])
diff --git a/examples/imagenet/inception/serve.py b/examples/imagenet/inception/serve.py
index 62b719b..307640a 100644
--- a/examples/imagenet/inception/serve.py
+++ b/examples/imagenet/inception/serve.py
@@ -38,7 +38,6 @@ def serve(agent, net, use_cpu, parameter_file, topk=5):
     else:
         print("runing with gpu")
         dev = device.create_cuda_gpu()
-    agent = agent
 
     print('Start intialization............')
     # fix the bug when creating net
@@ -83,9 +82,12 @@ def serve(agent, net, use_cpu, parameter_file, topk=5):
                 idx = np.argsort(-prob)[0:topk]
                 for i in idx:
                     response += "%s:%s<br/>" % (labels[i], prob[i])
-            except:
+            except Exception:
                 traceback.print_exc()
                 response = "Sorry, system error during prediction."
+            except SystemExit:
+                traceback.print_exc()
+                response = "Sorry, error triggered sys.exit() during prediction."
             agent.push(MsgType.kResponse, response)
         elif MsgType.kCommandStop.equal(msg_type):
                 print('get stop command')
@@ -121,7 +123,7 @@ def main():
 
     except SystemExit:
         return
-    except:
+    except Exception:
         traceback.print_exc()
         sys.stderr.write("  for help use --help \n\n")
         return 2
diff --git a/examples/imagenet/resnet/serve.py b/examples/imagenet/resnet/serve.py
index 4c7d897..f337401 100644
--- a/examples/imagenet/resnet/serve.py
+++ b/examples/imagenet/resnet/serve.py
@@ -100,9 +100,12 @@ def serve(net, label_map, dev, agent, topk=5):
                 for i in range(topk):
                     response += "%s:%f <br/>" % (label_map[idx[i]],
                                                  prob[idx[i]])
-            except:
+            except Exception:
                 traceback.print_exc()
-                response = "sorry, system error during prediction."
+                response = "Sorry, system error during prediction."
+            except SystemExit:
+                traceback.print_exc()
+                response = "Sorry, error triggered sys.exit() during prediction."
             agent.push(MsgType.kResponse, response)
         elif msg.is_command():
             if MsgType.kCommandStop.equal(msg):
@@ -162,7 +165,7 @@ def main():
         agent.stop()
     except SystemExit:
         return
-    except:
+    except Exception:
         traceback.print_exc()
         sys.stderr.write("  for help use --help \n\n")
         return 2
diff --git a/examples/imagenet/vgg/serve.py b/examples/imagenet/vgg/serve.py
index b611ae7..7514a8e 100644
--- a/examples/imagenet/vgg/serve.py
+++ b/examples/imagenet/vgg/serve.py
@@ -76,9 +76,12 @@ def serve(net, label_map, dev, agent, topk=5):
                 for i in range(topk):
                     response += "%s:%f <br/>" % (label_map[idx[i]],
                                                  prob[idx[i]])
-            except:
+            except Exception:
                 traceback.print_exc()
-                response = "sorry, system error during prediction."
+                response = "Sorry, system error during prediction."
+            except SystemExit:
+                traceback.print_exc()
+                response = "Sorry, error triggered sys.exit() during prediction."
             agent.push(MsgType.kResponse, response)
         elif msg.is_command():
             if MsgType.kCommandStop.equal(msg):
@@ -137,7 +140,7 @@ def main():
         agent.stop()
     except SystemExit:
         return
-    except:
+    except Exception:
         traceback.print_exc()
         sys.stderr.write("  for help use --help \n\n")
         return 2
diff --git a/python/singa/autograd.py b/python/singa/autograd.py
index 6beac64..d6b7553 100644
--- a/python/singa/autograd.py
+++ b/python/singa/autograd.py
@@ -425,11 +425,6 @@ def less(x,y):
     return Less()(x,y)[0]
 
 
-
-
-
-
-
 class Clip(Operation):
     def __init__(self,min,max):
         super(Clip, self).__init__()
@@ -1996,7 +1991,7 @@ class RNN_Base(Layer):
     def __call__(self):
         raise NotImplementedError
 
-    def step_forward(self):
+    def step_forward(self, x=None, h=None, c=None, Wx=None, Wh=None, Bx=None, Bh=None, b=None):
         raise NotImplementedError
 
 
@@ -2533,8 +2528,8 @@ class And(Operation):
         return cur
 
     def backward(self, dy):
-        assert 0,('no gradient')
-        return None
+        assert False,('no gradient for backward function')
+
 
 def _and(a,b):
     return And()(a,b)[0]
@@ -2551,8 +2546,7 @@ class Or(Operation):
         return cur
 
     def backward(self, dy):
-        assert 0,('no gradient for backward function')
-        return None
+        assert False,('no gradient for backward function')
 
 
 def _or(a,b):
@@ -2571,8 +2565,8 @@ class Not(Operation):
         return cur
 
     def backward(self, dy):
-        assert 0,('no gradient for backward function')
-        return None
+        assert False,('no gradient for backward function')
+
 
 def _not(x):
     return Not()(x)[0]
@@ -2589,8 +2583,7 @@ class Xor(Operation):
         return cur
 
     def backward(self, dy):
-        assert 0,('no gradient for backward function')
-        return None
+        assert False,('no gradient for backward function')
 
 
 def _xor(a,b):
diff --git a/python/singa/sonnx.py b/python/singa/sonnx.py
index 5428566..239ed68 100755
--- a/python/singa/sonnx.py
+++ b/python/singa/sonnx.py
@@ -21,13 +21,13 @@
 from __future__ import division
 
 import warnings
-from collections import deque
 
 from . import singa_wrap as singa
 from . import autograd
 from . import tensor
 
 import collections
+deque = collections.deque
 
 from onnx import (checker, helper, numpy_helper, GraphProto, NodeProto, TensorProto, OperatorSetIdProto)
 from onnx.backend.base import Backend, BackendRep
diff --git a/tool/opencl/clsrc_to_str.py b/tool/opencl/clsrc_to_str.py
index 2feeae1..760e441 100755
--- a/tool/opencl/clsrc_to_str.py
+++ b/tool/opencl/clsrc_to_str.py
@@ -71,5 +71,5 @@ if __name__ == "__main__":
                 fout.write(src)
                 fout.write("\";")
         fout.write("\n } //  namespace opencl \n} //  namespace singa\n\n")
-		fout.write("#endif")
+        fout.write("#endif")
         fout.close()