File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
vllm/model_executor/guided_decoding Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ def maybe_backend_fallback(
4040 guided_params .backend = "outlines"
4141
4242 if guided_params .backend == "xgrammar" :
43+ from vllm .model_executor .guided_decoding .xgrammar_decoding import (
44+ xgr_installed )
4345 # xgrammar only has x86 wheels for linux, fallback to outlines
4446 from vllm .platforms import current_platform
4547 if current_platform .get_cpu_architecture () is not CpuArchEnum .X86 :
@@ -77,6 +79,13 @@ def maybe_backend_fallback(
7779 "Falling back to use outlines instead." )
7880 guided_params .backend = "outlines"
7981
82+ # If the xgrammar module cannot be imported successfully,
83+ # we should still allow users to use guided decoding with a fallback.
84+ elif not xgr_installed :
85+ logger .warning ("xgrammar module cannot be imported successfully. "
86+ "Falling back to use outlines instead." )
87+ guided_params .backend = "outlines"
88+
8089 if (guided_params .backend == "outlines"
8190 and guided_params .json_object is not None ):
8291 # outlines doesn't support json_object, fallback to xgrammar
Original file line number Diff line number Diff line change 1414try :
1515 import xgrammar as xgr
1616 from xgrammar .base import _core as xgr_core
17+ xgr_installed = True
1718except ImportError :
19+ xgr_installed = False
1820 pass
1921
2022from vllm .model_executor .guided_decoding .utils import (convert_lark_to_gbnf ,
You can’t perform that action at this time.
0 commit comments