vllm.transformers_utils.gguf_utils ¶
GGUF utility functions.
Functions:
-
check_gguf_file–Check if the file is a GGUF model.
-
detect_gguf_multimodal–Check if GGUF model has multimodal projector file.
-
extract_vision_config_from_gguf–Extract vision config parameters from mmproj.gguf metadata.
-
get_gguf_file_path_from_hf–Get the GGUF file path from HuggingFace Hub based on repo_id and quant_type.
-
is_gguf–Check if the model is a GGUF model.
-
is_nonstandard_gguf_quant_type–Check if a non-standard quant type contains a known GGML type.
-
is_remote_gguf–Check if the model is a remote GGUF model.
-
is_valid_gguf_quant_type–Check if the quant type is a valid GGUF quant type.
-
maybe_patch_hf_config_from_gguf–Patch HF config for GGUF models.
-
split_remote_gguf–Split the model into repo_id and quant type.
check_gguf_file(model) cached ¶
Check if the file is a GGUF model.
Source code in vllm/transformers_utils/gguf_utils.py
detect_gguf_multimodal(model) ¶
Check if GGUF model has multimodal projector file.
Parameters:
Returns:
-
Path | None–Path to mmproj file if found, None otherwise
Source code in vllm/transformers_utils/gguf_utils.py
extract_vision_config_from_gguf(mmproj_path) ¶
Extract vision config parameters from mmproj.gguf metadata.
Reads vision encoder configuration from GGUF metadata fields using standardized GGUF constants. Automatically detects the projector type (e.g., gemma3, llama4) and applies model-specific parameters accordingly.
The function extracts standard CLIP vision parameters from GGUF metadata and applies projector-type-specific customizations. For unknown projector types, it uses safe defaults from SiglipVisionConfig.
Parameters:
Returns:
-
SiglipVisionConfig | None–SiglipVisionConfig if extraction succeeds, None if any required
-
SiglipVisionConfig | None–field is missing from the GGUF metadata
Raises:
-
Exception–Exceptions from GGUF reading (file not found, corrupted file, etc.) propagate directly from gguf.GGUFReader
Source code in vllm/transformers_utils/gguf_utils.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
get_gguf_file_path_from_hf(repo_id, quant_type, revision=None) ¶
Get the GGUF file path from HuggingFace Hub based on repo_id and quant_type.
Parameters:
-
(repo_id¶str | Path) –The HuggingFace repository ID (e.g., "Qwen/Qwen3-0.6B")
-
(quant_type¶str) –The quantization type (e.g., "Q4_K_M", "F16")
-
(revision¶str | None, default:None) –Optional revision/branch name
Returns:
-
str–The path to the GGUF file on HuggingFace Hub (e.g., "filename.gguf"),
Source code in vllm/transformers_utils/gguf_utils.py
is_gguf(model) ¶
Check if the model is a GGUF model.
Parameters:
Returns:
-
bool–True if the model is a GGUF model, False otherwise.
Source code in vllm/transformers_utils/gguf_utils.py
is_nonstandard_gguf_quant_type(quant_type) ¶
Check if a non-standard quant type contains a known GGML type.
Splits the quant type by the last - and checks whether the trailing part is a standard GGML type. For example::
UD-Q4_K_XL → rsplit → ["UD", "Q4_K_XL"] → Q4_K_XL valid ✓
UD-IQ4_NL → rsplit → ["UD", "IQ4_NL"] → IQ4_NL valid ✓
Custom-UD-Q4_K → rsplit → ["Custom-UD", "Q4_K"] → Q4_K valid ✓
RANDOM → no "-" → False
Source code in vllm/transformers_utils/gguf_utils.py
is_remote_gguf(model) cached ¶
Check if the model is a remote GGUF model.
Recognizes two forms: 1. Standard: repo_id:quant_type where quant_type is a known GGML quantization type (e.g. Q4_K_M). 2. Non-standard: repo_id:quant_type where quant_type contains a known GGML type with extra prefixes (e.g. UD-Q4_K_XL). A warning is logged and actual file existence is validated later during download.
Source code in vllm/transformers_utils/gguf_utils.py
is_valid_gguf_quant_type(gguf_quant_type) ¶
Check if the quant type is a valid GGUF quant type.
Supports both exact GGML quant types (e.g., Q4_K, IQ1_S) and extended naming conventions (e.g., Q4_K_M, Q3_K_S, Q5_K_L).
Source code in vllm/transformers_utils/gguf_utils.py
maybe_patch_hf_config_from_gguf(model, hf_config) ¶
Patch HF config for GGUF models.
Applies GGUF-specific patches to HuggingFace config: 1. For multimodal models: patches architecture and vision config 2. For all GGUF models: overrides vocab_size from embedding tensor
This ensures compatibility with GGUF models that have extended vocabularies (e.g., Unsloth) where the GGUF file contains more tokens than the HuggingFace tokenizer config specifies.
Parameters:
-
(model¶str) –Model path string
-
(hf_config¶PretrainedConfig) –HuggingFace config to patch in-place
Returns:
-
PretrainedConfig–Updated HuggingFace config
Source code in vllm/transformers_utils/gguf_utils.py
split_remote_gguf(model) ¶
Split the model into repo_id and quant type.