From 4a01d23631ef5298f073634d0fc08c3e779a1a64 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Wed, 5 Aug 2020 10:53:08 +0800 Subject: [PATCH] ci(mgb/python_module): fix doctest syntax error GitOrigin-RevId: e98ca810ea7ca46de473ac14ae9078cfc9a4bd32 --- python_module/megengine/core/function.py | 2 +- python_module/megengine/module/sequential.py | 21 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/python_module/megengine/core/function.py b/python_module/megengine/core/function.py index 1219b21e2..c6fb7d438 100644 --- a/python_module/megengine/core/function.py +++ b/python_module/megengine/core/function.py @@ -82,7 +82,7 @@ class Function(metaclass=ABCMeta): self.save_for_backward(y) return y - def backward(self. output_grads): + def backward(self, output_grads): (y, ) = self.saved_tensors return output_grads * y * (1-y) diff --git a/python_module/megengine/module/sequential.py b/python_module/megengine/module/sequential.py index 42d43d844..01291e98a 100644 --- a/python_module/megengine/module/sequential.py +++ b/python_module/megengine/module/sequential.py @@ -21,26 +21,27 @@ class Sequential(Module): .. testcode:: from collections import OrderedDict import numpy as np - import megengine.nn as nn - import megengine.nn.functional as F + import megengine.functional as F + from megengine.module import Sequential, Linear + from megengine import tensor batch_size = 64 - data = nn.Input("data", shape=(batch_size, 1, 28, 28), dtype=np.float32, value=np.zeros((batch_size, 1, 28, 28))) - label = nn.Input("label", shape=(batch_size,), dtype=np.int32, value=np.zeros(batch_size,)) + data = tensor(np.zeros((batch_size, 1, 28, 28)), dtype=np.float32) + label = tensor(np.zeros(batch_size,), dtype=np.int32) data = data.reshape(batch_size, -1) - net0 = nn.Sequential( - nn.Linear(28 * 28, 320), - nn.Linear(320, 10) + net0 = Sequential( + Linear(28 * 28, 320), + Linear(320, 10) ) pred0 = net0(data) modules = OrderedDict() - modules["fc0"] = nn.Linear(28 * 28, 320) - modules["fc1"] = nn.Linear(320, 10) - net1 = nn.Sequential(modules) + modules["fc0"] = Linear(28 * 28, 320) + modules["fc1"] = Linear(320, 10) + net1 = Sequential(modules) pred1 = net1(data) """ -- GitLab