|
5 | 5 | import datetime |
6 | 6 | import enum |
7 | 7 | import getpass |
8 | | -import hashlib |
9 | 8 | import importlib |
10 | 9 | import inspect |
11 | 10 | import ipaddress |
12 | 11 | import json |
13 | 12 | import multiprocessing |
14 | 13 | import os |
15 | | -import pickle |
16 | 14 | import signal |
17 | 15 | import socket |
18 | 16 | import subprocess |
|
45 | 43 | from urllib.parse import urlparse |
46 | 44 | from uuid import uuid4 |
47 | 45 |
|
48 | | -import cbor2 |
49 | 46 | import cloudpickle |
50 | 47 | import psutil |
51 | 48 | import regex as re |
@@ -1463,56 +1460,7 @@ def check_use_alibi(model_config: ModelConfig) -> bool: |
1463 | 1460 | ) |
1464 | 1461 |
|
1465 | 1462 |
|
1466 | | -def sha256(input: Any) -> bytes: |
1467 | | - """Hash any picklable Python object using SHA-256. |
1468 | | -
|
1469 | | - The input is serialized using pickle before hashing, which allows |
1470 | | - arbitrary Python objects to be used. Note that this function does |
1471 | | - not use a hash seed—if you need one, prepend it explicitly to the input. |
1472 | | -
|
1473 | | - Args: |
1474 | | - input: Any picklable Python object. |
1475 | | -
|
1476 | | - Returns: |
1477 | | - Bytes representing the SHA-256 hash of the serialized input. |
1478 | | - """ |
1479 | | - input_bytes = pickle.dumps(input, protocol=pickle.HIGHEST_PROTOCOL) |
1480 | | - return hashlib.sha256(input_bytes).digest() |
1481 | | - |
1482 | | - |
1483 | | -def sha256_cbor(input: Any) -> bytes: |
1484 | | - """ |
1485 | | - Hash objects using CBOR serialization and SHA-256. |
1486 | | -
|
1487 | | - This option is useful for non-Python-dependent serialization and hashing. |
1488 | | -
|
1489 | | - Args: |
1490 | | - input: Object to be serialized and hashed. Supported types include |
1491 | | - basic Python types and complex structures like lists, tuples, and |
1492 | | - dictionaries. |
1493 | | - Custom classes must implement CBOR serialization methods. |
1494 | | -
|
1495 | | - Returns: |
1496 | | - Bytes representing the SHA-256 hash of the CBOR serialized input. |
1497 | | - """ |
1498 | | - input_bytes = cbor2.dumps(input, canonical=True) |
1499 | | - return hashlib.sha256(input_bytes).digest() |
1500 | | - |
1501 | | - |
1502 | | -def get_hash_fn_by_name(hash_fn_name: str) -> Callable[[Any], bytes]: |
1503 | | - """Get a hash function by name, or raise an error if |
1504 | | - the function is not found. |
1505 | | - Args: |
1506 | | - hash_fn_name: Name of the hash function. |
1507 | | - Returns: |
1508 | | - A hash function. |
1509 | | - """ |
1510 | | - if hash_fn_name == "sha256": |
1511 | | - return sha256 |
1512 | | - if hash_fn_name == "sha256_cbor": |
1513 | | - return sha256_cbor |
1514 | | - |
1515 | | - raise ValueError(f"Unsupported hash function: {hash_fn_name}") |
| 1463 | +## moved to vllm.utils.hashing |
1516 | 1464 |
|
1517 | 1465 |
|
1518 | 1466 | @cache |
|
0 commit comments