Skip to content

Commit c65561b

Browse files
plusNew001zijinZhangYulongg
authored
add fd ci case (#3124)
* add ce case,test=model * change sci ce,test=model * add sci ce,test=model * add ce case,test=model * add ce,test=model * add ci case,test=model * add ci case,test=model * fix ci bug,test=model * add ci case,test=model * add ci case,test=model * fix ce bug,test=model * add ce case,test=model * fix ce bug,test=model * add ce case,test=model * add ce case ,test=model * add ce case,test=model * fix ce bug,test=model * fix ce bug,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * debug ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fixx ce bug,test=model * fix ce bug,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * change sci ci base,test=model * fix sci ci bug * add sci ci,test=model * add MT DCU env * add MT DCU env * add sci ci,test=model * change sci ci base,test=model * fix bug,test=model * fix bug,test=model * fix bug,test=model * fix bugs,test=model * fix bugs,test=model * fix sci ce bug,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * fix bugs,test=model * change sci ci,test=model * add modulus ce ,test=model * add modulus ce test,test=model * add modulus ce test,test=model * add modulus ce test,test=model * add modulus ce test,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * debug html,test=model * debug html,test=model * debug html,test=model * debug html,test=model * debug html,test=model * debug html,test=model * debug html,test=model * add timeout,test=model * add timeout,test=model * add timeout,test=model * add timeout,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * add cse case,test=model * add ce case,test=model * change sci case,test=model * change sci case,test=model * change sci ci case,test=model * debug bubble case,test=model * debug bubble case,test=model * debug bubble case,test=model * change sci case,test=model * add sci case,test=model * add sci case,test=model * add sci case,test=model * add sci case,test=model * add infer case,test=model * add infer case,test=model * change sci case,test=model * change sci case,test=model * add infer case,test=model * fix modulus ce bug,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * add ce case,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fix ce bug,test=model * change email,test=model * change email,test=model * change email,test=model * change email,test=model * change email,test=model * fix bug,test=model * fix bug,test=model * fix ce bug,test=model * fix ce bug,test=model * fix bug,test=model * fix bug,test=model * fix bug,test=model * debug ce,test=model * change email report name,test=model * change email report name,test=model * debug ce,test=model * debug ce,test=model * debug ce,test=model * debug ce,test=model * debug ce,test=model * debug ce,test=model * debug ce,test=model * add ci,test=model * fix ci bug,test=model * debug ce,test=model * debug ce,test=model * change email,test=model * change email,test=model * fix bug,test=model * change ce case,test=model * add PaddleX ci,test=model * fix sci bug,test=model * fix sci bug,test=model * fix paddlex ci bug,test=model * fix paddlesci bug,test=model * fix paddlesci bug,test=model * fix paddlesci bug,test=model * debug sci ce,test=model * delete Nonstationary_ad.yaml,test=model * delete Nonstationary_ad.yaml,test=model * delete Nonstationary_ad.yaml,test=model * fix sci ce bug,test=model * fix bugs,test=model * add PaddleX CE demo,test=model * debug ce,test=model * debug ce,test=model * debug ce,test=model * debug sci ce,test=model * Update test_comments.py,test=model * Update linux_env.sh * Update linux_env.sh * Update linux_env.sh * add npu case,test=model * add case,test=model * add case,test=model * add case,test=model * add sci case,test=model * fix bug,test=model * change modulus case,test=model * fix sci bug,test=model * add deepxde case,test=model * fix deepxde bug,test=model * fix deepxde bug,test=model * fix deepxde bug,test=model * fix deepxde bug,test=model * fix deepxde bug,test=model * fix deepxde bug,test=model * add sci ci case,test=model * add PaddlX tar,test=model * change sci ci base,test=model * Yōuhuà zhège suànfǎ * Update test_euler_beam.py * Update test_spinn.py * Update test_spinn.py * Update test_spinn.py * Update test_cylinder2d_unsteady_re100.py * Update test_cylinder2d_unsteady_re100.py * Create PaddleX_install_check.yml * Update PaddleX_install_check.yml * Update PaddleX_install_check.yml * Update PaddleX_install_check.yml * Create PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Create PaddleX_multimodal_pipeline_Run_Check.yml * Create PaddleX_ocr_pipeline_Run_Check.yml * Create PaddleX_speech_pipeline_Run_Check.yml * Update PaddleX_ocr_pipeline_Run_Check.yml * Update PaddleX_speech_pipeline_Run_Check.yml * Create PaddleX_ts_pipeline_Run_Check.yml * Create PaddleX_video_pipeline_Run_Check.yml * Update PaddleX_ocr_pipeline_Run_Check.yml * Update PaddleX_ocr_pipeline_Run_Check.yml * Update PaddleX_ocr_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Update PaddleX_cv_pipeline_Run_Check.yml * Create test.yml * Update test.yml * Update test.yml * Update PaddleX_install_check.yml * Update PaddleX_install_check.yml * add fd case * add fd ci case --------- Co-authored-by: zijin <[email protected]> Co-authored-by: ZhangYulongg <[email protected]>
1 parent 84743b5 commit c65561b

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

framework/fdtest/test_logprobs.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
from core import *
2+
import requests
3+
import json
4+
5+
# 测试非流式响应开启 logprobs 后,返回的 token 概率信息是否正确
6+
def test_unstream_logprobs():
7+
data = {
8+
"stream": False,
9+
"messages": [
10+
{"role": "system", "content": "You are a helpful assistant."},
11+
{"role": "user", "content": "牛顿的三大运动定律是什么?"},
12+
],
13+
"max_tokens": 3,
14+
}
15+
payload = build_request_payload(TEMPLATE, data)
16+
req = send_request(URL, payload)
17+
print(json.dumps(req.json(), indent=2, ensure_ascii=False))
18+
req = req.json()
19+
assert req["choices"][0]["message"]["content"] == "牛顿的"
20+
assert req["choices"][0]["logprobs"]["content"][0]["token"] == "牛顿"
21+
assert req["choices"][0]["logprobs"]["content"][0]["logprob"] == -0.031025361269712448
22+
assert req["choices"][0]["logprobs"]["content"][0]["top_logprobs"][0] == {
23+
"token": "牛顿",
24+
"logprob": -0.031025361269712448,
25+
"bytes": None,
26+
"top_logprobs": None
27+
}
28+
assert req["usage"] == {
29+
"prompt_tokens": 22,
30+
"total_tokens": 25,
31+
"completion_tokens": 3,
32+
"prompt_tokens_details": {"cached_tokens": 0}
33+
}
34+
35+
# 测试非流式响应关闭 logprobs 后,返回中是否不包含 logprobs 字段
36+
def test_unstream_unlogprobs():
37+
data = {
38+
"stream": False,
39+
"logprobs": False,
40+
"top_logprobs": None,
41+
"messages": [
42+
{"role": "system", "content": "You are a helpful assistant."},
43+
{"role": "user", "content": "牛顿的三大运动定律是什么?"},
44+
],
45+
"max_tokens": 3,
46+
}
47+
payload = build_request_payload(TEMPLATE, data)
48+
req = send_request(URL, payload)
49+
print(json.dumps(req.json(), indent=2, ensure_ascii=False))
50+
req = req.json()
51+
assert req["choices"][0]["message"]["content"] == "牛顿的"
52+
assert req["choices"][0]["logprobs"] is None
53+
assert req["usage"] == {
54+
"prompt_tokens": 22,
55+
"total_tokens": 25,
56+
"completion_tokens": 3,
57+
"prompt_tokens_details": {"cached_tokens": 0}
58+
}
59+
60+
# 测试流式响应开启 logprobs 后,返回的首个 token 的概率信息是否正确
61+
def test_stream_logprobs():
62+
data = {
63+
"stream": True,
64+
"messages": [
65+
{"role": "system", "content": "You are a helpful assistant."},
66+
{"role": "user", "content": "牛顿的三大运动定律是什么?"},
67+
],
68+
"max_tokens": 3,
69+
}
70+
payload = build_request_payload(TEMPLATE, data)
71+
req = send_request(URL, payload)
72+
result_dic = {}
73+
for line in req.iter_lines():
74+
if not line:
75+
continue
76+
decoded = line.decode("utf-8").removeprefix("data: ")
77+
if decoded == "[DONE]":
78+
break
79+
chunk = json.loads(decoded)
80+
content = chunk["choices"][0]["delta"].get("content")
81+
if content:
82+
result_dic = chunk
83+
print(json.dumps(result_dic, indent=2, ensure_ascii=False))
84+
break
85+
86+
assert result_dic["choices"][0]["delta"]["content"] == "牛顿"
87+
assert result_dic["choices"][0]["logprobs"]["content"][0]["token"] == "牛顿"
88+
assert result_dic["choices"][0]["logprobs"]["content"][0]["logprob"] == -0.031025361269712448
89+
assert result_dic["choices"][0]["logprobs"]["content"][0]["top_logprobs"][0] == {
90+
"token": "牛顿",
91+
"logprob": -0.031025361269712448
92+
}
93+
94+
# 测试流式响应关闭 logprobs 后,确认响应中不包含 logprobs 字段
95+
def test_stream_unlogprobs():
96+
data = {
97+
"stream": True,
98+
"logprobs": False,
99+
"top_logprobs": None,
100+
"messages": [
101+
{"role": "system", "content": "You are a helpful assistant."},
102+
{"role": "user", "content": "牛顿的三大运动定律是什么?"},
103+
],
104+
"max_tokens": 3,
105+
}
106+
payload = build_request_payload(TEMPLATE, data)
107+
req = send_request(URL, payload)
108+
result_dic = {}
109+
for line in req.iter_lines():
110+
if not line:
111+
continue
112+
decoded = line.decode("utf-8").removeprefix("data: ")
113+
if decoded == "[DONE]":
114+
break
115+
chunk = json.loads(decoded)
116+
content = chunk["choices"][0]["delta"].get("content")
117+
if content:
118+
result_dic = chunk
119+
print(json.dumps(result_dic, indent=2, ensure_ascii=False))
120+
break
121+
122+
assert result_dic["choices"][0]["delta"]["content"] == "牛顿"
123+
assert result_dic["choices"][0]["logprobs"] is None
124+
125+
# 主程序入口,运行测试
126+
if __name__ == '__main__':
127+
test_unstream_logprobs()
128+
test_unstream_unlogprobs()
129+
test_stream_logprobs()
130+
test_stream_unlogprobs()

framework/fdtest/test_stream.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from core import *
2+
import requests
3+
import json
4+
5+
def test_stream_and_not_stream():
6+
# 测试接口在 stream 模式和非 stream 模式下返回的内容是否一致
7+
8+
# 发送 stream=True 的请求,解析流式响应
9+
data = {
10+
"stream": True,
11+
"messages": [
12+
{"role": "system", "content": "You are a helpful assistant."},
13+
{"role": "user", "content": "牛顿的三大运动定律是什么?"},
14+
],
15+
"max_tokens": 100,
16+
}
17+
payload = build_request_payload(TEMPLATE, data)
18+
req = send_request(URL, payload)
19+
20+
# 解析流式响应内容
21+
resp_chunks = []
22+
for line in req.iter_lines():
23+
if line:
24+
decoded = line.decode("utf-8")
25+
if decoded.startswith("data: "):
26+
decoded = decoded[len("data: "):]
27+
if decoded == "[DONE]":
28+
break
29+
resp_chunks.append(json.loads(decoded))
30+
31+
# 拼接最终生成内容
32+
final_content = "".join([
33+
chunk["choices"][0]["delta"]["content"]
34+
for chunk in resp_chunks
35+
if "choices" in chunk and "delta" in chunk["choices"][0] and "content" in chunk["choices"][0]["delta"]
36+
])
37+
print(final_content)
38+
39+
# 发送 stream=False 的请求,获取完整响应
40+
data["stream"] = False
41+
payload = build_request_payload(TEMPLATE, data)
42+
req = send_request(URL, payload)
43+
print(json.dumps(req.json(), indent=2, ensure_ascii=False))
44+
req = req.json()
45+
46+
# 对比 stream 与非 stream 响应内容是否一致
47+
assert final_content == req["choices"][0]["message"]["content"]
48+
49+
if __name__ == '__main__':
50+
test_stream_and_not_stream() # 运行测试函数

0 commit comments

Comments
 (0)