Fix unit tests for the frontend language part (#872)

This commit is contained in:
Ying Sheng
2024-08-01 12:39:12 -07:00
committed by GitHub
parent aba6f51f88
commit 6f221d4ca0
11 changed files with 80 additions and 83 deletions

View File

@@ -99,7 +99,6 @@ class SglSamplingParams:
"stop": self.stop or None,
"temperature": self.temperature,
"top_p": self.top_p,
"top_k": self.top_k,
"frequency_penalty": self.frequency_penalty,
"presence_penalty": self.presence_penalty,
}

View File

@@ -479,6 +479,9 @@ class Runtime:
parent.wait(timeout=5)
self.pid = None
def cache_prefix(self, prefix: str):
self.endpoint.cache_prefix(prefix)
def get_tokenizer(self):
return get_tokenizer(
self.server_args.tokenizer_path,

View File

@@ -113,15 +113,14 @@ def test_decode_json_regex():
s += ' "population": ' + sgl.gen(regex=REGEX_INT + ",") + "\n"
s += ' "area": ' + sgl.gen(regex=REGEX_INT + ",") + "\n"
s += ' "latitude": ' + sgl.gen(regex=REGEX_FLOAT + ",") + "\n"
s += ' "country": ' + sgl.gen(regex=REGEX_STRING + ",") + "\n"
s += ' "timezone": ' + sgl.gen(regex=REGEX_STRING) + "\n"
s += ' "country": ' + sgl.gen(regex=REGEX_STRING) + "\n"
s += "}"
ret = decode_json.run()
ret = decode_json.run(temperature=0.0)
try:
js_obj = json.loads(ret["json_output"])
except json.decoder.JSONDecodeError:
print(ret["json_output"])
print("JSONDecodeError", ret["json_output"])
raise
assert isinstance(js_obj["name"], str)
assert isinstance(js_obj["population"], int)
@@ -141,8 +140,12 @@ def test_decode_json():
s += ' "timezone": ' + sgl.gen(dtype=str) + "\n"
s += "}"
ret = decode_json.run()
js_obj = json.loads(ret["json_output"])
ret = decode_json.run(max_new_tokens=64)
try:
js_obj = json.loads(ret["json_output"])
except json.decoder.JSONDecodeError:
print("JSONDecodeError", ret["json_output"])
raise
assert isinstance(js_obj["name"], str)
assert isinstance(js_obj["population"], int)