mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-16 15:06:58 +08:00
Signed-off-by: Yeshwanth Surya <yeshsurya@gmail.com> Signed-off-by: Yeshwanth N <yeshsurya@gmail.com> Signed-off-by: yeshsurya <yeshsurya@gmail.com>
33 lines
774 B
Python
33 lines
774 B
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
"""Math utility functions for vLLM."""
|
|
|
|
|
|
def cdiv(a: int, b: int) -> int:
|
|
"""Ceiling division."""
|
|
return -(a // -b)
|
|
|
|
|
|
def next_power_of_2(n: int) -> int:
|
|
"""The next power of 2 (inclusive)"""
|
|
if n < 1:
|
|
return 1
|
|
return 1 << (n - 1).bit_length()
|
|
|
|
|
|
def prev_power_of_2(n: int) -> int:
|
|
"""The previous power of 2 (inclusive)"""
|
|
if n <= 0:
|
|
return 0
|
|
return 1 << (n.bit_length() - 1)
|
|
|
|
|
|
def round_up(x: int, y: int) -> int:
|
|
"""Round up x to the nearest multiple of y."""
|
|
return ((x + y - 1) // y) * y
|
|
|
|
|
|
def round_down(x: int, y: int) -> int:
|
|
"""Round down x to the nearest multiple of y."""
|
|
return (x // y) * y
|