From 7a6d45bc8a201623c646627becd837afd6b35bc7 Mon Sep 17 00:00:00 2001 From: Matthew Vine <32849887+MattTheCuber@users.noreply.github.com> Date: Wed, 26 Mar 2025 20:19:46 -0400 Subject: [PATCH] Support FIPS enabled machines with MD5 hashing (#15299) Signed-off-by: Matthew Vine <32849887+MattTheCuber@users.noreply.github.com> --- tests/compile/piecewise/test_toy_llama.py | 3 +- vllm/compilation/backends.py | 7 ++-- vllm/compilation/compiler_interface.py | 3 +- vllm/config.py | 42 +++++++++++++++-------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/tests/compile/piecewise/test_toy_llama.py b/tests/compile/piecewise/test_toy_llama.py index 7307f44b6184..d4551b1cc3ae 100644 --- a/tests/compile/piecewise/test_toy_llama.py +++ b/tests/compile/piecewise/test_toy_llama.py @@ -63,7 +63,8 @@ class LlamaConfig: factors.append((k, v)) factors.sort() import hashlib - return hashlib.md5(str(factors).encode()).hexdigest() + return hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() def __post_init__(self): assert self.mlp_size >= self.hidden_size diff --git a/vllm/compilation/backends.py b/vllm/compilation/backends.py index d8c0c59ba9b2..45988c2e9b0d 100644 --- a/vllm/compilation/backends.py +++ b/vllm/compilation/backends.py @@ -381,8 +381,8 @@ class VllmBackend: with open(filepath) as f: hash_content.append(f.read()) import hashlib - code_hash = hashlib.md5( - "\n".join(hash_content).encode()).hexdigest() + code_hash = hashlib.md5("\n".join(hash_content).encode(), + usedforsecurity=False).hexdigest() factors.append(code_hash) # 3. compiler hash @@ -390,7 +390,8 @@ class VllmBackend: factors.append(compiler_hash) # combine all factors to generate the cache dir - hash_key = hashlib.md5(str(factors).encode()).hexdigest()[:10] + hash_key = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest()[:10] cache_dir = os.path.join( envs.VLLM_CACHE_ROOT, diff --git a/vllm/compilation/compiler_interface.py b/vllm/compilation/compiler_interface.py index b45c694fd7f8..571e2b832e95 100644 --- a/vllm/compilation/compiler_interface.py +++ b/vllm/compilation/compiler_interface.py @@ -139,7 +139,8 @@ class InductorAdaptor(CompilerInterface): from torch._inductor.codecache import torch_key torch_factors = torch_key() factors.append(torch_factors) - hash_str = hashlib.md5(str(factors).encode()).hexdigest()[:10] + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest()[:10] return hash_str def initialize_cache(self, cache_dir: str, disable_cache: bool = False): diff --git a/vllm/config.py b/vllm/config.py index 94cecba1e1fc..2e9325c258b2 100644 --- a/vllm/config.py +++ b/vllm/config.py @@ -1111,7 +1111,8 @@ class CacheConfig: factors: list[Any] = [] factors.append(self.cache_dtype) # `cpu_offload_gb` does not use `torch.compile` yet. - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __init__( @@ -1243,7 +1244,8 @@ class TokenizerPoolConfig: # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __post_init__(self): @@ -1354,7 +1356,8 @@ class LoadConfig: # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __post_init__(self): @@ -1674,7 +1677,8 @@ class SchedulerConfig: # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __post_init__(self) -> None: @@ -1810,7 +1814,8 @@ class DeviceConfig: # the device/platform information will be summarized # by torch/vllm automatically. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __init__(self, device: str = "auto") -> None: @@ -1983,7 +1988,8 @@ class SpeculativeConfig: # no factors to consider. # spec decode does not use `torch.compile` yet. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str @classmethod @@ -2358,7 +2364,8 @@ class LoRAConfig: factors.append(self.lora_extra_vocab_size) factors.append(self.long_lora_scaling_factors) factors.append(self.bias_enabled) - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __post_init__(self): @@ -2424,7 +2431,8 @@ class PromptAdapterConfig: # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __post_init__(self): @@ -2469,7 +2477,8 @@ class MultiModalConfig: # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def get_limit_per_prompt(self, modality: str) -> int: @@ -2535,7 +2544,8 @@ class PoolerConfig: # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str @staticmethod @@ -2816,7 +2826,8 @@ class DecodingConfig: # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __post_init__(self): @@ -2866,7 +2877,8 @@ class ObservabilityConfig: # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str def __post_init__(self): @@ -2928,7 +2940,8 @@ class KVTransferConfig(BaseModel): # no factors to consider. # this config will not affect the computation graph. factors: list[Any] = [] - hash_str = hashlib.md5(str(factors).encode()).hexdigest() + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest() return hash_str @classmethod @@ -3425,7 +3438,8 @@ class VllmConfig: vllm_factors.append("None") factors.append(vllm_factors) - hash_str = hashlib.md5(str(factors).encode()).hexdigest()[:10] + hash_str = hashlib.md5(str(factors).encode(), + usedforsecurity=False).hexdigest()[:10] return hash_str def pad_for_cudagraph(self, batch_size: int) -> int: