コード例 #1
0
    def build_impl(self, input_size, memory_size, dtype="float32"):
        t = TensorType(shape=(1, memory_size), dtype=dtype)
        i = self.input(
            var("lstmcell_input", shape=(1, input_size), dtype=dtype))
        c = self.input(Var("lstmcell_children", self.p.l(TupleType([t, t]))))
        sum = lam(["x", "y"], lambda x, y: x + y)
        child_h_sum = self.p.foldl(
            sum, op.zeros(shape=(1, memory_size), dtype=dtype),
            self.p.map(lam(["z"], lambda z: TupleGetItem(z, 1)), c))
        ioux = Linear(input_size=input_size, output_size=memory_size * 3)(i)
        iouh = Linear(input_size=memory_size,
                      output_size=memory_size * 3)(child_h_sum)
        iou = ioux + iouh
        fx = Linear(input_size=input_size, output_size=memory_size)(i)
        fh = Linear(input_size=memory_size, output_size=memory_size)
        i, o, u = op.split(iou, 3, axis=1)
        i, o, u = op.sigmoid(i), op.sigmoid(o), op.tanh(u)

        def foreach_children(children):
            f = op.sigmoid(fh(TupleGetItem(children, 1)) + fx)
            return f * TupleGetItem(children, 0)

        c = self.p.foldl(sum, i * u, self.p.map(lam(["z"], foreach_children),
                                                c))
        return Tuple([c, o * op.tanh(c)])
コード例 #2
0
ファイル: to_relay.py プロジェクト: zheng-xq/tvm
def _split(children, attrs, odtype='float32'):
    indices_or_sections = None
    try:
        indices_or_sections = attrs.get_int('indices_or_sections', None)
    except ValueError:
        indices_or_sections = indices_or_sections or attrs.get_int_tuple(
            'indices_or_sections')

    axis = attrs.get_int('axis', 0)

    return op.split(children[0], indices_or_sections, axis)