Skip to content

Commit 21fb68a

Browse files
[CI] Update guided decoding ut (#1312)
### What this PR does / why we need it? Update guided decoding ut. Signed-off-by: shen-shanshan <467638484@qq.com>
1 parent 339d689 commit 21fb68a

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

.github/workflows/vllm_ascend_test.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ jobs:
259259
# TODO: switch hf to modelscope
260260
VLLM_USE_MODELSCOPE=False HF_ENDPOINT=https://hf-mirror.com \
261261
pytest -sv tests/e2e/singlecard/test_ilama_lora.py
262-
# TODO(sss): guided decoding doesn't work, fix it later
263-
# pytest -sv tests/e2e/singlecard/test_guided_decoding.py
262+
pytest -sv tests/e2e/singlecard/test_guided_decoding.py
264263
pytest -sv tests/e2e/singlecard/test_camem.py
265264
pytest -sv tests/e2e/singlecard/ \
266265
--ignore=tests/e2e/singlecard/test_offline_inference.py \
@@ -278,8 +277,7 @@ jobs:
278277
# TODO: switch hf to modelscope
279278
VLLM_USE_MODELSCOPE=False HF_ENDPOINT=https://hf-mirror.com \
280279
pytest -sv tests/e2e/singlecard/test_ilama_lora.py
281-
# guided decoding doesn't work, fix it later
282-
# pytest -sv tests/e2e/singlecard/test_guided_decoding.py
280+
pytest -sv tests/e2e/singlecard/test_guided_decoding.py
283281
pytest -sv tests/e2e/singlecard/test_camem.py
284282
pytest -sv tests/e2e/singlecard/test_prompt_embedding.py
285283
pytest -sv tests/e2e/singlecard/ \

tests/e2e/singlecard/test_guided_decoding.py

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@
2828
from tests.conftest import VllmRunner
2929

3030
os.environ["PYTORCH_NPU_ALLOC_CONF"] = "max_split_size_mb:256"
31-
MODEL_NAME = "Qwen/Qwen2.5-1.5B-Instruct"
32-
GuidedDecodingBackendV0 = [
33-
"outlines",
34-
"lm-format-enforcer",
35-
"xgrammar",
36-
]
37-
GuidedDecodingBackendV1 = ["xgrammar", "guidance:disable-any-whitespace"]
31+
MODEL_NAME = "Qwen/Qwen2.5-0.5B-Instruct"
32+
33+
GuidedDecodingBackendV0 = ["outlines", "lm-format-enforcer", "xgrammar"]
34+
GuidedDecodingBackendV1 = ["xgrammar", "guidance"]
3835
GuidedDecodingBackend = list(
3936
set(GuidedDecodingBackendV0 + GuidedDecodingBackendV1))
4037

@@ -87,26 +84,25 @@ def sample_json_schema():
8784
}
8885

8986

90-
@pytest.mark.parametrize("guided_decoding_backend", GuidedDecodingBackend)
91-
def test_guided_json_completion(guided_decoding_backend: str,
92-
sample_json_schema):
93-
if guided_decoding_backend == "xgrammar":
94-
# xgrammar does not support json schema, will fall back to outlines, skip it
95-
pytest.skip(
96-
f"{guided_decoding_backend} will fall back to outlines, skip it")
87+
def check_backend(guided_decoding_backend: str):
9788
if guided_decoding_backend not in GuidedDecodingBackendV0 and os.getenv(
9889
"VLLM_USE_V1") == "0":
99-
# guidance does not support on v0, skip it
100-
pytest.skip(
101-
f"{guided_decoding_backend} does not support on v0, skip it")
90+
pytest.skip(f"{guided_decoding_backend} does not support v0, skip it.")
10291
if guided_decoding_backend not in GuidedDecodingBackendV1 and os.getenv(
10392
"VLLM_USE_V1") == "1":
104-
pytest.skip(f"{guided_decoding_backend} does not support v1, skip it")
93+
pytest.skip(f"{guided_decoding_backend} does not support v1, skip it.")
94+
95+
96+
@pytest.mark.parametrize("guided_decoding_backend", GuidedDecodingBackend)
97+
def test_guided_json_completion(guided_decoding_backend: str,
98+
sample_json_schema):
99+
check_backend(guided_decoding_backend)
105100

106101
sampling_params = SamplingParams(
107102
temperature=1.0,
108-
max_tokens=1000,
103+
max_tokens=500,
109104
guided_decoding=GuidedDecodingParams(json=sample_json_schema))
105+
110106
with VllmRunner(
111107
MODEL_NAME,
112108
seed=0,
@@ -138,19 +134,13 @@ def test_guided_json_completion(guided_decoding_backend: str,
138134

139135
@pytest.mark.parametrize("guided_decoding_backend", GuidedDecodingBackend)
140136
def test_guided_regex(guided_decoding_backend: str, sample_regex):
141-
if guided_decoding_backend not in GuidedDecodingBackendV0 and os.getenv(
142-
"VLLM_USE_V1") == "0":
143-
# guidance does not support on v0, skip it
144-
pytest.skip(
145-
f"{guided_decoding_backend} does not support on v0, skip it")
146-
if guided_decoding_backend not in GuidedDecodingBackendV1 and os.getenv(
147-
"VLLM_USE_V1") == "1":
148-
pytest.skip(f"{guided_decoding_backend} does not support v1, skip it")
137+
check_backend(guided_decoding_backend)
138+
139+
sampling_params = SamplingParams(
140+
temperature=0.8,
141+
top_p=0.95,
142+
guided_decoding=GuidedDecodingParams(regex=sample_regex))
149143

150-
sampling_params = SamplingParams(temperature=0.8,
151-
top_p=0.95,
152-
guided_decoding=GuidedDecodingParams(
153-
regex=sample_regex, ))
154144
with VllmRunner(
155145
MODEL_NAME,
156146
seed=0,

0 commit comments

Comments
 (0)