vllm.transformers_utils.gguf_utils ¶
GGUF utility functions.
check_gguf_file cached ¶
Check if the file is a GGUF model.
Source code in vllm/transformers_utils/gguf_utils.py
detect_gguf_multimodal ¶
Check if GGUF model has multimodal projector file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | str | Model path string | required |
Returns:
| Type | Description |
|---|---|
Path | None | Path to mmproj file if found, None otherwise |
Source code in vllm/transformers_utils/gguf_utils.py
extract_vision_config_from_gguf ¶
extract_vision_config_from_gguf(
mmproj_path: str,
) -> SiglipVisionConfig | None
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:
| Name | Type | Description | Default |
|---|---|---|---|
mmproj_path | str | Path to mmproj.gguf file (str or Path) | required |
Returns:
| Type | Description |
|---|---|
SiglipVisionConfig | None | SiglipVisionConfig if extraction succeeds, None if any required |
SiglipVisionConfig | None | field is missing from the GGUF metadata |
Raises:
| Type | Description |
|---|---|
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 ¶
get_gguf_file_path_from_hf(
repo_id: str | Path,
quant_type: str,
revision: str | None = None,
) -> str
Get the GGUF file path from HuggingFace Hub based on repo_id and quant_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_id | str | Path | The HuggingFace repository ID (e.g., "Qwen/Qwen3-0.6B") | required |
quant_type | str | The quantization type (e.g., "Q4_K_M", "F16") | required |
revision | str | None | Optional revision/branch name | None |
Returns:
| Type | Description |
|---|---|
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 ¶
Check if the model is a GGUF model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | str | Path | Model name, path, or Path object to check. | required |
Returns:
| Type | Description |
|---|---|
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 ¶
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 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 ¶
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 ¶
maybe_patch_hf_config_from_gguf(
model: str, hf_config: PretrainedConfig
) -> PretrainedConfig
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:
| Name | Type | Description | Default |
|---|---|---|---|
model | str | Model path string | required |
hf_config | PretrainedConfig | HuggingFace config to patch in-place | required |
Returns:
| Type | Description |
|---|---|
PretrainedConfig | Updated HuggingFace config |
Source code in vllm/transformers_utils/gguf_utils.py
split_remote_gguf ¶
Split the model into repo_id and quant type.