Skip to content

vllm.utils.cpu_resource_utils

parse_id_list

parse_id_list(raw_str: str) -> list[int]

Parses strings like '0-2,4,7-8' into [0, 1, 2, 4, 7, 8]

Source code in vllm/utils/cpu_resource_utils.py
def parse_id_list(raw_str: str) -> list[int]:
    """Parses strings like '0-2,4,7-8' into [0, 1, 2, 4, 7, 8]"""
    result: list[int] = []
    if not raw_str:
        return result

    for part in raw_str.split(","):
        if "-" in part:
            start, end = map(int, part.split("-"))
            result.extend(range(start, end + 1))
        else:
            result.append(int(part))
    return sorted(list(set(result)))