A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 15, 11:00 UTC
[CI] Make JSON output tests less likely to fail (#17859)
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Russell Bryant committed
May 12, 2025 at 18:31 UTC
ebab1ac37c8efbb29ce052044b1a73ab20b2ea62
2 files changed
+27
-11
tests/v1/entrypoints/conftest.py
+8
-4
@@ -72,12 +72,14 @@ def sample_json_schema():
72
"type": "string"
73
}
74
},
75
- "required": ["company", "duration", "position"]
75
+ "required": ["company", "duration", "position"],
76
+ "additionalProperties": False
77
}
78
}
79
},
80
"required":
80
- ["name", "age", "skills", "grade", "email", "work_history"]
81
+ ["name", "age", "skills", "grade", "email", "work_history"],
82
+ "additionalProperties": False
83
}
84
85
@@ -100,7 +102,8 @@ def unsupported_json_schema():
102
}
103
}
104
},
103
- "required": ["score", "tags"]
105
+ "required": ["score", "tags"],
106
+ "additionalProperties": False
107
}
108
109
@@ -139,7 +142,8 @@ def sample_definition_json_schema():
142
},
143
'required': ['steps', 'final_answer'],
144
'title': 'MathReasoning',
142
- 'type': 'object'
145
+ 'type': 'object',
146
+ "additionalProperties": False
147
}
148
149
tests/v1/entrypoints/llm/test_struct_output_generate.py
+19
-7
@@ -62,6 +62,16 @@ class CarDescription(BaseModel):
62
car_type: CarType
63
64
65
+def _load_json(s: str, backend: str) -> str:
66
+ if backend != "xgrammar":
67
+ return json.loads(s)
68
+
69
+ # xgrammar specific workarounds
70
+ # https://github.com/mlc-ai/xgrammar/issues/286
71
+ s = re.sub(r'[\x00-\x1F\x7F-\xFF]', '', s)
72
+ return json.loads(s)
73
+
74
+
75
@pytest.mark.skip_global_cleanup
76
@pytest.mark.parametrize(
77
"model_name, guided_decoding_backend, tokenizer_mode, speculative_config",
@@ -102,7 +112,7 @@ def test_structured_output(
112
#
113
sampling_params = SamplingParams(
114
temperature=1.0,
105
- max_tokens=1000,
115
+ max_tokens=4096,
116
guided_decoding=GuidedDecodingParams(json=sample_json_schema))
117
outputs = llm.generate(prompts=[
118
(f"Give an example JSON for an employee profile that fits this "
@@ -131,7 +141,7 @@ def test_structured_output(
141
#
142
sampling_params = SamplingParams(
143
temperature=1.0,
134
- max_tokens=100,
144
+ max_tokens=4096,
145
n=2,
146
guided_decoding=GuidedDecodingParams(json_object=True))
147
@@ -161,7 +171,7 @@ def test_structured_output(
171
#
172
sampling_params = SamplingParams(
173
temperature=1.0,
164
- max_tokens=1000,
174
+ max_tokens=4096,
175
guided_decoding=GuidedDecodingParams(json=unsupported_json_schema))
176
if guided_decoding_backend.startswith("xgrammar"):
177
with pytest.raises(ValueError,
@@ -376,12 +386,13 @@ def test_structured_output(
386
"minLength": min_length
387
}
388
},
379
- "required": ["description"]
389
+ "required": ["description"],
390
+ "additionalProperties": False
391
}
392
393
sampling_params = SamplingParams(
394
temperature=1.0,
384
- max_tokens=1000,
395
+ max_tokens=4096,
396
guided_decoding=GuidedDecodingParams(json=json_schema))
397
398
outputs = llm.generate(
@@ -417,7 +428,8 @@ def test_structured_output(
428
"city": {
429
"type": "string"
430
}
420
- }
431
+ },
432
+ "additionalProperties": False
433
},
434
"end": "</function>"
435
}],
@@ -426,7 +438,7 @@ def test_structured_output(
438
439
sampling_params = SamplingParams(
440
temperature=0.0,
429
- max_tokens=100,
441
+ max_tokens=4096,
442
guided_decoding=GuidedDecodingParams(
443
structural_tag=json.dumps(structural_tag_config)))
444