def test_with_placeholder():
    link = chainer.links.DilatedConvolution2D(None, 16, ksize=3, stride=1, pad=1, dilate=2)
    vx = chainer.Variable(np.random.rand(1, 3, 16, 16).astype(np.float32))
    vy = link(vx)

    N = Placeholder(label="N")
    H = Placeholder(label="H")
    W = Placeholder(label="W")
    px = PlaceholderVariable([N, 3, H, W])
    py = link(px)

    graph = ChainerConverter().convert([px], [py])

    x = graph.inputs[0]
    y = graph.outputs[0]

    N.value = 1
    H.value = 16
    W.value = 16
    generate_kernel_test_case(
        description=f"[chainer] L.DilatedConvolution2D with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={x: vx.data},
        expected={y: vy.data},
        EPS=1e-2
    )
Example #2
0
def test_with_placeholder():
    vx1 = chainer.Variable(np.random.rand(2, 10, 4, 5).astype(np.float32))
    vx2 = chainer.Variable(np.random.rand(2, 15, 4, 5).astype(np.float32))
    vy = chainer.functions.concat([vx1, vx2], axis=1)

    N = Placeholder(label="N")
    C1 = Placeholder(label="C1")
    C2 = Placeholder(label="C2")
    H = Placeholder(label="H")
    W = Placeholder(label="W")
    px1 = PlaceholderVariable([N, C1, H, W])
    px2 = PlaceholderVariable([N, C2, H, W])
    py = chainer.functions.concat([px1, px2], axis=1)

    graph = ChainerConverter().convert([px1, px2], [py])

    N.value = 2
    C1.value = 10
    C2.value = 15
    H.value = 4
    W.value = 5
    generate_kernel_test_case(
        description=f"[chainer] F.concat with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={
            graph.inputs[0]: vx1.data,
            graph.inputs[1]: vx2.data
        },
        expected={graph.outputs[0]: vy.data},
    )
Example #3
0
def test_with_placeholder():
    vx1 = chainer.Variable(np.random.rand(10, 12).astype(np.float32) * 2 - 1)
    vx2 = chainer.Variable(np.random.rand(12, 14).astype(np.float32) * 2 - 1)
    vy = chainer.functions.matmul(vx1, vx2, False, False)

    M = Placeholder(label="M")
    K = Placeholder(label="K")
    N = Placeholder(label="N")
    px1 = PlaceholderVariable([M, K])
    px2 = PlaceholderVariable([K, N])
    py = chainer.functions.matmul(px1, px2, False, False)

    graph = ChainerConverter().convert([px1, px2], [py])

    M.value = 10
    K.value = 12
    N.value = 14
    generate_kernel_test_case(
        description=f"[chainer] F.matmul with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={
            graph.inputs[0]: vx1.data,
            graph.inputs[1]: vx2.data
        },
        expected={graph.outputs[0]: vy.data})
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(1, 3, 16, 16).astype(np.float32))
    vy = chainer.functions.local_response_normalization(vx)

    N = Placeholder(label="N")
    C = Placeholder(label="C")
    H = Placeholder(label="H")
    W = Placeholder(label="W")
    px = PlaceholderVariable([N, C, H, W])
    py = chainer.functions.local_response_normalization(px)

    graph = ChainerConverter().convert([px], [py])

    x = graph.inputs[0]
    y = graph.outputs[0]

    N.value = 1
    C.value = 3
    H.value = 16
    W.value = 16
    generate_kernel_test_case(
        description=
        f"[chainer] F.local_response_normalization with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={x: vx.data},
        expected={y: vy.data},
    )
Example #5
0
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(2, 20, 4, 5).astype(np.float32))
    vy1, vy2, vy3 = chainer.functions.split_axis(vx, [5, 15], 1)

    N = Placeholder(label="N")
    H = Placeholder(label="H")
    W = Placeholder(label="W")
    px = PlaceholderVariable([N, 20, H, W])
    py1, py2, py3 = chainer.functions.split_axis(px, [5, 15], 1)

    graph = ChainerConverter().convert([px], [py1, py2, py3])

    N.value = 2
    H.value = 4
    W.value = 5
    generate_kernel_test_case(
        description=f"[chainer] F.split_axis with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx.data},
        expected={
            graph.outputs[0]: vy1.data,
            graph.outputs[1]: vy2.data,
            graph.outputs[2]: vy3.data
        },
    )
Example #6
0
def test_with_placeholder():
    link = chainer.links.BatchNormalization(size=3)
    vx = chainer.Variable(np.random.rand(1, 3, 16, 16).astype(np.float32))
    with chainer.using_config('train', False):
        vy = link(vx)

    N = Placeholder(label="N")
    H = Placeholder(label="H")
    W = Placeholder(label="W")
    px = PlaceholderVariable([N, 3, H, W])
    with chainer.using_config('train', False):
        py = link(px)

    graph = ChainerConverter().convert([px], [py])

    x = graph.inputs[0]
    y = graph.outputs[0]

    N.value = 1
    H.value = 16
    W.value = 16
    generate_kernel_test_case(
        description=f"[chainer] L.FixedBatchNormalization with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={x: vx.data},
        expected={y: vy.data},
    )
Example #7
0
def test_with_placeholder():
    vx0 = chainer.Variable(np.random.rand(10, 11, 12).astype(np.float32))
    vx1 = chainer.Variable(np.random.rand(10, 11, 12).astype(np.float32))
    vy = chainer.functions.minimum(vx0, vx1)

    A = Placeholder(label="A")
    B = Placeholder(label="B")
    C = Placeholder(label="C")
    px0 = PlaceholderVariable([A, B, C])
    px1 = PlaceholderVariable([A, B, C])
    py = chainer.functions.minimum(px0, px1)

    graph = ChainerConverter().convert([px0, px1], [py])

    A.value = 10
    B.value = 11
    C.value = 12
    generate_kernel_test_case(
        description=f"[chainer] F.minimum with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={
            graph.inputs[0]: vx0.data,
            graph.inputs[1]: vx1.data
        },
        expected={graph.outputs[0]: vy.data},
    )
Example #8
0
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(2, 3, 4, 5).astype(np.float32))
    vy = chainer.functions.expand_dims(vx, axis=1)

    N = Placeholder(label="N")
    C = Placeholder(label="C")
    H = Placeholder(label="H")
    W = Placeholder(label="W")
    px = PlaceholderVariable([N, C, H, W])
    py = chainer.functions.expand_dims(px, axis=1)

    graph = ChainerConverter().convert([px], [py])

    x = graph.inputs[0]
    y = graph.outputs[0]

    N.value = 2
    C.value = 3
    H.value = 4
    W.value = 5
    generate_kernel_test_case(
        description=f"[chainer] F.expand_dims with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={x: vx.data},
        expected={y: vy.data},
    )
Example #9
0
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(2, 5, 4, 8).astype(np.float32))
    vy = chainer.functions.space2depth(vx, r=2)

    N = Placeholder(label="N")
    C = Placeholder(label="C")
    px = PlaceholderVariable([N, C, 4, 8])
    py = chainer.functions.space2depth(px, r=2)

    graph = ChainerConverter().convert([px], [py])

    N.value = 2
    C.value = 5
    generate_kernel_test_case(
        description=f"[chainer] F.space2depth with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx.data},
        expected={graph.outputs[0]: vy.data},
    )
Example #10
0
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(10, 11, 12).astype(np.float32))
    vy = chainer.functions.logsumexp(vx, axis=1)

    A = Placeholder(label="A")
    C = Placeholder(label="C")
    px = PlaceholderVariable([A, 11, C])
    py = chainer.functions.logsumexp(px, axis=1)

    graph = ChainerConverter().convert([px], [py])

    A.value = 10
    C.value = 12
    generate_kernel_test_case(
        description=f"[chainer] F.logsumexp with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx.data},
        expected={graph.outputs[0]: vy.data},
        EPS=1e-2)
Example #11
0
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(1, 3, 16, 16).astype(np.float32))
    vy = vx ** 2

    H = Placeholder(label="H")
    W = Placeholder(label="W")
    px = PlaceholderVariable([1, 3, H, W])
    py = px ** 2

    graph = ChainerConverter().convert([px], [py])

    H.value = 16
    W.value = 16
    generate_kernel_test_case(
        description=f"[chainer] F.PowVarConst with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx.data},
        expected={graph.outputs[0]: vy.data}
    )
Example #12
0
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(2, 16, 7, 7).astype(np.float32))
    vy = chainer.functions.unpooling_2d(vx, ksize=3, stride=2, pad=0)

    N = Placeholder(label="N")
    C = Placeholder(label="C")
    px = PlaceholderVariable([N, C, 7, 7])
    py = chainer.functions.unpooling_2d(px, ksize=3, stride=2, pad=0)

    graph = ChainerConverter().convert([px], [py])

    N.value = 2
    C.value = 16
    generate_kernel_test_case(
        description=f"[chainer] F.unpooling_2d with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx.data},
        expected={graph.outputs[0]: vy.data},
    )
def test_with_placeholder():
    vx1 = chainer.Variable(np.random.rand(2, 8).astype(np.float32))
    vx2 = chainer.Variable(np.random.rand(8, 6).astype(np.float32))
    vy = vx1 @ vx2

    M = Placeholder(label="M")
    N = Placeholder(label="N")
    px1 = PlaceholderVariable([M, 8])
    px2 = PlaceholderVariable([8, N])
    py = px1 @ px2

    graph = ChainerConverter().convert([px1, px2], [py])

    M.value = 2
    N.value = 6
    generate_kernel_test_case(
        description=f"[chainer] F.MatMulVarVar with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx1.data, graph.inputs[1]: vx2.data},
        expected={graph.outputs[0]: vy.data}
    )
Example #14
0
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(10, 11, 12).astype(np.float32))
    vy = chainer.functions.softplus(vx, beta=1.0)

    A = Placeholder(label="A")
    B = Placeholder(label="B")
    C = Placeholder(label="C")
    px = PlaceholderVariable([A, B, C])
    py = chainer.functions.softplus(px, beta=1.0)

    graph = ChainerConverter().convert([px], [py])

    A.value = 10
    B.value = 11
    C.value = 12
    generate_kernel_test_case(
        description=f"[chainer] F.softplus with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx.data},
        expected={graph.outputs[0]: vy.data},
    )
Example #15
0
def test_with_placeholder():
    vx = chainer.Variable(np.random.rand(2, 1, 4, 1).astype(np.float32))
    vy = chainer.functions.squeeze(vx, axis=None)

    N = Placeholder(label="N")
    C = Placeholder(label="C")
    H = Placeholder(label="H")
    W = Placeholder(label="W")
    px = PlaceholderVariable([N, C, H, W])
    py = chainer.functions.squeeze(px, axis=None)

    graph = ChainerConverter().convert([px], [py])

    N.value = 2
    C.value = 1
    H.value = 4
    W.value = 1
    generate_kernel_test_case(
        description=f"[chainer] F.squeeze with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx.data},
        expected={graph.outputs[0]: vy.data},
    )
Example #16
0
def test_with_placeholder():
    link = chainer.links.Linear(16, 32)
    vx = chainer.Variable(np.random.rand(2, 16).astype(np.float32))
    vy = link(vx)

    N = Placeholder(label="N")
    px = PlaceholderVariable([N, 16])
    py = link(px)

    graph = ChainerConverter().convert([px], [py])

    N.value = 2
    generate_kernel_test_case(
        description=f"[chainer] L.Linear with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={graph.inputs[0]: vx.data},
        expected={graph.outputs[0]: vy.data},
    )
def test_with_placeholder():
    rhs = np.random.rand(8, 4)

    vx = chainer.Variable(np.random.rand(2, 8).astype(np.float32))
    vy = vx @ rhs

    M = Placeholder(label="M")
    px = PlaceholderVariable([M, 8])
    py = px @ rhs

    graph = ChainerConverter().convert([px], [py])

    x = graph.inputs[0]
    y = graph.outputs[0]

    M.value = 2
    generate_kernel_test_case(
        description=f"[chainer] F.MatMulVarConstant with placeholder",
        graph=graph,
        backend=["webgpu", "webassembly"],
        inputs={x: vx.data},
        expected={y: vy.data},
    )