mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2026-05-22 09:24:27 +08:00
[CI] Make JSON output tests less likely to fail (#17859)
Signed-off-by: Russell Bryant <rbryant@redhat.com>
This commit is contained in:
parent
2b0db9b0e2
commit
ebab1ac37c
@ -72,12 +72,14 @@ def sample_json_schema():
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["company", "duration", "position"]
|
"required": ["company", "duration", "position"],
|
||||||
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required":
|
"required":
|
||||||
["name", "age", "skills", "grade", "email", "work_history"]
|
["name", "age", "skills", "grade", "email", "work_history"],
|
||||||
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -100,7 +102,8 @@ def unsupported_json_schema():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["score", "tags"]
|
"required": ["score", "tags"],
|
||||||
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -139,7 +142,8 @@ def sample_definition_json_schema():
|
|||||||
},
|
},
|
||||||
'required': ['steps', 'final_answer'],
|
'required': ['steps', 'final_answer'],
|
||||||
'title': 'MathReasoning',
|
'title': 'MathReasoning',
|
||||||
'type': 'object'
|
'type': 'object',
|
||||||
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -62,6 +62,16 @@ class CarDescription(BaseModel):
|
|||||||
car_type: CarType
|
car_type: CarType
|
||||||
|
|
||||||
|
|
||||||
|
def _load_json(s: str, backend: str) -> str:
|
||||||
|
if backend != "xgrammar":
|
||||||
|
return json.loads(s)
|
||||||
|
|
||||||
|
# xgrammar specific workarounds
|
||||||
|
# https://github.com/mlc-ai/xgrammar/issues/286
|
||||||
|
s = re.sub(r'[\x00-\x1F\x7F-\xFF]', '', s)
|
||||||
|
return json.loads(s)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip_global_cleanup
|
@pytest.mark.skip_global_cleanup
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"model_name, guided_decoding_backend, tokenizer_mode, speculative_config",
|
"model_name, guided_decoding_backend, tokenizer_mode, speculative_config",
|
||||||
@ -102,7 +112,7 @@ def test_structured_output(
|
|||||||
#
|
#
|
||||||
sampling_params = SamplingParams(
|
sampling_params = SamplingParams(
|
||||||
temperature=1.0,
|
temperature=1.0,
|
||||||
max_tokens=1000,
|
max_tokens=4096,
|
||||||
guided_decoding=GuidedDecodingParams(json=sample_json_schema))
|
guided_decoding=GuidedDecodingParams(json=sample_json_schema))
|
||||||
outputs = llm.generate(prompts=[
|
outputs = llm.generate(prompts=[
|
||||||
(f"Give an example JSON for an employee profile that fits this "
|
(f"Give an example JSON for an employee profile that fits this "
|
||||||
@ -131,7 +141,7 @@ def test_structured_output(
|
|||||||
#
|
#
|
||||||
sampling_params = SamplingParams(
|
sampling_params = SamplingParams(
|
||||||
temperature=1.0,
|
temperature=1.0,
|
||||||
max_tokens=100,
|
max_tokens=4096,
|
||||||
n=2,
|
n=2,
|
||||||
guided_decoding=GuidedDecodingParams(json_object=True))
|
guided_decoding=GuidedDecodingParams(json_object=True))
|
||||||
|
|
||||||
@ -161,7 +171,7 @@ def test_structured_output(
|
|||||||
#
|
#
|
||||||
sampling_params = SamplingParams(
|
sampling_params = SamplingParams(
|
||||||
temperature=1.0,
|
temperature=1.0,
|
||||||
max_tokens=1000,
|
max_tokens=4096,
|
||||||
guided_decoding=GuidedDecodingParams(json=unsupported_json_schema))
|
guided_decoding=GuidedDecodingParams(json=unsupported_json_schema))
|
||||||
if guided_decoding_backend.startswith("xgrammar"):
|
if guided_decoding_backend.startswith("xgrammar"):
|
||||||
with pytest.raises(ValueError,
|
with pytest.raises(ValueError,
|
||||||
@ -376,12 +386,13 @@ def test_structured_output(
|
|||||||
"minLength": min_length
|
"minLength": min_length
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["description"]
|
"required": ["description"],
|
||||||
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
|
|
||||||
sampling_params = SamplingParams(
|
sampling_params = SamplingParams(
|
||||||
temperature=1.0,
|
temperature=1.0,
|
||||||
max_tokens=1000,
|
max_tokens=4096,
|
||||||
guided_decoding=GuidedDecodingParams(json=json_schema))
|
guided_decoding=GuidedDecodingParams(json=json_schema))
|
||||||
|
|
||||||
outputs = llm.generate(
|
outputs = llm.generate(
|
||||||
@ -417,7 +428,8 @@ def test_structured_output(
|
|||||||
"city": {
|
"city": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"additionalProperties": False
|
||||||
},
|
},
|
||||||
"end": "</function>"
|
"end": "</function>"
|
||||||
}],
|
}],
|
||||||
@ -426,7 +438,7 @@ def test_structured_output(
|
|||||||
|
|
||||||
sampling_params = SamplingParams(
|
sampling_params = SamplingParams(
|
||||||
temperature=0.0,
|
temperature=0.0,
|
||||||
max_tokens=100,
|
max_tokens=4096,
|
||||||
guided_decoding=GuidedDecodingParams(
|
guided_decoding=GuidedDecodingParams(
|
||||||
structural_tag=json.dumps(structural_tag_config)))
|
structural_tag=json.dumps(structural_tag_config)))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user