From dev-return-5580-archive-asf-public=cust-asf.ponee.io@singa.apache.org Tue Jun 2 02:32:33 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 622D01804BB for ; Tue, 2 Jun 2020 04:32:33 +0200 (CEST) Received: (qmail 89462 invoked by uid 500); 2 Jun 2020 02:32:32 -0000 Mailing-List: contact dev-help@singa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@singa.apache.org Delivered-To: mailing list dev@singa.apache.org Received: (qmail 89450 invoked by uid 99); 2 Jun 2020 02:32:32 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2020 02:32:32 +0000 From: =?utf-8?q?GitBox?= To: dev@singa.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bsinga=5D_XJDKC_commented_on_a_change_in_pull_reque?= =?utf-8?q?st_=23697=3A_New_Model_Layer_Operator_API?= Message-ID: <159106515227.10999.14028034192355111358.asfpy@gitbox.apache.org> Date: Tue, 02 Jun 2020 02:32:32 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit In-Reply-To: References: XJDKC commented on a change in pull request #697: URL: https://github.com/apache/singa/pull/697#discussion_r433577123 ########## File path: examples/mlp/module.py ########## @@ -56,10 +56,9 @@ def forward(self, inputs): x = autograd.add_bias(x, self.b1) return x - def loss(self, out, ty): - return autograd.softmax_cross_entropy(out, ty) - - def optim(self, loss, dist_option, spars): + def train_one_batch(self, x, y, dist_option, spars): + out = self.forward(x) + loss = autograd.softmax_cross_entropy(out, y) Review comment: Yes. In this way, users only needs to use layers to define their model. ########## File path: examples/cnn/model/resnet.py ########## @@ -21,30 +21,31 @@ # https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py from singa import autograd -from singa import module +from singa import layer +from singa import model def conv3x3(in_planes, out_planes, stride=1): """3x3 convolution with padding""" - return autograd.Conv2d( + return layer.Conv2d( in_planes, out_planes, - kernel_size=3, + 3, stride=stride, padding=1, bias=False, ) -class BasicBlock(autograd.Layer): +class BasicBlock(layer.Layer): expansion = 1 def __init__(self, inplanes, planes, stride=1, downsample=None): super(BasicBlock, self).__init__() self.conv1 = conv3x3(inplanes, planes, stride) - self.bn1 = autograd.BatchNorm2d(planes) + self.bn1 = layer.BatchNorm2d(planes) Review comment: Are there other operators besides ReLU that need to be encapsulated by Layer? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org