"vscode:/vscode.git/clone" did not exist on "76e2727b5c630fdad3b054c717e7ae4bdd5e2d8e"
test_httpserver_decode.py 1.37 KB
Newer Older
Lianmin Zheng's avatar
Lianmin Zheng committed
1
"""
2
Usage:
Lianmin Zheng's avatar
Lianmin Zheng committed
3
python3 -m sglang.launch_server --model-path TinyLlama/TinyLlama-1.1B-Chat-v0.4 --port 30000
4
5
python3 test_httpserver_decode.py

Lianmin Zheng's avatar
Lianmin Zheng committed
6
7
8
9
10
Output:
The capital of France is Paris.\nThe capital of the United States is Washington, D.C.\nThe capital of Canada is Ottawa.\nThe capital of Japan is Tokyo
"""

import argparse
Liangsheng Yin's avatar
Liangsheng Yin committed
11
import json
Lianmin Zheng's avatar
Lianmin Zheng committed
12
13
14

import requests

15

Liangsheng Yin's avatar
Liangsheng Yin committed
16
def test_decode(url, return_logprob, top_logprobs_num, return_text):
Lianmin Zheng's avatar
Lianmin Zheng committed
17
18
19
20
21
22
23
24
    response = requests.post(
        url + "/generate",
        json={
            "text": "The capital of France is",
            "sampling_params": {
                "temperature": 0,
                "max_new_tokens": 32,
            },
25
            "stream": False,
Cody Yu's avatar
Cody Yu committed
26
            "return_logprob": return_logprob,
Liangsheng Yin's avatar
Liangsheng Yin committed
27
28
            "top_logprobs_num": top_logprobs_num,
            "return_text_in_logprobs": return_text,
Cody Yu's avatar
Cody Yu committed
29
            "logprob_start_len": 0,
Lianmin Zheng's avatar
Lianmin Zheng committed
30
31
        },
    )
Liangsheng Yin's avatar
Liangsheng Yin committed
32
33
    print(json.dumps(response.json()))
    print("=" * 100)
Cody Yu's avatar
Cody Yu committed
34

35

Cody Yu's avatar
Cody Yu committed
36
37
38
39
40
41
42
43
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--host", type=str, default="http://127.0.0.1")
    parser.add_argument("--port", type=int, default=30000)
    args = parser.parse_args()

    url = f"{args.host}:{args.port}"

Liangsheng Yin's avatar
Liangsheng Yin committed
44
45
46
47
48
    test_decode(url, False, 0, False)
    test_decode(url, True, 0, False)
    test_decode(url, True, 0, True)
    test_decode(url, True, 3, False)
    test_decode(url, True, 3, True)