def _adaptive_pool2d_non_fixed_kernel_size_and_stride(x, output_shape, name, reduce_op):
    '''
    If the input dimension is not evenly divisible by the output dimension, then the
    stride and kernel size used by PyTorch is not fixed. This is true for both the
    height and width dimension.
    '''

    pool_results = []
    for s2, e2 in _get_kernel_indexes_1d_for_adaptive_pooling(x.shape[-2], output_shape[0]):
        for s3, e3 in _get_kernel_indexes_1d_for_adaptive_pooling(x.shape[-1], output_shape[1]):
            begin = tuple([0] * (x.rank - 2) + [s2, s3])
            end = x.shape[: x.rank - 2] + (e2, e3)
            cur_kernel = mb.slice_by_index(x=x, begin=begin, end=end)
            cur_result = reduce_op(
                x=cur_kernel,
                axes=[-2, -1],
                keep_dims=True
            )
            pool_results.append(cur_result)
    pool_result = mb.concat(values=pool_results, axis=-1)

    shape = x.shape[: x.rank - 2] + output_shape
    return mb.reshape(x=pool_result, shape=shape, name=name)

    If the input dimension is not evenly divisible by the output dimension, then the
    stride and kernel size used by PyTorch is not fixed. This is true for both the
    height and width dimension.
    
coremltools/converters/mil/frontend/torch/ops.py