Signed-off-by: AndyZhou952 <jzhoubc@connect.ust.hk> Signed-off-by: Andy Zhou <jzhoubc@connect.ust.hk> Signed-off-by: dongbo910220 <1275604947@qq.com> Signed-off-by: Andy Zhou <46011930+AndyZhou952@users.noreply.github.com> Signed-off-by: Samit <285365963@qq.com> Co-authored-by: dongbo910220 <1275604947@qq.com> Co-authored-by: Samit <285365963@qq.com>
23 lines
771 B
Python
23 lines
771 B
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
|
|
|
|
def stable_lora_int_id(lora_path: str) -> int:
|
|
"""Return a deterministic positive integer ID for a LoRA adapter.
|
|
|
|
vLLM uses `lora_int_id` as the adapter's cache key. Python's built-in
|
|
`hash()` is intentionally randomized per process (PYTHONHASHSEED), which
|
|
makes it unsuitable for persistent IDs. This helper derives a stable
|
|
63-bit positive integer from the adapter path.
|
|
"""
|
|
digest = hashlib.sha256(lora_path.encode("utf-8")).digest()
|
|
value = int.from_bytes(digest[:8], byteorder="big", signed=False) & ((1 << 63) - 1)
|
|
return value or 1
|
|
|
|
|
|
__all__ = ["stable_lora_int_id"]
|