def test_softmax_cross_entropy(): shape = (400, 1000) y = np.random.uniform(-5, 5, shape).astype(dtype) y_ = np.random.uniform(-5, 5, shape).astype(dtype) out = np.zeros((1,)).astype(dtype) arr_y = tvm.nd.array(y, ctx=ctx) arr_y_ = tvm.nd.array(y_, ctx=ctx) arr_out = tvm.nd.array(out, ctx=ctx) matrix_softmax_cross_entropy = tvm_op.make_matrix_softmax_cross_entropy(shape, tgt, tgt_host, "softmax_cross_entropy") matrix_softmax_cross_entropy(arr_y, arr_y_, arr_out) out = arr_out.asnumpy() # numpy calculation cross_entropy = np.mean( -np.sum(y_ * np.log(autodiff.softmax_func(y)), axis=1), keepdims=True) np.testing.assert_allclose(cross_entropy, out, rtol=1e-5)