Beispiel #1
0
def verify_reverse_sequence(x_data, seq_lengths, batch_axis, seq_axis, ref_res):
    seq_lengths_data = np.array(seq_lengths).astype('int32')
    x = relay.var('x', relay.TensorType(x_data.shape, str(x_data.dtype)))
    z = relay.reverse_sequence(x, relay.const(seq_lengths_data), seq_axis, batch_axis)
    zz = run_infer_type(z)
    assert (zz.checked_type == x.type_annotation)
    func = relay.Function([x], z)
    for (target, ctx) in tvm.testing.enabled_targets():
        for kind in ['graph', 'debug']:
            intrp = relay.create_executor(kind, ctx=ctx, target=target)
            op_res = intrp.evaluate(func)(x_data)
            tvm.testing.assert_allclose(op_res.asnumpy(), ref_res, rtol=1e-05)
    def verify_reverse_sequence(x_data, seq_lengths, batch_axis, seq_axis,
                                ref_res):
        seq_lengths_data = np.array(seq_lengths).astype("int32")
        x = relay.var("x", relay.TensorType(x_data.shape, str(x_data.dtype)))
        z = relay.reverse_sequence(x, relay.const(seq_lengths_data), seq_axis,
                                   batch_axis)
        zz = run_infer_type(z)
        assert zz.checked_type == x.type_annotation
        func = relay.Function([x], z)

        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(kind, ctx=ctx, target=target)
                op_res = intrp.evaluate(func)(x_data)
                tvm.testing.assert_allclose(op_res.asnumpy(),
                                            ref_res,
                                            rtol=1e-5)