def _get_closet_bucket(bucket_sizes, data_length):
    """Select the one from bucket_sizes that is closest in distance to
    data_length. This is required for TorchAcc.
    """
    closest_length = sys.maxsize
    for b in bucket_sizes:
        if b == data_length or ((b < closest_length) and (b > data_length)):
            closest_length = b

    if closest_length == sys.maxsize:
        bucket_sizes.append(data_length)
        closest_length = data_length

    return closest_length
Select the one from bucket_sizes that is closest in distance to
    data_length. This is required for TorchAcc.
    
swift/utils/torchacc_utils.py