def METHOD_NAME(test_case, ndim):
    device = random_device()
    minibatch = random(1, 5).to(int).value()
    channels = random(1, 5).to(int).value()
    padding = random(0, 3).to(int).value()
    ceil_mode = random_bool().value()
    count_include_pad = random_bool().value()
    divisor_override = random().to(int).value()
    kernel_size = random(4, 6).to(int).value()
    stride = random(1, 3).to(int).value()
    x_shape = [minibatch, channels] + [
        random(8, 12).to(int).value() for i in range(ndim)
    ]
    kwargs = {
        "kernel_size": kernel_size,
        "stride": oneof(stride, nothing()),
        "padding": oneof(padding, nothing()),
        "ceil_mode": ceil_mode,
        "count_include_pad": count_include_pad,
    }
    if ndim != 1:
        kwargs["divisor_override"] = divisor_override
    m = eval(f"torch.nn.AvgPool{ndim}d")(**kwargs)
    m.to(device)
    x = random_tensor(len(x_shape), *x_shape).to(device)
    y = m(x)
    _check_equal(test_case, y.pytorch, y.oneflow, "y")
    init_grad_y = random_tensor(len(y.oneflow.shape), *y.oneflow.shape).to(device)
    init_grad_x = random_tensor(len(x.oneflow.shape), *x.oneflow.shape).to(device)
    dx = torch.autograd.grad(y, x, init_grad_y, True, True)[0]
    _check_equal(test_case, dx.pytorch, dx.oneflow, "dx")
    ddx_ddy = torch.autograd.grad(dx, [x, init_grad_y], init_grad_x, True, True)
    ddx, ddy = ddx_ddy[0], ddx_ddy[1]
    _check_equal(test_case, ddx.pytorch, ddx.oneflow, "ddx")
    _check_equal(test_case, ddy.pytorch, ddy.oneflow, "ddy")