Skip to content

Commit b854321

Browse files
authored
[Docs] Lazy import gguf (#20785)
Signed-off-by: simon-mo <simon.mo@hey.com>
1 parent 5b6fe23 commit b854321

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

vllm/entrypoints/score_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
ChatCompletionContentPartImageParam, ChatCompletionContentPartTextParam,
1212
MultiModalItemTracker, _ContentPart, _parse_chat_message_content_part)
1313
from vllm.inputs import TokensPrompt
14-
from vllm.model_executor.model_loader import get_model_cls
1514
from vllm.model_executor.models.interfaces import supports_score_template
1615
from vllm.multimodal.inputs import MultiModalDataDict
1716
from vllm.outputs import PoolingRequestOutput
@@ -140,6 +139,8 @@ def apply_score_template(
140139
prompt_1: str,
141140
prompt_2: str,
142141
) -> str:
142+
# NOTE(Simon): lazy import to avoid bring in all dependencies (e.g. gguf)
143+
from vllm.model_executor.model_loader import get_model_cls
143144

144145
model = get_model_cls(model_config)
145146
if supports_score_template(model):
@@ -162,6 +163,9 @@ def post_process_tokens(
162163
Note:
163164
This is an in-place operation.
164165
"""
166+
# NOTE(Simon): lazy import to avoid bring in all dependencies (e.g. gguf)
167+
from vllm.model_executor.model_loader import get_model_cls
168+
165169
model = get_model_cls(model_config)
166170
if supports_score_template(model):
167171
model.post_process_tokens(prompt)

vllm/model_executor/model_loader/weight_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from typing import Any, Callable, Optional, Union
1515

1616
import filelock
17-
import gguf
1817
import huggingface_hub.constants
1918
import numpy as np
2019
import torch
@@ -40,6 +39,11 @@
4039
SafetensorsStreamer = runai_model_streamer.placeholder_attr(
4140
"SafetensorsStreamer")
4241

42+
try:
43+
import gguf
44+
except ImportError:
45+
gguf = PlaceholderModule("gguf")
46+
4347
try:
4448
from fastsafetensors import SafeTensorsFileLoader, SingleGroup
4549
except ImportError:

0 commit comments

Comments
 (0)