vllm.utils.math_utils ¶ Math utility functions for vLLM. cdiv ¶ cdiv(a: int, b: int) -> int Ceiling division. Source code in vllm/utils/math_utils.py 6 7 8def cdiv(a: int, b: int) -> int: """Ceiling division.""" return -(a // -b) next_power_of_2 ¶ next_power_of_2(n: int) -> int The next power of 2 (inclusive) Source code in vllm/utils/math_utils.py 11 12 13 14 15def next_power_of_2(n: int) -> int: """The next power of 2 (inclusive)""" if n < 1: return 1 return 1 << (n - 1).bit_length() prev_power_of_2 ¶ prev_power_of_2(n: int) -> int The previous power of 2 (inclusive) Source code in vllm/utils/math_utils.py 18 19 20 21 22def prev_power_of_2(n: int) -> int: """The previous power of 2 (inclusive)""" if n <= 0: return 0 return 1 << (n.bit_length() - 1) round_down ¶ round_down(x: int, y: int) -> int Round down x to the nearest multiple of y. Source code in vllm/utils/math_utils.py 30 31 32def round_down(x: int, y: int) -> int: """Round down x to the nearest multiple of y.""" return (x // y) * y round_up ¶ round_up(x: int, y: int) -> int Round up x to the nearest multiple of y. Source code in vllm/utils/math_utils.py 25 26 27def round_up(x: int, y: int) -> int: """Round up x to the nearest multiple of y.""" return ((x + y - 1) // y) * y