vllm.utils.math_utils ¶ Math utility functions for vLLM. RCP_LN2 module-attribute ¶ RCP_LN2 = 1.4426950216 cdiv ¶ cdiv(a: int, b: int) -> int Ceiling division. Source code in vllm/utils/math_utils.py 10 11 12def 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 15 16 17 18 19def 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 22 23 24 25 26def 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 34 35 36def 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 29 30 31def round_up(x: int, y: int) -> int: """Round up x to the nearest multiple of y.""" return ((x + y - 1) // y) * y