luclima commited on
Commit
4e9d621
·
verified ·
1 Parent(s): 61b35cc

Upload folder using huggingface_hub (part 48)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. asian_ai/performance/SGLang/test/registered/ascend/basic_function/quant/test_npu_gptq_moe.py +83 -0
  2. asian_ai/performance/SGLang/test/registered/ascend/basic_function/quant/test_npu_w4a4_quantization.py +82 -0
  3. asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_mla_fia_w8a8int8.py +83 -0
  4. asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_mla_w8a8int8.py +81 -0
  5. asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_tp1_bf16.py +78 -0
  6. asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_tp2_bf16.py +80 -0
  7. asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_tp2_fia_bf16.py +83 -0
  8. asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_tp4_bf16.py +83 -0
  9. asian_ai/performance/SGLang/test/registered/ascend/basic_function/speculative_inference/test_npu_eagle3.py +62 -0
  10. asian_ai/performance/SGLang/test/registered/ascend/embedding_models/test_npu_bge_large_en_v1_5.py +112 -0
  11. asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_api.py +735 -0
  12. asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_api_abort_request.py +78 -0
  13. asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_api_encode.py +134 -0
  14. asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_enable_thinking.py +195 -0
  15. asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_matched_stop.py +163 -0
  16. asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_openai_function_calling.py +940 -0
  17. asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_openai_server_ignore_eos.py +101 -0
  18. asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_penalty.py +111 -0
  19. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_ascend_dbrx_instruct.py +26 -0
  20. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_ascend_minimax_m2.py +44 -0
  21. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_ascend_trinity_mini.py +47 -0
  22. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_afm_4_5b.py +23 -0
  23. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_baichuan2_13b_chat.py +37 -0
  24. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_c4ai_command_r_v01.py +40 -0
  25. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_chatglm2_6b.py +33 -0
  26. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_deepseek_v3_2_exp_w8a8.py +37 -0
  27. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_exaone_3.py +34 -0
  28. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_gemma_3_4b_it_llm.py +38 -0
  29. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_glm4_9b_chat.py +27 -0
  30. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_granite_3_0_3b_a800m.py +25 -0
  31. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_granite_3_1_8b.py +23 -0
  32. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_grok_2.py +33 -0
  33. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_internlm2_7b.py +29 -0
  34. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_ling_lite.py +33 -0
  35. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_llama4_scount_17b_16e.py +40 -0
  36. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_llama_2_7b.py +23 -0
  37. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_llama_2_7b_communications_compression.py +37 -0
  38. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_mimo_7b_rl.py +23 -0
  39. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_minicpm3_4b.py +37 -0
  40. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_mistral_7b.py +23 -0
  41. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_persimmon_8b_chat.py +29 -0
  42. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_phi_4_multimodal_llm.py +23 -0
  43. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_0_6b.py +30 -0
  44. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_1_7b_gptq_int8.py +32 -0
  45. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_235b_a22b_w8a8.py +36 -0
  46. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_30b.py +39 -0
  47. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_30b_attn_cp.py +55 -0
  48. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_30b_w4a4.py +37 -0
  49. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_32b.py +37 -0
  50. asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_8b_communications_quantization.py +37 -0
asian_ai/performance/SGLang/test/registered/ascend/basic_function/quant/test_npu_gptq_moe.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import unittest
3
+ from types import SimpleNamespace
4
+ from urllib.parse import urlparse
5
+
6
+ from sglang.srt.utils import kill_process_tree
7
+ from sglang.test.ascend.test_ascend_utils import (
8
+ QWEN3_30B_A3B_GPTQ_2507_INT4_WEIGHTS_PATH,
9
+ )
10
+ from sglang.test.ci.ci_register import register_npu_ci
11
+ from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
12
+ from sglang.test.test_utils import (
13
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
14
+ DEFAULT_URL_FOR_TEST,
15
+ CustomTestCase,
16
+ popen_launch_server,
17
+ )
18
+
19
+ register_npu_ci(est_time=400, suite="stage-b-test-1-npu-a2", nightly=False)
20
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
21
+
22
+ logger = logging.getLogger(__name__)
23
+
24
+ TEST_MODEL_MATRIX = {
25
+ QWEN3_30B_A3B_GPTQ_2507_INT4_WEIGHTS_PATH: {
26
+ "accuracy": 0.85,
27
+ },
28
+ }
29
+
30
+
31
+ class TestAscendGPTQMoEInt4(CustomTestCase):
32
+
33
+ @classmethod
34
+ def setUpClass(cls):
35
+ cls.models = TEST_MODEL_MATRIX.keys()
36
+ cls.base_url = DEFAULT_URL_FOR_TEST
37
+ cls.url = urlparse(DEFAULT_URL_FOR_TEST)
38
+ cls.common_args = [
39
+ "--trust-remote-code",
40
+ "--mem-fraction-static",
41
+ 0.8,
42
+ "--attention-backend",
43
+ "ascend",
44
+ "--quantization",
45
+ "gptq",
46
+ ]
47
+
48
+ def test_a_gsm8k(self):
49
+ for model in self.models:
50
+ with self.subTest(model=model):
51
+ logger.info(f"##=== Testing accuracy: {model} ===##")
52
+
53
+ process = popen_launch_server(
54
+ model,
55
+ self.base_url,
56
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
57
+ other_args=[
58
+ *self.common_args,
59
+ ],
60
+ )
61
+
62
+ try:
63
+ args = SimpleNamespace(
64
+ num_shots=5,
65
+ data_path=None,
66
+ num_questions=1319,
67
+ max_new_tokens=512,
68
+ parallel=128,
69
+ host=f"http://{self.url.hostname}",
70
+ port=int(self.url.port),
71
+ )
72
+
73
+ metrics = run_eval_few_shot_gsm8k(args)
74
+ self.assertGreaterEqual(
75
+ metrics["accuracy"],
76
+ TEST_MODEL_MATRIX[model]["accuracy"],
77
+ )
78
+ finally:
79
+ kill_process_tree(process.pid)
80
+
81
+
82
+ if __name__ == "__main__":
83
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/basic_function/quant/test_npu_w4a4_quantization.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Usage:
3
+ python3 -m unittest test_ascend_w4a4_quantization.TestAscendW4A4.test_gsm8k
4
+ """
5
+
6
+ import os
7
+ import time
8
+ import unittest
9
+
10
+ import requests
11
+
12
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
13
+ from sglang.test.ascend.test_ascend_utils import (
14
+ ECO_TECH_QWEN3_32B_W4A4_LAOS_WEIGHTS_PATH,
15
+ )
16
+ from sglang.test.ci.ci_register import register_npu_ci
17
+ from sglang.test.test_utils import CustomTestCase, is_in_ci, write_github_step_summary
18
+
19
+ register_npu_ci(est_time=400, suite="stage-b-test-4-npu-a3", nightly=False)
20
+ register_npu_ci(est_time=400, suite="nightly-4-npu-a3", nightly=True)
21
+
22
+
23
+ class TestAscendW4A4(GSM8KAscendMixin, CustomTestCase):
24
+
25
+ model = ECO_TECH_QWEN3_32B_W4A4_LAOS_WEIGHTS_PATH
26
+ other_args = [
27
+ "--trust-remote-code",
28
+ "--device",
29
+ "npu",
30
+ "--attention-backend",
31
+ "ascend",
32
+ "--tp-size",
33
+ "4",
34
+ "--mem-fraction-static",
35
+ "0.8",
36
+ "--cuda-graph-bs",
37
+ "64",
38
+ "--disable-radix-cache",
39
+ ]
40
+
41
+ env = {
42
+ **os.environ,
43
+ }
44
+
45
+ # GSM8K Configs
46
+ accuracy = 0.80 # GSM8K accuracy ≥0.80
47
+ num_questions = 1319
48
+ gsm8k_num_shots = 5
49
+ output_throughput = 1000 # GSM8K output throughput ≥1000 tokens/s
50
+ gsm8k_parallel = 64
51
+
52
+ def run_decode(self, max_new_tokens):
53
+ response = requests.post(
54
+ self.base_url + "/generate",
55
+ json={
56
+ "text": "The capital of France is",
57
+ "sampling_params": {
58
+ "temperature": 0,
59
+ "max_new_tokens": max_new_tokens,
60
+ },
61
+ "ignore_eos": True,
62
+ },
63
+ )
64
+ return response.json()
65
+
66
+ def test_throughput(self):
67
+ max_tokens = 256
68
+
69
+ tic = time.perf_counter()
70
+ res = self.run_decode(max_tokens)
71
+ tok = time.perf_counter()
72
+ throughput = max_tokens / (tok - tic)
73
+ summary = res["text"] + f"\nThroughput: {throughput} tokens/s"
74
+ print(summary)
75
+
76
+ if is_in_ci():
77
+ write_github_step_summary(summary + "\nThroughput threshold: 35 tokens/s")
78
+ self.assertGreaterEqual(throughput, 35)
79
+
80
+
81
+ if __name__ == "__main__":
82
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_mla_fia_w8a8int8.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import unittest
3
+ from types import SimpleNamespace
4
+ from urllib.parse import urlparse
5
+
6
+ from sglang.srt.utils import kill_process_tree
7
+ from sglang.test.ci.ci_register import register_npu_ci
8
+ from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
9
+ from sglang.test.test_utils import (
10
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
11
+ DEFAULT_URL_FOR_TEST,
12
+ CustomTestCase,
13
+ popen_launch_server,
14
+ )
15
+
16
+ register_npu_ci(est_time=400, suite="stage-b-test-2-npu-a2", nightly=False)
17
+ register_npu_ci(est_time=400, suite="nightly-2-npu-a3", nightly=True)
18
+
19
+ TEST_MODEL_MATRIX = {
20
+ "/root/.cache/modelscope/hub/models/vllm-ascend/DeepSeek-V2-Lite-W8A8": {
21
+ "accuracy": 0.34,
22
+ "latency": 1000,
23
+ "output_throughput": 6,
24
+ },
25
+ }
26
+
27
+
28
+ class TestAscendMlaW8A8Int8(CustomTestCase):
29
+
30
+ @classmethod
31
+ def setUpClass(cls):
32
+ cls.models = TEST_MODEL_MATRIX.keys()
33
+ cls.base_url = DEFAULT_URL_FOR_TEST
34
+ cls.url = urlparse(DEFAULT_URL_FOR_TEST)
35
+ cls.common_args = [
36
+ "--trust-remote-code",
37
+ "--disable-cuda-graph",
38
+ "--mem-fraction-static",
39
+ 0.8,
40
+ "--attention-backend",
41
+ "ascend",
42
+ "--tp-size",
43
+ 2,
44
+ "--disable-radix-cache",
45
+ ]
46
+
47
+ def test_a_gsm8k(self):
48
+ os.environ["ASCEND_USE_FIA"] = "true"
49
+ for model in self.models:
50
+ with self.subTest(model=model):
51
+ print(f"##=== Testing accuracy: {model} ===##")
52
+
53
+ process = popen_launch_server(
54
+ model,
55
+ self.base_url,
56
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
57
+ other_args=[
58
+ *self.common_args,
59
+ ],
60
+ )
61
+
62
+ try:
63
+ args = SimpleNamespace(
64
+ num_shots=5,
65
+ data_path=None,
66
+ num_questions=1319,
67
+ max_new_tokens=512,
68
+ parallel=128,
69
+ host=f"http://{self.url.hostname}",
70
+ port=int(self.url.port),
71
+ )
72
+
73
+ metrics = run_eval_few_shot_gsm8k(args)
74
+ self.assertGreaterEqual(
75
+ metrics["accuracy"],
76
+ TEST_MODEL_MATRIX[model]["accuracy"],
77
+ )
78
+ finally:
79
+ kill_process_tree(process.pid)
80
+
81
+
82
+ if __name__ == "__main__":
83
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_mla_w8a8int8.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from types import SimpleNamespace
3
+ from urllib.parse import urlparse
4
+
5
+ from sglang.srt.utils import kill_process_tree
6
+ from sglang.test.ci.ci_register import register_npu_ci
7
+ from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
8
+ from sglang.test.test_utils import (
9
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
10
+ DEFAULT_URL_FOR_TEST,
11
+ CustomTestCase,
12
+ popen_launch_server,
13
+ )
14
+
15
+ register_npu_ci(est_time=400, suite="stage-b-test-4-npu-a3", nightly=False)
16
+ register_npu_ci(est_time=400, suite="nightly-4-npu-a3", nightly=True)
17
+
18
+ TEST_MODEL_MATRIX = {
19
+ "/root/.cache/modelscope/hub/models/vllm-ascend/DeepSeek-V2-Lite-W8A8": {
20
+ "accuracy": 0.34,
21
+ "latency": 1000,
22
+ "output_throughput": 6,
23
+ },
24
+ }
25
+
26
+
27
+ class TestAscendMlaW8A8Int8(CustomTestCase):
28
+
29
+ @classmethod
30
+ def setUpClass(cls):
31
+ cls.models = TEST_MODEL_MATRIX.keys()
32
+ cls.base_url = DEFAULT_URL_FOR_TEST
33
+ cls.url = urlparse(DEFAULT_URL_FOR_TEST)
34
+ cls.common_args = [
35
+ "--trust-remote-code",
36
+ "--disable-cuda-graph",
37
+ "--mem-fraction-static",
38
+ 0.8,
39
+ "--attention-backend",
40
+ "ascend",
41
+ "--tp-size",
42
+ 4,
43
+ "--disable-radix-cache",
44
+ ]
45
+
46
+ def test_a_gsm8k(self):
47
+ for model in self.models:
48
+ with self.subTest(model=model):
49
+ print(f"##=== Testing accuracy: {model} ===##")
50
+
51
+ process = popen_launch_server(
52
+ model,
53
+ self.base_url,
54
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
55
+ other_args=[
56
+ *self.common_args,
57
+ ],
58
+ )
59
+
60
+ try:
61
+ args = SimpleNamespace(
62
+ num_shots=5,
63
+ data_path=None,
64
+ num_questions=1319,
65
+ max_new_tokens=512,
66
+ parallel=128,
67
+ host=f"http://{self.url.hostname}",
68
+ port=int(self.url.port),
69
+ )
70
+
71
+ metrics = run_eval_few_shot_gsm8k(args)
72
+ self.assertGreaterEqual(
73
+ metrics["accuracy"],
74
+ TEST_MODEL_MATRIX[model]["accuracy"],
75
+ )
76
+ finally:
77
+ kill_process_tree(process.pid)
78
+
79
+
80
+ if __name__ == "__main__":
81
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_tp1_bf16.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from types import SimpleNamespace
3
+ from urllib.parse import urlparse
4
+
5
+ from sglang.srt.utils import kill_process_tree
6
+ from sglang.test.ci.ci_register import register_npu_ci
7
+ from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
8
+ from sglang.test.test_utils import (
9
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
10
+ DEFAULT_URL_FOR_TEST,
11
+ CustomTestCase,
12
+ popen_launch_server,
13
+ )
14
+
15
+ register_npu_ci(est_time=400, suite="stage-b-test-1-npu-a2", nightly=False)
16
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
17
+
18
+ TEST_MODEL_MATRIX = {
19
+ "/root/.cache/modelscope/hub/models/Qwen/Qwen2.5-7B-Instruct": {
20
+ "accuracy": 0.84,
21
+ "latency": 150,
22
+ "output_throughput": 30,
23
+ },
24
+ }
25
+
26
+
27
+ class TestAscendTp1Bf16(CustomTestCase):
28
+
29
+ @classmethod
30
+ def setUpClass(cls):
31
+ cls.models = TEST_MODEL_MATRIX.keys()
32
+ cls.base_url = DEFAULT_URL_FOR_TEST
33
+ cls.url = urlparse(DEFAULT_URL_FOR_TEST)
34
+ cls.common_args = [
35
+ "--trust-remote-code",
36
+ "--disable-cuda-graph",
37
+ "--mem-fraction-static",
38
+ 0.8,
39
+ "--attention-backend",
40
+ "ascend",
41
+ ]
42
+
43
+ def test_a_gsm8k(self):
44
+ for model in self.models:
45
+ with self.subTest(model=model):
46
+ print(f"##=== Testing accuracy: {model} ===##")
47
+
48
+ process = popen_launch_server(
49
+ model,
50
+ self.base_url,
51
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
52
+ other_args=[
53
+ *self.common_args,
54
+ ],
55
+ )
56
+
57
+ try:
58
+ args = SimpleNamespace(
59
+ num_shots=5,
60
+ data_path=None,
61
+ num_questions=1319,
62
+ max_new_tokens=512,
63
+ parallel=128,
64
+ host=f"http://{self.url.hostname}",
65
+ port=int(self.url.port),
66
+ )
67
+
68
+ metrics = run_eval_few_shot_gsm8k(args)
69
+ self.assertGreaterEqual(
70
+ metrics["accuracy"],
71
+ TEST_MODEL_MATRIX[model]["accuracy"],
72
+ )
73
+ finally:
74
+ kill_process_tree(process.pid)
75
+
76
+
77
+ if __name__ == "__main__":
78
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_tp2_bf16.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from types import SimpleNamespace
3
+ from urllib.parse import urlparse
4
+
5
+ from sglang.srt.utils import kill_process_tree
6
+ from sglang.test.ci.ci_register import register_npu_ci
7
+ from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
8
+ from sglang.test.test_utils import (
9
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
10
+ DEFAULT_URL_FOR_TEST,
11
+ CustomTestCase,
12
+ popen_launch_server,
13
+ )
14
+
15
+ register_npu_ci(est_time=400, suite="stage-b-test-2-npu-a2", nightly=False)
16
+ register_npu_ci(est_time=400, suite="nightly-2-npu-a3", nightly=True)
17
+
18
+ TEST_MODEL_MATRIX = {
19
+ "/root/.cache/modelscope/hub/models/Qwen/Qwen2.5-7B-Instruct": {
20
+ "accuracy": 0.85,
21
+ "latency": 180,
22
+ "output_throughput": 20,
23
+ },
24
+ }
25
+
26
+
27
+ class TestAscendTp2Bf16(CustomTestCase):
28
+
29
+ @classmethod
30
+ def setUpClass(cls):
31
+ cls.models = TEST_MODEL_MATRIX.keys()
32
+ cls.base_url = DEFAULT_URL_FOR_TEST
33
+ cls.url = urlparse(DEFAULT_URL_FOR_TEST)
34
+ cls.common_args = [
35
+ "--trust-remote-code",
36
+ "--disable-cuda-graph",
37
+ "--mem-fraction-static",
38
+ 0.8,
39
+ "--attention-backend",
40
+ "ascend",
41
+ "--tp-size",
42
+ 2,
43
+ ]
44
+
45
+ def test_a_gsm8k(self):
46
+ for model in self.models:
47
+ with self.subTest(model=model):
48
+ print(f"##=== Testing accuracy: {model} ===##")
49
+
50
+ process = popen_launch_server(
51
+ model,
52
+ self.base_url,
53
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
54
+ other_args=[
55
+ *self.common_args,
56
+ ],
57
+ )
58
+
59
+ try:
60
+ args = SimpleNamespace(
61
+ num_shots=5,
62
+ data_path=None,
63
+ num_questions=1319,
64
+ max_new_tokens=512,
65
+ parallel=128,
66
+ host=f"http://{self.url.hostname}",
67
+ port=int(self.url.port),
68
+ )
69
+
70
+ metrics = run_eval_few_shot_gsm8k(args)
71
+ self.assertGreaterEqual(
72
+ metrics["accuracy"],
73
+ TEST_MODEL_MATRIX[model]["accuracy"],
74
+ )
75
+ finally:
76
+ kill_process_tree(process.pid)
77
+
78
+
79
+ if __name__ == "__main__":
80
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_tp2_fia_bf16.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import unittest
3
+ from types import SimpleNamespace
4
+ from urllib.parse import urlparse
5
+
6
+ from sglang.srt.utils import kill_process_tree
7
+ from sglang.test.ci.ci_register import register_npu_ci
8
+ from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
9
+ from sglang.test.test_utils import (
10
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
11
+ DEFAULT_URL_FOR_TEST,
12
+ CustomTestCase,
13
+ popen_launch_server,
14
+ )
15
+
16
+ register_npu_ci(est_time=400, suite="stage-b-test-2-npu-a2", nightly=False)
17
+ register_npu_ci(est_time=400, suite="nightly-2-npu-a3", nightly=True)
18
+
19
+ TEST_MODEL_MATRIX = {
20
+ "/root/.cache/modelscope/hub/models/Qwen/Qwen2.5-7B-Instruct": {
21
+ "accuracy": 0.85,
22
+ "latency": 180,
23
+ "output_throughput": 20,
24
+ },
25
+ }
26
+
27
+
28
+ class TestAscendTp2Bf16(CustomTestCase):
29
+
30
+ @classmethod
31
+ def setUpClass(cls):
32
+ cls.models = TEST_MODEL_MATRIX.keys()
33
+ cls.base_url = DEFAULT_URL_FOR_TEST
34
+ cls.url = urlparse(DEFAULT_URL_FOR_TEST)
35
+ cls.common_args = [
36
+ "--trust-remote-code",
37
+ "--disable-cuda-graph",
38
+ "--mem-fraction-static",
39
+ 0.8,
40
+ "--attention-backend",
41
+ "ascend",
42
+ "--tp-size",
43
+ 2,
44
+ "--disable-radix-cache",
45
+ ]
46
+
47
+ def test_a_gsm8k(self):
48
+ os.environ["ASCEND_USE_FIA"] = "true"
49
+ for model in self.models:
50
+ with self.subTest(model=model):
51
+ print(f"##=== Testing accuracy: {model} ===##")
52
+
53
+ process = popen_launch_server(
54
+ model,
55
+ self.base_url,
56
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
57
+ other_args=[
58
+ *self.common_args,
59
+ ],
60
+ )
61
+
62
+ try:
63
+ args = SimpleNamespace(
64
+ num_shots=5,
65
+ data_path=None,
66
+ num_questions=1319,
67
+ max_new_tokens=512,
68
+ parallel=128,
69
+ host=f"http://{self.url.hostname}",
70
+ port=int(self.url.port),
71
+ )
72
+
73
+ metrics = run_eval_few_shot_gsm8k(args)
74
+ self.assertGreaterEqual(
75
+ metrics["accuracy"],
76
+ TEST_MODEL_MATRIX[model]["accuracy"],
77
+ )
78
+ finally:
79
+ kill_process_tree(process.pid)
80
+
81
+
82
+ if __name__ == "__main__":
83
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/basic_function/runtime_opts/test_npu_tp4_bf16.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from types import SimpleNamespace
3
+ from urllib.parse import urlparse
4
+
5
+ from sglang.srt.utils import kill_process_tree
6
+ from sglang.test.ci.ci_register import register_npu_ci
7
+ from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
8
+ from sglang.test.test_utils import (
9
+ DEFAULT_URL_FOR_TEST,
10
+ CustomTestCase,
11
+ popen_launch_server,
12
+ )
13
+
14
+ register_npu_ci(est_time=400, suite="stage-b-test-4-npu-a3", nightly=False)
15
+ register_npu_ci(est_time=400, suite="nightly-4-npu-a3", nightly=True)
16
+
17
+ TEST_MODEL_MATRIX = {
18
+ "Qwen/Qwen3-30B-A3B-Instruct-2507": {
19
+ "accuracy": 0.90,
20
+ "latency": 180,
21
+ "output_throughput": 20,
22
+ },
23
+ }
24
+
25
+
26
+ class TestAscendTp4Bf16(CustomTestCase):
27
+
28
+ @classmethod
29
+ def setUpClass(cls):
30
+ cls.models = TEST_MODEL_MATRIX.keys()
31
+ cls.base_url = DEFAULT_URL_FOR_TEST
32
+ cls.url = urlparse(DEFAULT_URL_FOR_TEST)
33
+ cls.common_args = [
34
+ "--trust-remote-code",
35
+ "--mem-fraction-static",
36
+ 0.7,
37
+ "--max-running-requests",
38
+ 32,
39
+ "--attention-backend",
40
+ "ascend",
41
+ "--disable-radix-cache",
42
+ "--cuda-graph-max-bs-decode",
43
+ 32,
44
+ "--tp-size",
45
+ 4,
46
+ ]
47
+
48
+ def test_a_gsm8k(self):
49
+ for model in self.models:
50
+ with self.subTest(model=model):
51
+ print(f"##=== Testing accuracy: {model} ===##")
52
+
53
+ process = popen_launch_server(
54
+ model,
55
+ self.base_url,
56
+ timeout=1800,
57
+ other_args=[
58
+ *self.common_args,
59
+ ],
60
+ )
61
+
62
+ try:
63
+ args = SimpleNamespace(
64
+ num_shots=5,
65
+ data_path=None,
66
+ num_questions=1319,
67
+ max_new_tokens=512,
68
+ parallel=128,
69
+ host=f"http://{self.url.hostname}",
70
+ port=int(self.url.port),
71
+ )
72
+
73
+ metrics = run_eval_few_shot_gsm8k(args)
74
+ self.assertGreaterEqual(
75
+ metrics["accuracy"],
76
+ TEST_MODEL_MATRIX[model]["accuracy"],
77
+ )
78
+ finally:
79
+ kill_process_tree(process.pid)
80
+
81
+
82
+ if __name__ == "__main__":
83
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/basic_function/speculative_inference/test_npu_eagle3.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import unittest
3
+
4
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
5
+ from sglang.test.ascend.test_ascend_utils import (
6
+ QWEN3_8B_EAGLE3_WEIGHTS_PATH,
7
+ QWEN3_8B_WEIGHTS_PATH,
8
+ )
9
+ from sglang.test.ci.ci_register import register_npu_ci
10
+ from sglang.test.test_utils import CustomTestCase
11
+
12
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
13
+
14
+
15
+ class TestNpuEagle3(GSM8KAscendMixin, CustomTestCase):
16
+ """Testcase: Verify GSM8K inference accuracy ≥0.81 for model with specified EAGLE3 speculative inference parameters.
17
+
18
+ [Test Category] Speculative Decoding
19
+ [Test Target] --speculative-draft-model-quantization; --speculative-algorithm; --speculative-draft-model-path; --speculative-num-steps; --speculative-eagle-topk; --speculative-num-draft-tokens; --speculative-attention-mode
20
+ """
21
+
22
+ model = QWEN3_8B_WEIGHTS_PATH
23
+ timeout_for_server_launch = 1500
24
+ other_args = [
25
+ "--trust-remote-code",
26
+ "--attention-backend",
27
+ "ascend",
28
+ "--disable-radix-cache",
29
+ "--speculative-draft-model-quantization",
30
+ "unquant",
31
+ "--speculative-algorithm",
32
+ "EAGLE3",
33
+ "--speculative-draft-model-path",
34
+ QWEN3_8B_EAGLE3_WEIGHTS_PATH,
35
+ "--speculative-num-steps",
36
+ "4",
37
+ "--speculative-eagle-topk",
38
+ "1",
39
+ "--speculative-num-draft-tokens",
40
+ "5",
41
+ "--speculative-attention-mode",
42
+ "decode",
43
+ "--tp-size",
44
+ "1",
45
+ "--mem-fraction-static",
46
+ "0.7",
47
+ "--disable-cuda-graph",
48
+ "--dtype",
49
+ "bfloat16",
50
+ ]
51
+
52
+ env = {
53
+ **os.environ,
54
+ "SGLANG_ENABLE_OVERLAP_PLAN_STREAM": "1",
55
+ }
56
+
57
+ accuracy = 0.81
58
+ num_questions = 1319
59
+
60
+
61
+ if __name__ == "__main__":
62
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/embedding_models/test_npu_bge_large_en_v1_5.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import multiprocessing as mp
2
+ import unittest
3
+ from typing import Optional
4
+
5
+ import torch
6
+ from transformers import AutoConfig, AutoTokenizer
7
+
8
+ from sglang.test.ci.ci_register import register_npu_ci
9
+ from sglang.test.runners import HFRunner, SRTRunner
10
+ from sglang.test.test_utils import CustomTestCase, get_similarities
11
+
12
+ register_npu_ci(
13
+ est_time=400,
14
+ suite="full-1-npu-a3",
15
+ nightly=True,
16
+ disabled="embeddings are not all close",
17
+ )
18
+
19
+ DEFAULT_PROMPTS = [
20
+ "The capital of the United Kingdom is",
21
+ "Today is a sunny day and I like",
22
+ "AI is a field of computer science focused on",
23
+ ]
24
+
25
+ MODELS = [
26
+ ("/root/.cache/modelscope/hub/models/bge-large-en-v1.5", 1, 1e-5),
27
+ ]
28
+ TORCH_DTYPES = [torch.float16]
29
+
30
+
31
+ class TestEmbeddingModels(CustomTestCase):
32
+
33
+ @classmethod
34
+ def setUpClass(cls):
35
+ mp.set_start_method("spawn", force=True)
36
+
37
+ def _truncate_prompts(self, prompts, model_path):
38
+ config = AutoConfig.from_pretrained(model_path)
39
+ max_length = getattr(config, "max_position_embeddings", 2048)
40
+
41
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
42
+
43
+ truncated_prompts = []
44
+ for prompt in prompts:
45
+ tokens = tokenizer(prompt, return_tensors="pt", truncation=False)
46
+ if len(tokens.input_ids[0]) > max_length:
47
+ truncated_text = tokenizer.decode(
48
+ tokens.input_ids[0][: max_length - 1], skip_special_tokens=True
49
+ )
50
+ truncated_prompts.append(truncated_text)
51
+ else:
52
+ truncated_prompts.append(prompt)
53
+ return truncated_prompts
54
+
55
+ def assert_close_prefill_logits(
56
+ self,
57
+ prompts,
58
+ model_path,
59
+ tp_size,
60
+ torch_dtype,
61
+ prefill_tolerance,
62
+ matryoshka_dim: Optional[int] = None,
63
+ ) -> None:
64
+ truncated_prompts = self._truncate_prompts(prompts, model_path)
65
+
66
+ with HFRunner(
67
+ model_path,
68
+ torch_dtype=torch_dtype,
69
+ model_type="embedding",
70
+ matryoshka_dim=matryoshka_dim,
71
+ ) as hf_runner:
72
+ hf_outputs = hf_runner.forward(truncated_prompts)
73
+
74
+ attention_backend = "ascend"
75
+ with SRTRunner(
76
+ model_path,
77
+ tp_size=tp_size,
78
+ torch_dtype=torch_dtype,
79
+ model_type="embedding",
80
+ attention_backend=attention_backend,
81
+ json_model_override_args=(
82
+ {"matryoshka_dimensions": [matryoshka_dim]} if matryoshka_dim else None
83
+ ),
84
+ ) as srt_runner:
85
+ srt_outputs = srt_runner.forward(
86
+ truncated_prompts, dimensions=matryoshka_dim
87
+ )
88
+
89
+ for i in range(len(prompts)):
90
+ hf_logits = torch.Tensor(hf_outputs.embed_logits[i])
91
+ srt_logits = torch.Tensor(srt_outputs.embed_logits[i])
92
+
93
+ similarity = torch.tensor(get_similarities(hf_logits, srt_logits))
94
+ print("similarity diff", abs(similarity - 1))
95
+
96
+ if len(prompts[i]) <= 1000:
97
+ assert torch.all(
98
+ abs(similarity - 1) < prefill_tolerance
99
+ ), "embeddings are not all close"
100
+
101
+ def test_prefill_logits(self):
102
+ models_to_test = MODELS
103
+
104
+ for model, tp_size, prefill_tolerance in models_to_test:
105
+ for torch_dtype in TORCH_DTYPES:
106
+ self.assert_close_prefill_logits(
107
+ DEFAULT_PROMPTS, model, tp_size, torch_dtype, prefill_tolerance
108
+ )
109
+
110
+
111
+ if __name__ == "__main__":
112
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_api.py ADDED
@@ -0,0 +1,735 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import logging
3
+ import os
4
+ import shutil
5
+ import unittest
6
+
7
+ import requests
8
+ from transformers import AutoTokenizer
9
+
10
+ from sglang.srt.environ import envs
11
+ from sglang.srt.utils import kill_process_tree
12
+ from sglang.test.ascend.test_ascend_utils import LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
13
+ from sglang.test.ci.ci_register import register_npu_ci
14
+ from sglang.test.test_utils import (
15
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
16
+ DEFAULT_URL_FOR_TEST,
17
+ CustomTestCase,
18
+ popen_launch_server,
19
+ )
20
+
21
+ # Global variables: Manage server process and initialization status
22
+ GLOBAL_SERVER_PROCESS = None
23
+ GLOBAL_SERVER_INITIALIZED = False
24
+ OUTPUT_DIR = "./profiler_dir"
25
+
26
+ register_npu_ci(est_time=1600, suite="nightly-npu-a3-merged", nightly=True)
27
+
28
+
29
+ class TestNpuApi(CustomTestCase):
30
+ """Testcase: Verify that the basic functions of the API interfaces work properly and the returned parameters are consistent with the configurations.
31
+
32
+ [Test Category] Interface
33
+ [Test Target] /health; /health_generate; /ping; /model_info; /server_info; /v1/loads; /v1/models; /v1/models/{model:path}; /generate
34
+ """
35
+
36
+ @classmethod
37
+ def setUpClass(cls):
38
+ global GLOBAL_SERVER_PROCESS, GLOBAL_SERVER_INITIALIZED
39
+ # Start server only if not initialized
40
+ if not GLOBAL_SERVER_INITIALIZED:
41
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
42
+ other_args = [
43
+ "--attention-backend",
44
+ "ascend",
45
+ "--enable-return-hidden-states",
46
+ ]
47
+ # Start server and save to global variable
48
+ GLOBAL_SERVER_PROCESS = popen_launch_server(
49
+ cls.model,
50
+ DEFAULT_URL_FOR_TEST,
51
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
52
+ other_args=other_args,
53
+ )
54
+ GLOBAL_SERVER_INITIALIZED = True
55
+ cls.base_url = DEFAULT_URL_FOR_TEST
56
+
57
+ @classmethod
58
+ def tearDownClass(cls):
59
+ # First class does not terminate server
60
+ pass
61
+
62
+ def test_api_health(self):
63
+ response = requests.get(f"{self.base_url}/health")
64
+ self.assertEqual(response.status_code, 200)
65
+
66
+ def test_api_health_generate(self):
67
+ response = requests.get(f"{self.base_url}/health_generate")
68
+ self.assertEqual(response.status_code, 200)
69
+
70
+ def test_api_ping(self):
71
+ response = requests.get(f"{self.base_url}/ping")
72
+ self.assertEqual(response.status_code, 200)
73
+
74
+ def test_api_model_info(self):
75
+ response = requests.get(f"{self.base_url}/model_info")
76
+ self.assertEqual(response.status_code, 200)
77
+ self.assertEqual(response.json()["model_path"], self.model)
78
+ self.assertEqual(response.json()["tokenizer_path"], self.model)
79
+ self.assertTrue(response.json()["is_generation"])
80
+ self.assertIsNone(response.json()["preferred_sampling_params"])
81
+ self.assertEqual(response.json()["weight_version"], "default")
82
+ self.assertFalse(response.json()["has_image_understanding"])
83
+ self.assertFalse(response.json()["has_audio_understanding"])
84
+ self.assertEqual(response.json()["model_type"], "llama")
85
+ self.assertEqual(response.json()["architectures"][0], "LlamaForCausalLM")
86
+
87
+ def test_api_server_info(self):
88
+ response = requests.get(f"{self.base_url}/server_info")
89
+ self.assertEqual(response.status_code, 200)
90
+ self.assertEqual(response.json()["model_path"], self.model)
91
+ self.assertEqual(response.json()["tokenizer_path"], self.model)
92
+
93
+ def test_api_v1_loads(self):
94
+ response = requests.get(f"{self.base_url}/v1/loads")
95
+ self.assertEqual(response.status_code, 200)
96
+ body = response.json()
97
+ self.assertIn("loads", body)
98
+ self.assertIn("aggregate", body)
99
+ self.assertGreaterEqual(len(body["loads"]), 1)
100
+ load = body["loads"][0]
101
+ self.assertGreaterEqual(load["num_running_reqs"], 0)
102
+ self.assertGreaterEqual(load["num_waiting_reqs"], 0)
103
+ self.assertGreaterEqual(load["num_used_tokens"], 0)
104
+ self.assertGreaterEqual(load["num_total_tokens"], 0)
105
+
106
+ def test_api_v1_models(self):
107
+ response = requests.get(f"{self.base_url}/v1/models")
108
+ self.assertEqual(response.status_code, 200)
109
+ self.assertEqual(response.json()["data"][0]["id"], self.model)
110
+ self.assertEqual(response.json()["data"][0]["object"], "model")
111
+ self.assertEqual(response.json()["data"][0]["owned_by"], "sglang")
112
+ self.assertEqual(response.json()["data"][0]["root"], self.model)
113
+ self.assertEqual(response.json()["data"][0]["max_model_len"], 131072)
114
+
115
+ def test_api_v1_models_path(self):
116
+ response = requests.get(f"{self.base_url}/v1/models/{self.model}")
117
+ self.assertEqual(response.status_code, 200)
118
+ self.assertEqual(response.json()["id"], self.model)
119
+ self.assertEqual(response.json()["object"], "model")
120
+ self.assertEqual(response.json()["owned_by"], "sglang")
121
+ self.assertEqual(response.json()["root"], self.model)
122
+ self.assertEqual(response.json()["max_model_len"], 131072)
123
+
124
+ def test_api_generate_single_text(self):
125
+ response = requests.post(
126
+ f"{self.base_url}/generate",
127
+ json={
128
+ "rid": "req_001",
129
+ "text": "The capital of France is",
130
+ "sampling_params": {
131
+ "temperature": 0,
132
+ "max_new_tokens": 20,
133
+ },
134
+ "return_logprob": True,
135
+ "stream": False,
136
+ "return_hidden_states": True,
137
+ },
138
+ )
139
+ self.assertEqual(response.status_code, 200)
140
+ meta_info_keys = response.json()["meta_info"].keys()
141
+ self.assertEqual("req_001", response.json()["meta_info"]["id"])
142
+ self.assertIn("Paris", response.json()["text"])
143
+ self.assertEqual(20, response.json()["meta_info"]["completion_tokens"])
144
+ self.assertIn("input_token_logprobs", meta_info_keys)
145
+ self.assertIn("output_token_logprobs", meta_info_keys)
146
+ self.assertIn("hidden_states", meta_info_keys)
147
+
148
+ def test_api_generate_batch_texts(self):
149
+ rids = ["req_1", "req_2"]
150
+ texts = [
151
+ "The capital of France is",
152
+ "What is the best time of year to visit Japan for cherry blossoms?",
153
+ ]
154
+ response = requests.post(
155
+ f"{self.base_url}/generate",
156
+ json={
157
+ "rid": rids,
158
+ "text": texts,
159
+ "sampling_params": {
160
+ "temperature": 0,
161
+ "max_new_tokens": 20,
162
+ },
163
+ "return_logprob": False,
164
+ "stream": False,
165
+ "return_hidden_states": False,
166
+ },
167
+ )
168
+ self.assertEqual(response.status_code, 200)
169
+ self.assertEqual("req_1", response.json()[0]["meta_info"]["id"])
170
+ self.assertIn("Paris", response.json()[0]["text"])
171
+ self.assertEqual("req_2", response.json()[1]["meta_info"]["id"])
172
+ self.assertIn("Japan", response.json()[1]["text"])
173
+
174
+ def test_api_generate_temperature(self):
175
+ response = requests.post(
176
+ f"{self.base_url}/generate",
177
+ json={
178
+ "text": "The capital of France is",
179
+ "sampling_params": {
180
+ "temperature": 5,
181
+ "max_new_tokens": 20,
182
+ },
183
+ },
184
+ )
185
+ self.assertEqual(response.status_code, 200)
186
+ text1 = response.json()["text"]
187
+ response = requests.post(
188
+ f"{self.base_url}/generate",
189
+ json={
190
+ "text": "The capital of France is",
191
+ "sampling_params": {
192
+ "temperature": 5,
193
+ "max_new_tokens": 20,
194
+ },
195
+ },
196
+ )
197
+ self.assertEqual(response.status_code, 200)
198
+ text2 = response.json()["text"]
199
+ self.assertNotEqual(text2, text1)
200
+
201
+ def test_api_generate_input_ids(self):
202
+ text = "The capital of France is"
203
+ tokenizer = AutoTokenizer.from_pretrained(self.model)
204
+ input_ids = tokenizer(text, return_tensors="pt")["input_ids"][0].tolist()
205
+ response = requests.post(
206
+ f"{self.base_url}/generate",
207
+ json={
208
+ "rid": "req_002",
209
+ "input_ids": input_ids,
210
+ "sampling_params": {
211
+ "temperature": 0,
212
+ "max_new_tokens": 10,
213
+ },
214
+ "return_logprob": False,
215
+ "stream": True,
216
+ "return_hidden_states": False,
217
+ },
218
+ )
219
+ self.assertEqual(response.status_code, 200)
220
+ lines = response.text.strip().split("\n")
221
+ self.assertGreaterEqual(len(lines), 10)
222
+ json_data = lines[-3][6:]
223
+ data = json.loads(json_data)
224
+ meta_info_keys = data["meta_info"].keys()
225
+ self.assertEqual("req_002", data["meta_info"]["id"])
226
+ self.assertIn("Paris", data["text"])
227
+ self.assertEqual(10, data["meta_info"]["completion_tokens"])
228
+ self.assertNotIn("input_token_logprobs", meta_info_keys)
229
+ self.assertNotIn("output_token_logprobs", meta_info_keys)
230
+ self.assertNotIn("hidden_states", meta_info_keys)
231
+
232
+
233
+ class TestChatCompletionsInterface(CustomTestCase):
234
+ """Testcase: The test is to verify whether the functions of each parameter of the v1/chat/completions interface are normal.
235
+
236
+ [Test Category] Interface
237
+ [Test Target] v1/chat/completions
238
+ """
239
+
240
+ @classmethod
241
+ def setUpClass(cls):
242
+ # Skip initialization, directly reuse global server
243
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
244
+ cls.base_url = DEFAULT_URL_FOR_TEST
245
+ cls.additional_chat_kwargs = {}
246
+
247
+ @classmethod
248
+ def tearDownClass(cls):
249
+ # Do not terminate server
250
+ pass
251
+
252
+ def test_model_and_messages(self):
253
+ response = requests.post(
254
+ f"{self.base_url}/v1/chat/completions",
255
+ json={
256
+ "model": self.model,
257
+ "messages": [{"role": "user", "content": "Hello"}],
258
+ },
259
+ )
260
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
261
+ data = response.json()
262
+ self.assertEqual(data["model"], self.model)
263
+ self.assertIsNotNone(data["choices"][0]["message"]["reasoning_content"])
264
+
265
+ response = requests.post(
266
+ f"{self.base_url}/v1/chat/completions",
267
+ json={
268
+ "messages": [{"role": "user", "content": "Hello"}],
269
+ },
270
+ )
271
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
272
+ data = response.json()
273
+ self.assertEqual(data["model"], "default")
274
+ self.assertIsNotNone(data["choices"][0]["message"]["reasoning_content"])
275
+
276
+ def test_max_completion_tokens(self):
277
+ response = requests.post(
278
+ f"{self.base_url}/v1/chat/completions",
279
+ json={
280
+ "messages": [{"role": "user", "content": "Hello"}],
281
+ "max_completion_tokens": 1,
282
+ },
283
+ )
284
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
285
+ self.assertEqual(response.json()["choices"][0]["finish_reason"], "length")
286
+
287
+ def test_stream(self):
288
+ response = requests.post(
289
+ f"{self.base_url}/v1/chat/completions",
290
+ json={
291
+ "model": self.model,
292
+ "messages": [{"role": "user", "content": "Hello"}],
293
+ "stream": True,
294
+ },
295
+ )
296
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
297
+ has_reasoning = False
298
+ has_content = False
299
+
300
+ for line in response.iter_lines():
301
+ if line:
302
+ line = line.decode("utf-8")
303
+ if line.startswith("data:") and not line.startswith("data: [DONE]"):
304
+ data = json.loads(line[6:])
305
+ if "choices" in data and len(data["choices"]) > 0:
306
+ delta = data["choices"][0].get("delta", {})
307
+ if "reasoning_content" in delta and delta["reasoning_content"]:
308
+ has_reasoning = True
309
+ if "content" in delta and delta["content"]:
310
+ has_content = True
311
+
312
+ self.assertTrue(
313
+ has_reasoning, "Reasoning content not included in stream response"
314
+ )
315
+ self.assertTrue(has_content, "Normal content not included in stream response")
316
+
317
+ def test_temperature(self):
318
+ response1 = requests.post(
319
+ f"{self.base_url}/v1/chat/completions",
320
+ json={
321
+ "model": self.model,
322
+ "messages": [
323
+ {
324
+ "role": "user",
325
+ "content": "Please write a five-character quatrain for me.",
326
+ }
327
+ ],
328
+ "temperature": 0,
329
+ },
330
+ )
331
+ self.assertEqual(response1.status_code, 200, f"Failed with: {response1.text}")
332
+ content1 = response1.json()["choices"][0]["message"]["content"]
333
+
334
+ response2 = requests.post(
335
+ f"{self.base_url}/v1/chat/completions",
336
+ json={
337
+ "model": self.model,
338
+ "messages": [
339
+ {
340
+ "role": "user",
341
+ "content": "Please write a five-character quatrain for me.",
342
+ }
343
+ ],
344
+ "temperature": 0,
345
+ },
346
+ )
347
+ self.assertEqual(response2.status_code, 200, f"Failed with: {response2.text}")
348
+ content2 = response2.json()["choices"][0]["message"]["content"]
349
+ self.assertEqual(content1, content2)
350
+
351
+ response3 = requests.post(
352
+ f"{self.base_url}/v1/chat/completions",
353
+ json={
354
+ "model": self.model,
355
+ "messages": [
356
+ {
357
+ "role": "user",
358
+ "content": "Please write a five-character quatrain for me.",
359
+ }
360
+ ],
361
+ "temperature": 2,
362
+ },
363
+ )
364
+ self.assertEqual(response3.status_code, 200, f"Failed with: {response3.text}")
365
+ content3 = response3.json()["choices"][0]["message"]["content"]
366
+
367
+ response4 = requests.post(
368
+ f"{self.base_url}/v1/chat/completions",
369
+ json={
370
+ "model": self.model,
371
+ "messages": [
372
+ {
373
+ "role": "user",
374
+ "content": "Please write a five-character quatrain for me.",
375
+ }
376
+ ],
377
+ "temperature": 2,
378
+ },
379
+ )
380
+ self.assertEqual(response4.status_code, 200, f"Failed with: {response4.text}")
381
+ content4 = response4.json()["choices"][0]["message"]["content"]
382
+ self.assertNotEqual(content3, content4)
383
+
384
+ def test_return_hidden_states(self):
385
+ response = requests.post(
386
+ f"{self.base_url}/v1/chat/completions",
387
+ json={
388
+ "model": self.model,
389
+ "messages": [{"role": "user", "content": "Hello"}],
390
+ "return_hidden_states": True,
391
+ },
392
+ )
393
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
394
+ self.assertIn("hidden_states", response.json()["choices"][0])
395
+
396
+ response = requests.post(
397
+ f"{self.base_url}/v1/chat/completions",
398
+ json={
399
+ "model": self.model,
400
+ "messages": [{"role": "user", "content": "Hello"}],
401
+ },
402
+ )
403
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
404
+ self.assertNotIn("hidden_states", response.json()["choices"][0])
405
+
406
+ def test_top_k(self):
407
+ response1 = requests.post(
408
+ f"{self.base_url}/v1/chat/completions",
409
+ json={
410
+ "model": self.model,
411
+ "messages": [
412
+ {
413
+ "role": "user",
414
+ "content": "Please write a five-character quatrain for me.",
415
+ }
416
+ ],
417
+ "top_k": 20,
418
+ },
419
+ )
420
+ self.assertEqual(response1.status_code, 200, f"Failed with: {response1.text}")
421
+ content1 = response1.json()["choices"][0]["message"]["content"]
422
+
423
+ response2 = requests.post(
424
+ f"{self.base_url}/v1/chat/completions",
425
+ json={
426
+ "model": self.model,
427
+ "messages": [
428
+ {
429
+ "role": "user",
430
+ "content": "Please write a five-character quatrain for me.",
431
+ }
432
+ ],
433
+ "top_k": 20,
434
+ },
435
+ )
436
+ self.assertEqual(response2.status_code, 200, f"Failed with: {response2.text}")
437
+ content2 = response2.json()["choices"][0]["message"]["content"]
438
+ self.assertNotEqual(content1, content2)
439
+
440
+ def test_stop_token_ids(self):
441
+ response = requests.post(
442
+ f"{self.base_url}/v1/chat/completions",
443
+ json={
444
+ "model": self.model,
445
+ "messages": [{"role": "user", "content": "Hello"}],
446
+ "stop_token_ids": [1, 13],
447
+ },
448
+ )
449
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
450
+ self.assertEqual(response.json()["choices"][0]["matched_stop"], 13)
451
+
452
+ def test_rid(self):
453
+ response = requests.post(
454
+ f"{self.base_url}/v1/chat/completions",
455
+ json={
456
+ "model": self.model,
457
+ "messages": [{"role": "user", "content": "Hello"}],
458
+ "rid": "sssss",
459
+ },
460
+ )
461
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
462
+ self.assertEqual(response.json()["id"], "sssss")
463
+
464
+
465
+ class TestEnableThinking(CustomTestCase):
466
+ """Testcase: The test is to verify whether the functions of each parameter of the v1/completions interface are normal.
467
+
468
+ [Test Category] Interface
469
+ [Test Target] v1/completions
470
+ """
471
+
472
+ @classmethod
473
+ def setUpClass(cls):
474
+ # Skip initialization, directly reuse global server
475
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
476
+ cls.base_url = DEFAULT_URL_FOR_TEST
477
+ cls.additional_chat_kwargs = {}
478
+ logging.basicConfig(level=logging.INFO) # Initialize logging
479
+
480
+ @classmethod
481
+ def tearDownClass(cls):
482
+ # Do not terminate server
483
+ pass
484
+
485
+ def test_model_parameters_model(self):
486
+ response = requests.post(
487
+ f"{self.base_url}/v1/completions",
488
+ json={"model": self.model, "prompt": "who are you?"},
489
+ )
490
+ logging.info(f"response.json:{response.json()}")
491
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
492
+ data = response.json()
493
+ self.assertEqual(data["model"], self.model)
494
+
495
+ def test_model_parameters_prompt(self):
496
+ # str format
497
+ response = requests.post(
498
+ f"{self.base_url}/v1/completions",
499
+ json={"prompt": "who are you?"},
500
+ )
501
+ logging.info(f"response.json:{response.json()}")
502
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
503
+
504
+ # list[int] format
505
+ list_int = [1, 2, 3, 4]
506
+ response1 = requests.post(
507
+ f"{self.base_url}/v1/completions",
508
+ json={"prompt": list_int},
509
+ )
510
+ logging.info(f"response1.json:{response1.json()}")
511
+ self.assertEqual(response1.status_code, 200, f"Failed with: {response1.text}")
512
+
513
+ # list[str] format
514
+ list_str = ["who is you", "hello world", "ABChello"]
515
+ response2 = requests.post(
516
+ f"{self.base_url}/v1/completions",
517
+ json={"prompt": list_str},
518
+ )
519
+ logging.info(f"response2.json:{response2.json()}")
520
+ self.assertEqual(response2.status_code, 200, f"Failed with: {response2.text}")
521
+
522
+ # list[list[int]] format
523
+ list_list_int = [[14990], [1350, 445, 14990, 1879, 899], [14623, 525, 498, 30]]
524
+ response3 = requests.post(
525
+ f"{self.base_url}/v1/completions",
526
+ json={"prompt": list_list_int},
527
+ )
528
+ logging.info(f"response3.json:{response3.json()}")
529
+ self.assertEqual(response3.status_code, 200, f"Failed with: {response3.text}")
530
+
531
+ def test_model_parameters_max_tokens(self):
532
+ response = requests.post(
533
+ f"{self.base_url}/v1/completions",
534
+ json={"prompt": "who are you?", "max_tokens": 1},
535
+ )
536
+ logging.info(f"response.json:{response.json()}")
537
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
538
+ logging.info(f"finish_reason:{response.json()['choices'][0]['finish_reason']}")
539
+ self.assertEqual(response.json()["choices"][0]["finish_reason"], "length")
540
+
541
+ def test_model_parameters_stream(self):
542
+ response = requests.post(
543
+ f"{self.base_url}/v1/completions",
544
+ json={"prompt": "who are you?", "stream": True},
545
+ )
546
+ logging.info(f"response.text:{response.text}")
547
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
548
+
549
+ has_text = False
550
+ logging.info("\n=== Stream With Reasoning ===")
551
+ for line in response.iter_lines():
552
+ if line:
553
+ line = line.decode("utf-8")
554
+ if line.startswith("data:") and not line.startswith("data: [DONE]"):
555
+ data = json.loads(line[6:])
556
+ if "choices" in data and len(data["choices"]) > 0:
557
+ if "text" in data["choices"][0]:
558
+ has_text = True
559
+ self.assertTrue(has_text, "Text content not included in stream response")
560
+
561
+ def test_model_parameters_temperature(self):
562
+ response = requests.post(
563
+ f"{self.base_url}/v1/completions",
564
+ json={"prompt": "who are you?", "temperature": 0},
565
+ )
566
+ logging.info(f"response.json:{response.json()}")
567
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
568
+
569
+ response1 = requests.post(
570
+ f"{self.base_url}/v1/completions",
571
+ json={"prompt": "who are you?", "temperature": 0},
572
+ )
573
+ logging.info(f"response1.json:{response1.json()}")
574
+ self.assertEqual(response1.status_code, 200, f"Failed with: {response1.text}")
575
+ self.assertEqual(
576
+ response.json()["choices"][0]["text"],
577
+ response1.json()["choices"][0]["text"],
578
+ )
579
+
580
+ response2 = requests.post(
581
+ f"{self.base_url}/v1/completions",
582
+ json={"prompt": "who are you?", "temperature": 2},
583
+ )
584
+ logging.info(f"response2.json:{response2.json()}")
585
+ self.assertEqual(response2.status_code, 200, f"Failed with: {response2.text}")
586
+
587
+ response3 = requests.post(
588
+ f"{self.base_url}/v1/completions",
589
+ json={"prompt": "who are you?", "temperature": 2},
590
+ )
591
+ logging.info(f"response3.json:{response3.json()}")
592
+ self.assertEqual(response3.status_code, 200, f"Failed with: {response3.text}")
593
+ self.assertNotEqual(
594
+ response2.json()["choices"][0]["text"],
595
+ response3.json()["choices"][0]["text"],
596
+ )
597
+
598
+ def test_model_parameters_hidden_states(self):
599
+ response = requests.post(
600
+ f"{self.base_url}/v1/completions",
601
+ json={"prompt": "who are you?", "return_hidden_states": True},
602
+ )
603
+ logging.info(f"response.json:{response.json()}")
604
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
605
+ self.assertIn("hidden_states", response.json()["choices"][0])
606
+
607
+ def test_model_parameters_top_k(self):
608
+ response = requests.post(
609
+ f"{self.base_url}/v1/completions",
610
+ json={"prompt": "who are you?", "top_k": 20},
611
+ )
612
+ logging.info(f"response.json:{response.json()}")
613
+ logging.info(f"response.text:{response.text}")
614
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
615
+
616
+ response1 = requests.post(
617
+ f"{self.base_url}/v1/completions",
618
+ json={"prompt": "who are you?", "top_k": 20},
619
+ )
620
+ logging.info(f"response1.json:{response1.json()}")
621
+ logging.info(f"response1.text:{response1.text}")
622
+ self.assertEqual(response1.status_code, 200, f"Failed with: {response1.text}")
623
+ self.assertNotEqual(
624
+ response.json()["choices"][0]["text"],
625
+ response1.json()["choices"][0]["text"],
626
+ )
627
+
628
+ def test_model_parameters_stop_token_ids(self):
629
+ list_ids = [13]
630
+ response = requests.post(
631
+ f"{self.base_url}/v1/completions",
632
+ json={
633
+ "prompt": "who are you?",
634
+ "stop_token_ids": list_ids,
635
+ "max_tokens": 1024,
636
+ },
637
+ )
638
+ logging.info(f"response.json:{response.json()}")
639
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
640
+ self.assertEqual(response.json()["choices"][0]["matched_stop"], 13)
641
+
642
+ def test_model_parameters_rid(self):
643
+ response = requests.post(
644
+ f"{self.base_url}/v1/completions",
645
+ json={"prompt": "who are you?", "rid": "10086"},
646
+ )
647
+ logging.info(f"response.json:{response.json()}")
648
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
649
+ self.assertEqual(response.json()["id"], "10086")
650
+
651
+
652
+ class TestStartProfile(CustomTestCase):
653
+ """Testcase: Verify the correctness of /start_profile API with different parameter combinations (start_step/num_steps) on Ascend NPU backend.
654
+
655
+ [Test Category] Interface
656
+ [Test Target] /start_profile
657
+ """
658
+
659
+ @classmethod
660
+ def setUpClass(cls):
661
+ # Skip initialization, reuse global server + configure profiler directory
662
+ envs.SGLANG_TORCH_PROFILER_DIR.set(OUTPUT_DIR)
663
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
664
+ cls.base_url = DEFAULT_URL_FOR_TEST
665
+ cls.additional_chat_kwargs = {}
666
+
667
+ @classmethod
668
+ def tearDownClass(cls):
669
+ # Terminate server in last class
670
+ global GLOBAL_SERVER_PROCESS
671
+ if GLOBAL_SERVER_PROCESS:
672
+ kill_process_tree(GLOBAL_SERVER_PROCESS.pid)
673
+ GLOBAL_SERVER_PROCESS = None
674
+
675
+ def setUp(self):
676
+ self._clear_profile_dir()
677
+
678
+ def test_start_profile_1(self):
679
+ self._start_profile(start_step="15", num_steps=5)
680
+ self._post_request()
681
+ self._check_non_empty_profile_dir()
682
+
683
+ def test_start_profile_2(self):
684
+ self._clear_profile_dir()
685
+ self._check_empty_profile_dir()
686
+ self._start_profile()
687
+ self._post_request()
688
+ requests.post(f"{self.base_url}/stop_profile")
689
+ self._check_non_empty_profile_dir()
690
+
691
+ def test_start_profile_3(self):
692
+ self._start_profile(num_steps=5)
693
+ self._post_request()
694
+ self._check_non_empty_profile_dir()
695
+
696
+ def _start_profile(self, **kwargs):
697
+ response = requests.post(
698
+ f"{self.base_url}/start_profile",
699
+ json=kwargs if kwargs else None,
700
+ )
701
+ self.assertEqual(response.status_code, 200)
702
+ return response
703
+
704
+ def _post_request(self):
705
+ response = requests.post(
706
+ f"{self.base_url}/generate",
707
+ json={
708
+ "text": "The capital of France is",
709
+ "sampling_params": {
710
+ "temperature": 0,
711
+ "max_new_tokens": 32,
712
+ },
713
+ },
714
+ )
715
+ self.assertEqual(response.status_code, 200)
716
+
717
+ def _clear_profile_dir(self):
718
+ if os.path.isdir(OUTPUT_DIR):
719
+ shutil.rmtree(OUTPUT_DIR)
720
+
721
+ def _check_non_empty_profile_dir(self):
722
+ self.assertTrue(os.path.isdir(OUTPUT_DIR), "Profiler directory does not exist")
723
+ self.assertNotEqual(
724
+ len(os.listdir(OUTPUT_DIR)), 0, "Profiler directory is empty"
725
+ )
726
+
727
+ def _check_empty_profile_dir(self):
728
+ if os.path.isdir(OUTPUT_DIR):
729
+ self.assertEqual(
730
+ len(os.listdir(OUTPUT_DIR)), 0, "Profiler directory is not empty"
731
+ )
732
+
733
+
734
+ if __name__ == "__main__":
735
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_api_abort_request.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import threading
2
+ import time
3
+ import unittest
4
+
5
+ import requests
6
+
7
+ from sglang.srt.utils import kill_process_tree
8
+ from sglang.test.ascend.test_ascend_utils import LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
9
+ from sglang.test.ci.ci_register import register_npu_ci
10
+ from sglang.test.test_utils import (
11
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
12
+ DEFAULT_URL_FOR_TEST,
13
+ CustomTestCase,
14
+ popen_launch_server,
15
+ )
16
+
17
+ responses = []
18
+
19
+
20
+ def send_requests(url, **kwargs):
21
+ response = requests.post(DEFAULT_URL_FOR_TEST + url, json=kwargs)
22
+ responses.append(response)
23
+
24
+
25
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
26
+
27
+
28
+ class TestNpuApi(CustomTestCase):
29
+ """Testcase: Verify the functionality of /abort_request API to terminate a running /generate request on Ascend backend.
30
+
31
+ [Test Category] Interface
32
+ [Test Target] /abort_request
33
+ """
34
+
35
+ @classmethod
36
+ def setUpClass(cls):
37
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
38
+ other_args = [
39
+ "--attention-backend",
40
+ "ascend",
41
+ ]
42
+ cls.process = popen_launch_server(
43
+ cls.model,
44
+ DEFAULT_URL_FOR_TEST,
45
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
46
+ other_args=other_args,
47
+ )
48
+
49
+ @classmethod
50
+ def tearDownClass(cls):
51
+ kill_process_tree(cls.process.pid)
52
+
53
+ def test_api_abort_request(self):
54
+ # Create thread 1: Send a long-running /generate request with rid=10086
55
+ thread1 = threading.Thread(
56
+ target=send_requests,
57
+ args=("/generate",),
58
+ kwargs={
59
+ "rid": "10086",
60
+ "text": "who are you?",
61
+ "sampling_params": {"temperature": 0.0, "max_new_tokens": 1024},
62
+ },
63
+ )
64
+ # Create thread 2: Send an /abort_request to terminate the request with rid=10086
65
+ thread2 = threading.Thread(
66
+ target=send_requests, args=("/abort_request",), kwargs={"rid": "10086"}
67
+ )
68
+ thread1.start()
69
+ time.sleep(0.5)
70
+ thread2.start()
71
+ thread1.join()
72
+ thread2.join()
73
+ print(responses[1].text)
74
+
75
+
76
+ if __name__ == "__main__":
77
+
78
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_api_encode.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import unittest
3
+
4
+ import requests
5
+
6
+ from sglang.srt.utils import kill_process_tree
7
+ from sglang.test.ascend.test_ascend_utils import QWEN3_VL_4B_INSTRUCT_WEIGHTS_PATH
8
+ from sglang.test.ci.ci_register import register_npu_ci
9
+ from sglang.test.test_utils import (
10
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
11
+ DEFAULT_URL_FOR_TEST,
12
+ CustomTestCase,
13
+ popen_launch_server,
14
+ )
15
+
16
+ logging.basicConfig(
17
+ level=logging.INFO,
18
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
19
+ handlers=[logging.StreamHandler()],
20
+ )
21
+ logger = logging.getLogger(__name__)
22
+
23
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
24
+
25
+
26
+ class TestNpuApi(CustomTestCase):
27
+ """Testcase: Verify the availability and correctness of the /encode API on Ascend backend with GME_QWEN2_VL_2B_INSTRUCT model.
28
+
29
+ [Test Category] Interface
30
+ [Test Target] /encode
31
+ """
32
+
33
+ @classmethod
34
+ def setUpClass(cls):
35
+ cls.model = QWEN3_VL_4B_INSTRUCT_WEIGHTS_PATH
36
+ other_args = [
37
+ "--attention-backend",
38
+ "ascend",
39
+ "--disable-cuda-graph",
40
+ "--tp-size",
41
+ 2,
42
+ "--is-embedding",
43
+ ]
44
+ cls.process = popen_launch_server(
45
+ cls.model,
46
+ DEFAULT_URL_FOR_TEST,
47
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
48
+ other_args=other_args,
49
+ )
50
+
51
+ @classmethod
52
+ def tearDownClass(cls):
53
+ kill_process_tree(cls.process.pid)
54
+
55
+ def test_api_encode_01(self):
56
+ # Test Scenario 1: Call /encode API with plain text parameter
57
+ response = requests.post(
58
+ f"{DEFAULT_URL_FOR_TEST}/encode",
59
+ json={
60
+ "rid": "2",
61
+ "text": "what is the capital of France",
62
+ "sampling_params": {
63
+ "temperature": 0,
64
+ "max_new_tokens": 200,
65
+ "top_p": 1,
66
+ },
67
+ },
68
+ )
69
+ logger.info("Test 01 response keys: %s", response.json().keys())
70
+ self.assertEqual(response.status_code, 200)
71
+ self.assertEqual(response.json()["meta_info"]["id"], "2")
72
+
73
+ def test_api_encode_02(self):
74
+ # Test Scenario 2: Call /encode API with input_ids parameter
75
+ response = requests.post(
76
+ f"{DEFAULT_URL_FOR_TEST}/encode",
77
+ json={
78
+ "rid": "3",
79
+ "input_ids": [101, 7592, 2088, 102],
80
+ "sampling_params": {"temperature": 0, "max_new_tokens": 200},
81
+ },
82
+ )
83
+ self.assertEqual(response.status_code, 200)
84
+ self.assertEqual(response.json()["meta_info"]["id"], "3")
85
+
86
+ def test_api_encode_03(self):
87
+ # Test Scenario 3: Call /encode API with text and image parameters (multimodal capability verification)
88
+ response = requests.post(
89
+ f"{DEFAULT_URL_FOR_TEST}/encode",
90
+ json={
91
+ "rid": "4",
92
+ "text": "show me the words",
93
+ "image_data": "https://miaobi-lite.bj.bcebos.com/miaobi/5mao/b%27b2Ny6K%2BG5Yir5Luj56CBXzE3MzQ2MzcyNjAuMzgxNDk5NQ%3D%3D%27/0.png",
94
+ "sampling_params": {"temperature": 0, "max_new_tokens": 200},
95
+ },
96
+ )
97
+ logger.info("Test 03 response keys: %s", response.json().keys())
98
+ self.assertEqual(response.status_code, 200)
99
+ self.assertEqual(response.json()["meta_info"]["id"], "4")
100
+
101
+ def test_api_encode_04(self):
102
+ # Test Scenario 4: Call /encode API with list of rids (multiple requests) - text input
103
+ request_rids = ["5", "6", "7"]
104
+ response = requests.post(
105
+ f"{DEFAULT_URL_FOR_TEST}/encode",
106
+ json={
107
+ "rid": request_rids,
108
+ "text": [
109
+ "what is the capital of UK",
110
+ "what is the capital of Germany",
111
+ "what is the capital of Japan",
112
+ ],
113
+ "sampling_params": {
114
+ "temperature": 0,
115
+ "max_new_tokens": 200,
116
+ "top_p": 1,
117
+ },
118
+ },
119
+ )
120
+ response_json = response.json()
121
+ logger.info(
122
+ "Test 04 response type: %s, first item meta_info: %s",
123
+ type(response_json),
124
+ response_json[0].get("meta_info", {}),
125
+ )
126
+
127
+ self.assertEqual(response.status_code, 200)
128
+ self.assertEqual(len(response_json), len(request_rids))
129
+ for idx, result in enumerate(response_json):
130
+ self.assertEqual(result["meta_info"]["id"], request_rids[idx])
131
+
132
+
133
+ if __name__ == "__main__":
134
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_enable_thinking.py ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import unittest
3
+
4
+ import requests
5
+
6
+ from sglang.srt.utils import kill_process_tree
7
+ from sglang.test.ascend.test_ascend_utils import QWEN3_30B_A3B_WEIGHTS_PATH
8
+ from sglang.test.ci.ci_register import register_npu_ci
9
+ from sglang.test.test_utils import (
10
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
11
+ DEFAULT_URL_FOR_TEST,
12
+ CustomTestCase,
13
+ popen_launch_server,
14
+ )
15
+
16
+ register_npu_ci(
17
+ est_time=400,
18
+ suite="nightly-2-npu-a3",
19
+ nightly=True,
20
+ )
21
+
22
+
23
+ class TestEnableThinking(CustomTestCase):
24
+ """Testcase: Testing with the 'enable_thinking' feature enabled/disabled,
25
+ both streaming and non-streaming input requests successful
26
+
27
+ [Test Category] Interface
28
+ [Test Target] /v1/chat/completions
29
+ """
30
+
31
+ @classmethod
32
+ def setUpClass(cls):
33
+ cls.model = QWEN3_30B_A3B_WEIGHTS_PATH
34
+ cls.base_url = DEFAULT_URL_FOR_TEST
35
+ cls.other_args = [
36
+ "--attention-backend",
37
+ "ascend",
38
+ "--disable-cuda-graph",
39
+ "--mem-fraction-static",
40
+ 0.95,
41
+ "--tp",
42
+ 2,
43
+ "--reasoning-parser",
44
+ "qwen3",
45
+ ]
46
+ cls.process = popen_launch_server(
47
+ cls.model,
48
+ cls.base_url,
49
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
50
+ other_args=cls.other_args,
51
+ )
52
+ cls.additional_chat_kwargs = {}
53
+
54
+ @classmethod
55
+ def tearDownClass(cls):
56
+ kill_process_tree(cls.process.pid)
57
+
58
+ def test_chat_completion_with_reasoning(self):
59
+ # Test non-streaming with "enable_thinking": True, reasoning_content should not be empty
60
+ client = requests.post(
61
+ f"{self.base_url}/v1/chat/completions",
62
+ json={
63
+ "model": self.model,
64
+ "messages": [{"role": "user", "content": "Hello"}],
65
+ "temperature": 0,
66
+ "separate_reasoning": True,
67
+ "chat_template_kwargs": {"enable_thinking": True},
68
+ **self.additional_chat_kwargs,
69
+ },
70
+ )
71
+
72
+ self.assertEqual(client.status_code, 200, f"Failed with: {client.text}")
73
+ data = client.json()
74
+
75
+ self.assertIn("choices", data)
76
+ self.assertTrue(len(data["choices"]) > 0)
77
+ self.assertIn("message", data["choices"][0])
78
+ self.assertIn("reasoning_content", data["choices"][0]["message"])
79
+ self.assertIsNotNone(data["choices"][0]["message"]["reasoning_content"])
80
+
81
+ def test_chat_completion_without_reasoning(self):
82
+ # Test non-streaming with "enable_thinking": False, reasoning_content should be empty
83
+ client = requests.post(
84
+ f"{self.base_url}/v1/chat/completions",
85
+ json={
86
+ "model": self.model,
87
+ "messages": [{"role": "user", "content": "Hello"}],
88
+ "temperature": 0,
89
+ "separate_reasoning": True,
90
+ "chat_template_kwargs": {"enable_thinking": False},
91
+ **self.additional_chat_kwargs,
92
+ },
93
+ )
94
+
95
+ self.assertEqual(client.status_code, 200, f"Failed with: {client.text}")
96
+ data = client.json()
97
+
98
+ self.assertIn("choices", data)
99
+ self.assertTrue(len(data["choices"]) > 0)
100
+ self.assertIn("message", data["choices"][0])
101
+
102
+ if "reasoning_content" in data["choices"][0]["message"]:
103
+ self.assertIsNone(data["choices"][0]["message"]["reasoning_content"])
104
+
105
+ def test_stream_chat_completion_with_reasoning(self):
106
+ # Test streaming with "enable_thinking": True, reasoning_content should not be empty
107
+ response = requests.post(
108
+ f"{self.base_url}/v1/chat/completions",
109
+ json={
110
+ "model": self.model,
111
+ "messages": [{"role": "user", "content": "Hello"}],
112
+ "temperature": 0,
113
+ "separate_reasoning": True,
114
+ "stream": True,
115
+ "chat_template_kwargs": {"enable_thinking": True},
116
+ **self.additional_chat_kwargs,
117
+ },
118
+ stream=True,
119
+ )
120
+
121
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
122
+
123
+ has_reasoning = False
124
+ has_content = False
125
+
126
+ print("\n=== Stream With Reasoning ===")
127
+ for line in response.iter_lines():
128
+ if line:
129
+ line = line.decode("utf-8")
130
+ if line.startswith("data:") and not line.startswith("data: [DONE]"):
131
+ data = json.loads(line[6:])
132
+ if "choices" in data and len(data["choices"]) > 0:
133
+ delta = data["choices"][0].get("delta", {})
134
+
135
+ if "reasoning_content" in delta and delta["reasoning_content"]:
136
+ has_reasoning = True
137
+
138
+ if "content" in delta and delta["content"]:
139
+ has_content = True
140
+
141
+ self.assertTrue(
142
+ has_reasoning,
143
+ "The reasoning content is not included in the stream response",
144
+ )
145
+ self.assertTrue(
146
+ has_content, "The stream response does not contain normal content"
147
+ )
148
+
149
+ def test_stream_chat_completion_without_reasoning(self):
150
+ # Test streaming with "enable_thinking": False, reasoning_content should be empty
151
+ response = requests.post(
152
+ f"{self.base_url}/v1/chat/completions",
153
+ json={
154
+ "model": self.model,
155
+ "messages": [{"role": "user", "content": "Hello"}],
156
+ "temperature": 0,
157
+ "separate_reasoning": True,
158
+ "stream": True,
159
+ "chat_template_kwargs": {"enable_thinking": False},
160
+ **self.additional_chat_kwargs,
161
+ },
162
+ stream=True,
163
+ )
164
+
165
+ self.assertEqual(response.status_code, 200, f"Failed with: {response.text}")
166
+
167
+ has_reasoning = False
168
+ has_content = False
169
+
170
+ print("\n=== Stream Without Reasoning ===")
171
+ for line in response.iter_lines():
172
+ if line:
173
+ line = line.decode("utf-8")
174
+ if line.startswith("data:") and not line.startswith("data: [DONE]"):
175
+ data = json.loads(line[6:])
176
+ if "choices" in data and len(data["choices"]) > 0:
177
+ delta = data["choices"][0].get("delta", {})
178
+
179
+ if "reasoning_content" in delta and delta["reasoning_content"]:
180
+ has_reasoning = True
181
+
182
+ if "content" in delta and delta["content"]:
183
+ has_content = True
184
+
185
+ self.assertFalse(
186
+ has_reasoning,
187
+ "The reasoning content should not be included in the stream response",
188
+ )
189
+ self.assertTrue(
190
+ has_content, "The stream response does not contain normal content"
191
+ )
192
+
193
+
194
+ if __name__ == "__main__":
195
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_matched_stop.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import unittest
3
+
4
+ import requests
5
+
6
+ from sglang.srt.utils import kill_process_tree
7
+ from sglang.test.ascend.test_ascend_utils import LLAMA_3_1_8B_INSTRUCT_WEIGHTS_PATH
8
+ from sglang.test.ci.ci_register import register_npu_ci
9
+ from sglang.test.test_utils import (
10
+ DEFAULT_URL_FOR_TEST,
11
+ CustomTestCase,
12
+ popen_launch_server,
13
+ )
14
+
15
+ MANY_NEW_TOKENS_PROMPT = """
16
+ Please write an extremely detailed and vivid fantasy story, set in a world full of intricate magic systems, political intrigue, and complex characters.
17
+ Ensure that you thoroughly describe every scene, character's motivations, and the environment. Include long, engaging dialogues and elaborate on the inner thoughts of the characters.
18
+ Each section should be as comprehensive as possible to create a rich and immersive experience for the reader.
19
+ The story should span multiple events, challenges, and character developments over time. Aim to make the story at least 3,000 words long.
20
+ """
21
+
22
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
23
+
24
+
25
+ class TestMatchedStop(CustomTestCase):
26
+ """Testcase: Test configuring 'matched_stop' to different values(string, EOS token, length) correctly identifies
27
+ it as a stop signal.
28
+
29
+ [Test Category] Interface
30
+ [Test Target] /v1/chat/completions; /v1/completions
31
+ """
32
+
33
+ @classmethod
34
+ def setUpClass(cls):
35
+ cls.model = LLAMA_3_1_8B_INSTRUCT_WEIGHTS_PATH
36
+ cls.base_url = DEFAULT_URL_FOR_TEST
37
+ cls.other_args = [
38
+ "--max-running-requests",
39
+ 10,
40
+ "--attention-backend",
41
+ "ascend",
42
+ "--disable-cuda-graph",
43
+ "--mem-fraction-static",
44
+ 0.8,
45
+ ]
46
+ cls.process = popen_launch_server(
47
+ cls.model, cls.base_url, timeout=300, other_args=cls.other_args
48
+ )
49
+
50
+ @classmethod
51
+ def tearDownClass(cls):
52
+ kill_process_tree(cls.process.pid)
53
+
54
+ def run_completions_generation(
55
+ self,
56
+ prompt=MANY_NEW_TOKENS_PROMPT,
57
+ max_tokens=1,
58
+ stop=None,
59
+ finish_reason=None,
60
+ matched_stop=None,
61
+ ):
62
+ # Configure matched_stop to None, and use the '/v1/completions' interface
63
+ # verify that the actual termination reason matches the configured value.
64
+ payload = {
65
+ "prompt": prompt,
66
+ "model": self.model,
67
+ "temperature": 0,
68
+ "top_p": 1,
69
+ "max_tokens": max_tokens,
70
+ }
71
+
72
+ if stop is not None:
73
+ payload["stop"] = stop
74
+
75
+ response_completions = requests.post(
76
+ self.base_url + "/v1/completions",
77
+ json=payload,
78
+ )
79
+ print(json.dumps(response_completions.json()))
80
+ print("=" * 100)
81
+
82
+ assert (
83
+ response_completions.json()["choices"][0]["finish_reason"] == finish_reason
84
+ )
85
+ assert response_completions.json()["choices"][0]["matched_stop"] == matched_stop
86
+
87
+ def run_chat_completions_generation(
88
+ self,
89
+ prompt=MANY_NEW_TOKENS_PROMPT,
90
+ max_tokens=1,
91
+ stop=None,
92
+ finish_reason=None,
93
+ matched_stop=None,
94
+ ):
95
+ # Configure matched_stop to None, and use the '/v1/chat/completions' interface
96
+ # verify that the actual termination reason matches the configured value.
97
+ chat_payload = {
98
+ "model": self.model,
99
+ "messages": [
100
+ {"role": "system", "content": "You are a helpful AI assistant"},
101
+ {"role": "user", "content": prompt},
102
+ ],
103
+ "temperature": 0,
104
+ "top_p": 1,
105
+ "max_tokens": max_tokens,
106
+ }
107
+
108
+ if stop is not None:
109
+ chat_payload["stop"] = stop
110
+
111
+ response_chat = requests.post(
112
+ self.base_url + "/v1/chat/completions",
113
+ json=chat_payload,
114
+ )
115
+ print(json.dumps(response_chat.json()))
116
+ print("=" * 100)
117
+
118
+ assert response_chat.json()["choices"][0]["finish_reason"] == finish_reason
119
+ assert response_chat.json()["choices"][0]["matched_stop"] == matched_stop
120
+
121
+ def test_finish_stop_str(self):
122
+ # Setting finish_reason="stop",'matched_stop="\n"' allows for correct termination
123
+ self.run_completions_generation(
124
+ max_tokens=1000, stop="\n", finish_reason="stop", matched_stop="\n"
125
+ )
126
+ self.run_chat_completions_generation(
127
+ max_tokens=1000, stop="\n", finish_reason="stop", matched_stop="\n"
128
+ )
129
+
130
+ def test_finish_stop_eos(self):
131
+ # Setting matched_stop is a specific EOS end flagallows for correct identification and termination of signal
132
+ llama_format_prompt = """
133
+ <|begin_of_text|><|start_header_id|>system<|end_header_id|>
134
+ You are a helpful assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>
135
+
136
+ What is 2 + 2?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
137
+ """
138
+ eos_token_id = 128009
139
+ self.run_completions_generation(
140
+ prompt=llama_format_prompt,
141
+ max_tokens=1000,
142
+ finish_reason="stop",
143
+ matched_stop=eos_token_id,
144
+ )
145
+ self.run_chat_completions_generation(
146
+ prompt="What is 2 + 2?",
147
+ max_tokens=1000,
148
+ finish_reason="stop",
149
+ matched_stop=eos_token_id,
150
+ )
151
+
152
+ def test_finish_length(self):
153
+ # Setting finish_reason="length",'matched_stop="\n"' allows for correct termination
154
+ self.run_completions_generation(
155
+ max_tokens=5, finish_reason="length", matched_stop=None
156
+ )
157
+ self.run_chat_completions_generation(
158
+ max_tokens=5, finish_reason="length", matched_stop=None
159
+ )
160
+
161
+
162
+ if __name__ == "__main__":
163
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_openai_function_calling.py ADDED
@@ -0,0 +1,940 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import unittest
3
+
4
+ import openai
5
+
6
+ from sglang.srt.utils import kill_process_tree
7
+ from sglang.srt.utils.hf_transformers_utils import get_tokenizer
8
+ from sglang.test.ascend.test_ascend_utils import LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
9
+ from sglang.test.ci.ci_register import register_npu_ci
10
+ from sglang.test.test_utils import (
11
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
12
+ DEFAULT_URL_FOR_TEST,
13
+ CustomTestCase,
14
+ popen_launch_server,
15
+ )
16
+
17
+ register_npu_ci(
18
+ est_time=400,
19
+ suite="nightly-1-npu-a3",
20
+ nightly=True,
21
+ )
22
+
23
+
24
+ class TestOpenAIServerFunctionCalling(CustomTestCase):
25
+ """Testcase:Verify the correctness of full-scenario OpenAI-style function calling with llama3 parser for Llama-3.2-1B-Instruct model.
26
+ Cover: Single/multi-turn calls, streaming/non-streaming returns, multi-parameter verification of tool_choice, and JSON parsing validity of function parameters.
27
+
28
+ [Test Category] Interface
29
+ [Test Target] /v1/chat/completions
30
+ """
31
+
32
+ # NOTE: this system_message is for Llama3.2 system prompt. Without this,
33
+ # sometimes Llama3.2 gives a different tool call format such as:
34
+ # '<|python_tag|>{"type": "function", "function": "add", "parameters": {"a": "3", "b": "5"}}'
35
+ SYSTEM_MESSAGE = (
36
+ "You are a helpful assistant with tool calling capabilities. "
37
+ "Only reply with a tool call if the function exists in the library provided by the user. "
38
+ "If it doesn't exist, just reply directly in natural language. "
39
+ "When you receive a tool call response, use the output to format an answer to the original user question. "
40
+ "You have access to the following functions. "
41
+ "To call a function, please respond with JSON for a function call. "
42
+ 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}. '
43
+ "Do not use variables.\n\n"
44
+ )
45
+
46
+ @classmethod
47
+ def setUpClass(cls):
48
+ # Replace with the model name needed for testing
49
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
50
+ cls.base_url = DEFAULT_URL_FOR_TEST
51
+ cls.api_key = "sk-123456"
52
+
53
+ # Start the local OpenAI Server. If necessary, you can add other parameters such as --enable-tools.
54
+ cls.process = popen_launch_server(
55
+ cls.model,
56
+ cls.base_url,
57
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
58
+ api_key=cls.api_key,
59
+ other_args=[
60
+ # If your server needs extra parameters to test function calling, please add them here.
61
+ "--attention-backend",
62
+ "ascend",
63
+ "--disable-cuda-graph",
64
+ "--tool-call-parser",
65
+ "llama3",
66
+ ],
67
+ )
68
+ cls.base_url += "/v1"
69
+ cls.tokenizer = get_tokenizer(cls.model)
70
+
71
+ @classmethod
72
+ def tearDownClass(cls):
73
+ kill_process_tree(cls.process.pid)
74
+
75
+ def test_function_calling_format(self):
76
+ """
77
+ Test: Whether the function call format returned by the AI is correct.
78
+ When returning a tool call, message.content should be None, and tool_calls should be a list.
79
+ """
80
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
81
+
82
+ tools = [
83
+ {
84
+ "type": "function",
85
+ "function": {
86
+ "name": "add",
87
+ "description": "Compute the sum of two numbers",
88
+ "parameters": {
89
+ "type": "object",
90
+ "properties": {
91
+ "a": {
92
+ "type": "integer",
93
+ "description": "A number",
94
+ },
95
+ "b": {
96
+ "type": "integer",
97
+ "description": "A number",
98
+ },
99
+ },
100
+ "required": ["a", "b"],
101
+ },
102
+ },
103
+ }
104
+ ]
105
+
106
+ messages = [
107
+ {"role": "system", "content": self.SYSTEM_MESSAGE},
108
+ {"role": "user", "content": "Compute (3+5)"},
109
+ ]
110
+ response = client.chat.completions.create(
111
+ model=self.model,
112
+ max_tokens=2048,
113
+ messages=messages,
114
+ temperature=0.8,
115
+ top_p=0.8,
116
+ stream=False,
117
+ tools=tools,
118
+ )
119
+
120
+ tool_calls = response.choices[0].message.tool_calls
121
+
122
+ assert (
123
+ isinstance(tool_calls, list) and len(tool_calls) > 0
124
+ ), "tool_calls should be a non-empty list"
125
+
126
+ function_name = tool_calls[0].function.name
127
+ assert function_name == "add", "Function name should be 'add'"
128
+
129
+ # This unit test is too difficult for default model. Mark it as optional unit tests so it won't trigger unless specified.
130
+ def _test_function_calling_multiturn(self):
131
+ """
132
+ Test: Whether the function call format returned by the AI is correct.
133
+ When returning a tool call, message.content should be None, and tool_calls should be a list.
134
+ """
135
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
136
+
137
+ tools = [
138
+ {
139
+ "type": "function",
140
+ "function": {
141
+ "name": "add",
142
+ "description": "Compute the sum of two numbers",
143
+ "parameters": {
144
+ "type": "object",
145
+ "properties": {
146
+ "a": {
147
+ "type": "integer",
148
+ "description": "A number",
149
+ },
150
+ "b": {
151
+ "type": "integer",
152
+ "description": "A number",
153
+ },
154
+ },
155
+ "required": ["a", "b"],
156
+ },
157
+ },
158
+ }
159
+ ]
160
+
161
+ messages = [{"role": "user", "content": "Compute (3+5)"}]
162
+
163
+ response = client.chat.completions.create(
164
+ model=self.model,
165
+ max_tokens=2048,
166
+ messages=messages,
167
+ temperature=0.8,
168
+ top_p=0.8,
169
+ stream=False,
170
+ tools=tools,
171
+ )
172
+
173
+ tool_call = response.choices[0].message.tool_calls[0]
174
+ function_name = tool_call.function.name
175
+ assert function_name == "add", "Function name should be 'add'"
176
+ function_arguments = json.loads(tool_call.function.arguments)
177
+ assert function_arguments in [
178
+ {"a": 3, "b": 5},
179
+ {"a": "3", "b": "5"},
180
+ ], f"Unexpected function arguments: {function_arguments}"
181
+
182
+ messages.append(response.choices[0].message)
183
+ messages.append(
184
+ {
185
+ "role": "tool",
186
+ "tool_call_id": tool_call.id,
187
+ "content": "8",
188
+ "name": function_name,
189
+ }
190
+ )
191
+
192
+ final_response = client.chat.completions.create(
193
+ model=self.model,
194
+ max_tokens=2048,
195
+ messages=messages,
196
+ temperature=0.8,
197
+ top_p=0.8,
198
+ stream=False,
199
+ tools=tools,
200
+ )
201
+
202
+ assert (
203
+ "8" in final_response.choices[0].message.content
204
+ ), "tool_call response should have the sum 8 in the content"
205
+
206
+ def test_function_calling_streaming_simple(self):
207
+ """
208
+ Test: Whether the function name can be correctly recognized in streaming mode.
209
+ - Expect a function call to be found, and the function name to be correct.
210
+ - Verify that streaming mode returns at least multiple chunks.
211
+ """
212
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
213
+
214
+ tools = [
215
+ {
216
+ "type": "function",
217
+ "function": {
218
+ "name": "get_current_weather",
219
+ "description": "Get the current weather in a given location",
220
+ "parameters": {
221
+ "type": "object",
222
+ "properties": {
223
+ "city": {
224
+ "type": "string",
225
+ "description": "The city to find the weather for",
226
+ },
227
+ "unit": {
228
+ "type": "string",
229
+ "description": "Weather unit (celsius or fahrenheit)",
230
+ "enum": ["celsius", "fahrenheit"],
231
+ },
232
+ },
233
+ "required": ["city", "unit"],
234
+ },
235
+ },
236
+ }
237
+ ]
238
+
239
+ messages = [
240
+ {"role": "system", "content": self.SYSTEM_MESSAGE},
241
+ {
242
+ "role": "user",
243
+ "content": "What is the temperature in Paris in celsius??",
244
+ },
245
+ ]
246
+
247
+ response_stream = client.chat.completions.create(
248
+ model=self.model,
249
+ max_tokens=2048,
250
+ messages=messages,
251
+ temperature=0.8,
252
+ top_p=0.8,
253
+ stream=True,
254
+ tools=tools,
255
+ )
256
+
257
+ chunks = list(response_stream)
258
+ self.assertTrue(len(chunks) > 0, "Streaming should return at least one chunk")
259
+
260
+ found_function_name = False
261
+ for chunk in chunks:
262
+ choice = chunk.choices[0]
263
+ # Check whether the current chunk contains tool_calls
264
+ if choice.delta.tool_calls:
265
+ tool_call = choice.delta.tool_calls[0]
266
+ if tool_call.function.name:
267
+ self.assertEqual(
268
+ tool_call.function.name,
269
+ "get_current_weather",
270
+ "Function name should be 'get_current_weather'",
271
+ )
272
+ found_function_name = True
273
+ break
274
+
275
+ self.assertTrue(
276
+ found_function_name,
277
+ "Target function name 'get_current_weather' was not found in the streaming chunks",
278
+ )
279
+
280
+ finish_reason = chunks[-1].choices[0].finish_reason
281
+ self.assertEqual(
282
+ finish_reason,
283
+ "tool_calls",
284
+ "Final response of function calling should have finish_reason 'tool_calls'",
285
+ )
286
+
287
+ def test_function_calling_streaming_args_parsing(self):
288
+ """
289
+ Test: Whether the function call arguments returned in streaming mode can be correctly concatenated into valid JSON.
290
+ - The user request requires multiple parameters.
291
+ - AI may return the arguments in chunks that need to be concatenated.
292
+ """
293
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
294
+
295
+ tools = [
296
+ {
297
+ "type": "function",
298
+ "function": {
299
+ "name": "add",
300
+ "description": "Compute the sum of two integers",
301
+ "parameters": {
302
+ "type": "object",
303
+ "properties": {
304
+ "a": {
305
+ "type": "integer",
306
+ "description": "First integer",
307
+ },
308
+ "b": {
309
+ "type": "integer",
310
+ "description": "Second integer",
311
+ },
312
+ },
313
+ "required": ["a", "b"],
314
+ },
315
+ "strict": True, # Llama-3.2-1B is flaky in tool call. It won't always respond with parameters unless we set strict.
316
+ },
317
+ }
318
+ ]
319
+
320
+ messages = [
321
+ {"role": "system", "content": self.SYSTEM_MESSAGE},
322
+ {"role": "user", "content": "Please sum 5 and 7, just call the function."},
323
+ ]
324
+
325
+ response_stream = client.chat.completions.create(
326
+ model=self.model,
327
+ max_tokens=2048,
328
+ messages=messages,
329
+ temperature=0.9,
330
+ top_p=0.9,
331
+ stream=True,
332
+ tools=tools,
333
+ )
334
+
335
+ argument_fragments = []
336
+ chunks = list(response_stream)
337
+ function_name = None
338
+ for chunk in chunks:
339
+ choice = chunk.choices[0]
340
+ if choice.delta.tool_calls:
341
+ tool_call = choice.delta.tool_calls[0]
342
+ # Record the function name on first occurrence
343
+ function_name = tool_call.function.name or function_name
344
+ # In case of multiple chunks, JSON fragments may need to be concatenated
345
+ if tool_call.function.arguments is not None:
346
+ argument_fragments.append(tool_call.function.arguments)
347
+
348
+ self.assertEqual(function_name, "add", "Function name should be 'add'")
349
+ joined_args = "".join(argument_fragments)
350
+ self.assertTrue(
351
+ len(joined_args) > 0,
352
+ "No parameter fragments were returned in the function call",
353
+ )
354
+
355
+ finish_reason = chunks[-1].choices[0].finish_reason
356
+ self.assertEqual(
357
+ finish_reason,
358
+ "tool_calls",
359
+ "Final response of function calling should have finish_reason 'tool_calls'",
360
+ )
361
+
362
+ # Check whether the concatenated JSON is valid
363
+ try:
364
+ args_obj = json.loads(joined_args)
365
+ except json.JSONDecodeError:
366
+ self.fail(
367
+ "The concatenated tool call arguments are not valid JSON, parsing failed"
368
+ )
369
+
370
+ self.assertIn("a", args_obj, "Missing parameter 'a'")
371
+ self.assertIn("b", args_obj, "Missing parameter 'b'")
372
+ self.assertEqual(str(args_obj["a"]), "5", "Parameter a should be 5")
373
+ self.assertEqual(str(args_obj["b"]), "7", "Parameter b should be 7")
374
+
375
+ def test_function_call_strict(self):
376
+ """
377
+ Test: Whether the strict mode of function calling works as expected.
378
+ - When strict mode is enabled, the AI should not return a function call if the function name is not recognized.
379
+ """
380
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
381
+
382
+ tools = [
383
+ {
384
+ "type": "function",
385
+ "function": {
386
+ "name": "sub",
387
+ "description": "Compute the difference of two integers",
388
+ "parameters": {
389
+ "type": "object",
390
+ "properties": {
391
+ "int_a": {
392
+ "type": "integer",
393
+ "description": "First integer",
394
+ },
395
+ "int_b": {
396
+ "type": "integer",
397
+ "description": "Second integer",
398
+ },
399
+ },
400
+ "required": ["int_a", "int_b"],
401
+ },
402
+ "strict": True,
403
+ },
404
+ }
405
+ ]
406
+
407
+ messages = [
408
+ {"role": "user", "content": "Please compute 5 - 7, using your tool."}
409
+ ]
410
+ response = client.chat.completions.create(
411
+ model=self.model,
412
+ max_tokens=2048,
413
+ messages=messages,
414
+ temperature=0.8,
415
+ top_p=0.8,
416
+ stream=False,
417
+ tools=tools,
418
+ )
419
+
420
+ tool_calls = response.choices[0].message.tool_calls
421
+ function_name = tool_calls[0].function.name
422
+ arguments = tool_calls[0].function.arguments
423
+ args_obj = json.loads(arguments)
424
+
425
+ self.assertEqual(function_name, "sub", "Function name should be 'sub'")
426
+ self.assertEqual(str(args_obj["int_a"]), "5", "Parameter int_a should be 5")
427
+ self.assertEqual(str(args_obj["int_b"]), "7", "Parameter int_b should be 7")
428
+
429
+ def test_function_call_required(self):
430
+ """
431
+ Test: Whether tool_choice: "required" works as expected.
432
+ - When tool_choice == "required", the model MUST return one or more tool_calls.
433
+ - The model may choose ANY of the provided tools; we only verify that
434
+ a tool call exists and the selected name is among the candidates.
435
+ """
436
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
437
+
438
+ tools = [
439
+ {
440
+ "type": "function",
441
+ "function": {
442
+ "name": "sub",
443
+ "description": "Compute the difference of two integers",
444
+ "parameters": {
445
+ "type": "object",
446
+ "properties": {
447
+ "int_a": {
448
+ "type": "integer",
449
+ "description": "First integer",
450
+ },
451
+ "int_b": {
452
+ "type": "integer",
453
+ "description": "Second integer",
454
+ },
455
+ },
456
+ "required": ["int_a", "int_b"],
457
+ },
458
+ "strict": True,
459
+ },
460
+ },
461
+ {
462
+ "type": "function",
463
+ "function": {
464
+ "name": "get_weather",
465
+ "description": "use this to get latest weather information for a city given its name",
466
+ "parameters": {
467
+ "type": "object",
468
+ "properties": {
469
+ "city": {
470
+ "type": "string",
471
+ "description": "name of the city to get weather for",
472
+ }
473
+ },
474
+ "required": ["city"],
475
+ },
476
+ "strict": True,
477
+ },
478
+ },
479
+ ]
480
+
481
+ valid_tool_names = {t["function"]["name"] for t in tools}
482
+
483
+ messages = [{"role": "user", "content": "Tell me about Paris"}]
484
+ response = client.chat.completions.create(
485
+ model=self.model,
486
+ max_tokens=2048,
487
+ messages=messages,
488
+ temperature=0,
489
+ stream=False,
490
+ tools=tools,
491
+ tool_choice="required",
492
+ )
493
+
494
+ tool_calls = response.choices[0].message.tool_calls
495
+ self.assertIsNotNone(
496
+ tool_calls, "tool_choice='required' must produce tool_calls"
497
+ )
498
+ self.assertGreater(len(tool_calls), 0, "tool_calls list should be non-empty")
499
+
500
+ function_name = tool_calls[0].function.name
501
+ self.assertIn(
502
+ function_name,
503
+ valid_tool_names,
504
+ f"Function name '{function_name}' is not among the provided tools: {valid_tool_names}",
505
+ )
506
+
507
+ # Verify the arguments are parseable JSON
508
+ arguments = tool_calls[0].function.arguments
509
+ args_obj = json.loads(arguments)
510
+ self.assertIsInstance(
511
+ args_obj, dict, "Function arguments should be a JSON object"
512
+ )
513
+
514
+ def test_function_call_specific(self):
515
+ """
516
+ Test: Whether tool_choice: ToolChoice works as expected
517
+ - When tool_choice is a specific ToolChoice, the model should return one or more tool_calls.
518
+ """
519
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
520
+
521
+ tools = [
522
+ {
523
+ "type": "function",
524
+ "function": {
525
+ "name": "sub",
526
+ "description": "Compute the difference of two integers",
527
+ "parameters": {
528
+ "type": "object",
529
+ "properties": {
530
+ "int_a": {
531
+ "type": "integer",
532
+ "description": "First integer",
533
+ },
534
+ "int_b": {
535
+ "type": "integer",
536
+ "description": "Second integer",
537
+ },
538
+ },
539
+ "required": ["int_a", "int_b"],
540
+ },
541
+ "strict": True,
542
+ },
543
+ },
544
+ {
545
+ "type": "function",
546
+ "function": {
547
+ "name": "get_weather",
548
+ "description": "use this to get latest weather information for a city given its name",
549
+ "parameters": {
550
+ "type": "object",
551
+ "properties": {
552
+ "city": {
553
+ "type": "string",
554
+ "description": "name of the city to get weather for",
555
+ }
556
+ },
557
+ "required": ["city"],
558
+ },
559
+ "strict": True,
560
+ },
561
+ },
562
+ ]
563
+
564
+ messages = [{"role": "user", "content": "What is the capital of France?"}]
565
+ response = client.chat.completions.create(
566
+ model=self.model,
567
+ max_tokens=2048,
568
+ messages=messages,
569
+ temperature=0.8,
570
+ top_p=0.8,
571
+ stream=False,
572
+ tools=tools,
573
+ tool_choice={"type": "function", "function": {"name": "get_weather"}},
574
+ )
575
+
576
+ tool_calls = response.choices[0].message.tool_calls
577
+ self.assertIsNotNone(tool_calls, "No tool_calls in the response")
578
+ function_name = tool_calls[0].function.name
579
+ arguments = tool_calls[0].function.arguments
580
+ args_obj = json.loads(arguments)
581
+
582
+ self.assertEqual(
583
+ function_name, "get_weather", "Function name should be 'get_weather'"
584
+ )
585
+ self.assertIn("city", args_obj, "Function arguments should have 'city'")
586
+
587
+ def test_streaming_multiple_choices_finish_reason(self):
588
+ """
589
+ Test: Verify that each choice gets its own finish_reason chunk in streaming mode with n > 1.
590
+ This tests the fix for the bug where only the last index got a finish_reason chunk.
591
+ """
592
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
593
+
594
+ tools = [
595
+ {
596
+ "type": "function",
597
+ "function": {
598
+ "name": "get_current_weather",
599
+ "description": "Get the current weather in a given location",
600
+ "parameters": {
601
+ "type": "object",
602
+ "properties": {
603
+ "location": {
604
+ "type": "string",
605
+ "description": "The city and state, e.g. San Francisco, CA",
606
+ },
607
+ "unit": {
608
+ "type": "string",
609
+ "enum": ["celsius", "fahrenheit"],
610
+ },
611
+ },
612
+ "required": ["location"],
613
+ },
614
+ },
615
+ }
616
+ ]
617
+
618
+ messages = [
619
+ {"role": "user", "content": "What is the weather like in Los Angeles?"}
620
+ ]
621
+
622
+ # Request with n=2 to get multiple choices
623
+ response_stream = client.chat.completions.create(
624
+ model=self.model,
625
+ messages=messages,
626
+ max_tokens=2048,
627
+ temperature=0.8,
628
+ stream=True,
629
+ tools=tools,
630
+ tool_choice="required", # Force tool calls
631
+ n=2, # Multiple choices
632
+ )
633
+
634
+ chunks = list(response_stream)
635
+
636
+ # Track finish_reason chunks for each index
637
+ finish_reason_chunks = {}
638
+ for chunk in chunks:
639
+ if chunk.choices:
640
+ for choice in chunk.choices:
641
+ if choice.finish_reason is not None:
642
+ index = choice.index
643
+ if index not in finish_reason_chunks:
644
+ finish_reason_chunks[index] = []
645
+ finish_reason_chunks[index].append(choice.finish_reason)
646
+
647
+ # Verify we got finish_reason chunks for both indices
648
+ self.assertEqual(
649
+ len(finish_reason_chunks),
650
+ 2,
651
+ f"Expected finish_reason chunks for 2 indices, got {len(finish_reason_chunks)}",
652
+ )
653
+
654
+ # Verify both index 0 and 1 have finish_reason
655
+ self.assertIn(
656
+ 0, finish_reason_chunks, "Missing finish_reason chunk for index 0"
657
+ )
658
+ self.assertIn(
659
+ 1, finish_reason_chunks, "Missing finish_reason chunk for index 1"
660
+ )
661
+
662
+ # Verify the finish_reason is "tool_calls" since we forced tool calls
663
+ for index, reasons in finish_reason_chunks.items():
664
+ self.assertEqual(
665
+ reasons[-1], # Last finish_reason for this index
666
+ "tool_calls",
667
+ f"Expected finish_reason 'tool_calls' for index {index}, got {reasons[-1]}",
668
+ )
669
+
670
+ def test_function_calling_streaming_no_tool_call(self):
671
+ """
672
+ Test: Whether the finish_reason is stop in streaming mode when no tool call is given.
673
+ - Expect no function call to be found.
674
+ - Verify that finish_reason is stop
675
+ """
676
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
677
+
678
+ tools = [
679
+ {
680
+ "type": "function",
681
+ "function": {
682
+ "name": "get_current_weather",
683
+ "description": "Get the current weather in a given location",
684
+ "parameters": {
685
+ "type": "object",
686
+ "properties": {
687
+ "city": {
688
+ "type": "string",
689
+ "description": "The city to find the weather for",
690
+ },
691
+ "unit": {
692
+ "type": "string",
693
+ "description": "Weather unit (celsius or fahrenheit)",
694
+ "enum": ["celsius", "fahrenheit"],
695
+ },
696
+ },
697
+ "required": ["city", "unit"],
698
+ },
699
+ },
700
+ }
701
+ ]
702
+
703
+ messages = [{"role": "user", "content": "Who are you?"}]
704
+
705
+ response_stream = client.chat.completions.create(
706
+ model=self.model,
707
+ max_tokens=2048,
708
+ messages=messages,
709
+ temperature=0.8,
710
+ top_p=0.8,
711
+ stream=True,
712
+ tools=tools,
713
+ tool_choice="none",
714
+ )
715
+
716
+ chunks = list(response_stream)
717
+ self.assertTrue(len(chunks) > 0, "Streaming should return at least one chunk")
718
+
719
+ found_tool_call = False
720
+ for chunk in chunks:
721
+ choice = chunk.choices[0]
722
+ # Check whether the current chunk contains tool_calls
723
+ found_tool_call = choice.delta.tool_calls is not None
724
+
725
+ self.assertFalse(
726
+ found_tool_call,
727
+ "Shouldn't have any tool_call in the streaming chunks",
728
+ )
729
+
730
+ finish_reason = chunks[-1].choices[0].finish_reason
731
+ self.assertEqual(
732
+ finish_reason,
733
+ "stop",
734
+ "Final response of no function calling should have finish_reason 'stop'",
735
+ )
736
+
737
+ def test_streaming_multiple_choices_without_tools(self):
738
+ """
739
+ Test: Verify that each choice gets its own finish_reason chunk without tool calls.
740
+ This tests the fix for regular content streaming with multiple choices.
741
+ """
742
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
743
+
744
+ messages = [{"role": "user", "content": "Say hello in one word."}]
745
+
746
+ # Request with n=2 to get multiple choices, no tools
747
+ response_stream = client.chat.completions.create(
748
+ model=self.model,
749
+ messages=messages,
750
+ temperature=0.8,
751
+ stream=True,
752
+ max_tokens=10, # Keep it short
753
+ n=2, # Multiple choices
754
+ )
755
+
756
+ chunks = list(response_stream)
757
+
758
+ # Track finish_reason chunks for each index
759
+ finish_reason_chunks = {}
760
+ for chunk in chunks:
761
+ if chunk.choices:
762
+ for choice in chunk.choices:
763
+ if choice.finish_reason is not None:
764
+ index = choice.index
765
+ if index not in finish_reason_chunks:
766
+ finish_reason_chunks[index] = []
767
+ finish_reason_chunks[index].append(choice.finish_reason)
768
+
769
+ # Verify we got finish_reason chunks for both indices
770
+ self.assertEqual(
771
+ len(finish_reason_chunks),
772
+ 2,
773
+ f"Expected finish_reason chunks for 2 indices, got {len(finish_reason_chunks)}",
774
+ )
775
+
776
+ # Verify both index 0 and 1 have finish_reason
777
+ self.assertIn(
778
+ 0, finish_reason_chunks, "Missing finish_reason chunk for index 0"
779
+ )
780
+ self.assertIn(
781
+ 1, finish_reason_chunks, "Missing finish_reason chunk for index 1"
782
+ )
783
+
784
+ # Verify the finish_reason is "stop" (regular completion)
785
+ for index, reasons in finish_reason_chunks.items():
786
+ self.assertIn(
787
+ reasons[-1],
788
+ ["stop", "length"], # Could be either depending on how model responds
789
+ f"Expected finish_reason 'stop' or 'length' for index {index}, got {reasons[-1]}",
790
+ )
791
+
792
+
793
+ class TestOpenAIPythonicFunctionCalling(CustomTestCase):
794
+ """Testcase:Verify the functionality of Python-style list-format function calling with pythonic parser for Llama-3.2-1B-Instruct model on Ascend NPU backend.
795
+ Cover: Explicit format prompt verification, streaming call index integrity, and return validity of parallel tool calls.
796
+
797
+ [Test Category] Interface
798
+ [Test Target] /v1/chat/completions
799
+ """
800
+
801
+ PYTHONIC_TOOLS = [
802
+ {
803
+ "type": "function",
804
+ "function": {
805
+ "name": "get_weather",
806
+ "description": "Get the current weather for a given location.",
807
+ "parameters": {
808
+ "type": "object",
809
+ "properties": {
810
+ "location": {
811
+ "type": "string",
812
+ "description": "The name of the city or location.",
813
+ }
814
+ },
815
+ "required": ["location"],
816
+ },
817
+ },
818
+ },
819
+ {
820
+ "type": "function",
821
+ "function": {
822
+ "name": "get_tourist_attractions",
823
+ "description": "Get a list of top tourist attractions for a given city.",
824
+ "parameters": {
825
+ "type": "object",
826
+ "properties": {
827
+ "city": {
828
+ "type": "string",
829
+ "description": "The name of the city to find attractions for.",
830
+ }
831
+ },
832
+ "required": ["city"],
833
+ },
834
+ },
835
+ },
836
+ ]
837
+
838
+ PYTHONIC_MESSAGES = [
839
+ {
840
+ "role": "system",
841
+ "content": (
842
+ "You are a travel assistant. "
843
+ "When asked to call functions, ALWAYS respond ONLY with a python list of function calls, "
844
+ "using this format: [func_name1(param1=value1, param2=value2), func_name2(param=value)]. "
845
+ "Do NOT use JSON, do NOT use variables, do NOT use any other format. "
846
+ "Here is an example:\n"
847
+ '[get_weather(location="Paris"), get_tourist_attractions(city="Paris")]'
848
+ ),
849
+ },
850
+ {
851
+ "role": "user",
852
+ "content": (
853
+ "I'm planning a trip to Tokyo next week. What's the weather like and what are some top tourist attractions? "
854
+ "Propose parallel tool calls at once, using the python list of function calls format as shown above."
855
+ ),
856
+ },
857
+ ]
858
+
859
+ @classmethod
860
+ def setUpClass(cls):
861
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
862
+ cls.base_url = DEFAULT_URL_FOR_TEST
863
+ cls.api_key = "sk-123456"
864
+ cls.process = popen_launch_server(
865
+ cls.model,
866
+ cls.base_url,
867
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
868
+ api_key=cls.api_key,
869
+ other_args=[
870
+ "--attention-backend",
871
+ "ascend",
872
+ "--disable-cuda-graph",
873
+ "--tool-call-parser",
874
+ "pythonic",
875
+ ],
876
+ )
877
+ cls.base_url += "/v1"
878
+ cls.tokenizer = get_tokenizer(cls.model)
879
+
880
+ @classmethod
881
+ def tearDownClass(cls):
882
+ kill_process_tree(cls.process.pid)
883
+
884
+ def test_pythonic_tool_call_prompt(self):
885
+ """
886
+ Test: Explicit prompt for pythonic tool call format without chat template.
887
+ """
888
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
889
+ response = client.chat.completions.create(
890
+ model=self.model,
891
+ messages=self.PYTHONIC_MESSAGES,
892
+ tools=self.PYTHONIC_TOOLS,
893
+ temperature=0.1,
894
+ stream=False,
895
+ )
896
+ tool_calls = response.choices[0].message.tool_calls
897
+ self.assertIsInstance(tool_calls, list, "No tool_calls found")
898
+ self.assertGreaterEqual(len(tool_calls), 1)
899
+ names = [tc.function.name for tc in tool_calls]
900
+ self.assertTrue(
901
+ "get_weather" in names or "get_tourist_attractions" in names,
902
+ f"Function name '{names}' should container either 'get_weather' or 'get_tourist_attractions'",
903
+ )
904
+
905
+ def test_pythonic_tool_call_streaming(self):
906
+ """
907
+ Test: Streaming pythonic tool call format; assert tool_call index is present.
908
+ """
909
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
910
+ response_stream = client.chat.completions.create(
911
+ model=self.model,
912
+ messages=self.PYTHONIC_MESSAGES,
913
+ tools=self.PYTHONIC_TOOLS,
914
+ temperature=0.1,
915
+ stream=True,
916
+ )
917
+ found_tool_calls = False
918
+ found_index = False
919
+ found_names = set()
920
+ for chunk in response_stream:
921
+ choice = chunk.choices[0]
922
+ if getattr(choice.delta, "tool_calls", None):
923
+ found_tool_calls = True
924
+ tool_call = choice.delta.tool_calls[0]
925
+ if hasattr(tool_call, "index") or (
926
+ isinstance(tool_call, dict) and "index" in tool_call
927
+ ):
928
+ found_index = True
929
+ found_names.add(str(tool_call.function.name))
930
+
931
+ self.assertTrue(found_tool_calls, "No tool_calls found in streaming response")
932
+ self.assertTrue(found_index, "No index field found in any streamed tool_call")
933
+ self.assertTrue(
934
+ "get_weather" in found_names or "get_tourist_attractions" in found_names,
935
+ f"Function name '{found_names}' should container either 'get_weather' or 'get_tourist_attractions'",
936
+ )
937
+
938
+
939
+ if __name__ == "__main__":
940
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_openai_server_ignore_eos.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ import openai
4
+
5
+ from sglang.srt.utils import kill_process_tree
6
+ from sglang.srt.utils.hf_transformers_utils import get_tokenizer
7
+ from sglang.test.ascend.test_ascend_utils import LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
8
+ from sglang.test.ci.ci_register import register_npu_ci
9
+ from sglang.test.test_utils import (
10
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
11
+ DEFAULT_URL_FOR_TEST,
12
+ CustomTestCase,
13
+ popen_launch_server,
14
+ )
15
+
16
+ register_npu_ci(est_time=400, suite="nightly-2-npu-a3", nightly=True)
17
+
18
+
19
+ class TestOpenAIServerIgnoreEOS(CustomTestCase):
20
+ """Testcase: Test 'ignore_eos' is True, the EOS is ignored and continue reasoning
21
+
22
+ [Test Category] Interface
23
+ [Test Target] ignore_eos
24
+ """
25
+
26
+ @classmethod
27
+ def setUpClass(cls):
28
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
29
+ cls.base_url = DEFAULT_URL_FOR_TEST
30
+ cls.api_key = "sk-123456"
31
+ cls.other_args = [
32
+ "--attention-backend",
33
+ "ascend",
34
+ "--disable-cuda-graph",
35
+ ]
36
+ cls.process = popen_launch_server(
37
+ cls.model,
38
+ cls.base_url,
39
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
40
+ api_key=cls.api_key,
41
+ other_args=cls.other_args,
42
+ )
43
+ cls.base_url += "/v1"
44
+ cls.tokenizer = get_tokenizer(cls.model)
45
+
46
+ @classmethod
47
+ def tearDownClass(cls):
48
+ kill_process_tree(cls.process.pid)
49
+
50
+ def test_ignore_eos(self):
51
+ client = openai.Client(api_key=self.api_key, base_url=self.base_url)
52
+
53
+ max_tokens = 200
54
+
55
+ response_default = client.chat.completions.create(
56
+ model=self.model,
57
+ messages=[
58
+ {"role": "system", "content": "You are a helpful assistant."},
59
+ {"role": "user", "content": "Count from 1 to 20."},
60
+ ],
61
+ temperature=0,
62
+ max_tokens=max_tokens,
63
+ extra_body={"ignore_eos": False},
64
+ )
65
+
66
+ response_ignore_eos = client.chat.completions.create(
67
+ model=self.model,
68
+ messages=[
69
+ {"role": "system", "content": "You are a helpful assistant."},
70
+ {"role": "user", "content": "Count from 1 to 20."},
71
+ ],
72
+ temperature=0,
73
+ max_tokens=max_tokens,
74
+ extra_body={"ignore_eos": True},
75
+ )
76
+
77
+ default_tokens = len(
78
+ self.tokenizer.encode(response_default.choices[0].message.content)
79
+ )
80
+ ignore_eos_tokens = len(
81
+ self.tokenizer.encode(response_ignore_eos.choices[0].message.content)
82
+ )
83
+
84
+ # Check if ignore_eos resulted in more tokens or exactly max_tokens
85
+ # The ignore_eos response should either:
86
+ # 1. Have more tokens than the default response (if default stopped at EOS before max_tokens)
87
+ # 2. Have exactly max_tokens (if it reached the max_tokens limit)
88
+ self.assertTrue(
89
+ ignore_eos_tokens > default_tokens or ignore_eos_tokens >= max_tokens,
90
+ f"ignore_eos did not generate more tokens: {ignore_eos_tokens} vs {default_tokens}",
91
+ )
92
+
93
+ self.assertEqual(
94
+ response_ignore_eos.choices[0].finish_reason,
95
+ "length",
96
+ f"Expected finish_reason='length' for ignore_eos=True, got {response_ignore_eos.choices[0].finish_reason}",
97
+ )
98
+
99
+
100
+ if __name__ == "__main__":
101
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/interface/test_npu_penalty.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import random
3
+ import unittest
4
+ from concurrent.futures import ThreadPoolExecutor
5
+
6
+ import requests
7
+
8
+ from sglang.srt.utils import kill_process_tree
9
+ from sglang.test.ascend.test_ascend_utils import LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
10
+ from sglang.test.ci.ci_register import register_npu_ci
11
+ from sglang.test.test_utils import (
12
+ DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
13
+ DEFAULT_URL_FOR_TEST,
14
+ CustomTestCase,
15
+ popen_launch_server,
16
+ )
17
+
18
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
19
+
20
+
21
+ class TestPenalty(CustomTestCase):
22
+ """Testcase:Verify successful processing of inference requests with three specific mechanisms(frequency_penalty, presence_penalty, min_new_tokens).
23
+
24
+ [Test Category] Interface
25
+ [Test Target] /generate
26
+ """
27
+
28
+ @classmethod
29
+ def setUpClass(cls):
30
+ cls.model = LLAMA_3_2_1B_INSTRUCT_WEIGHTS_PATH
31
+ other_args = [
32
+ "--attention-backend",
33
+ "ascend",
34
+ "--disable-cuda-graph",
35
+ ]
36
+ cls.base_url = DEFAULT_URL_FOR_TEST
37
+ cls.process = popen_launch_server(
38
+ cls.model,
39
+ cls.base_url,
40
+ timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
41
+ other_args=other_args,
42
+ )
43
+
44
+ @classmethod
45
+ def tearDownClass(cls):
46
+ kill_process_tree(cls.process.pid)
47
+
48
+ def run_decode(self, sampling_params):
49
+ # Send inference request with specified sampling/penalty parameters.
50
+
51
+ return_logprob = True
52
+ top_logprobs_num = 5
53
+ return_text = True
54
+ n = 1
55
+
56
+ response = requests.post(
57
+ self.base_url + "/generate",
58
+ json={
59
+ # prompt that is supposed to generate < 32 tokens
60
+ "text": "<|start_header_id|>user<|end_header_id|>\n\nWhat is the answer for 1 + 1 = ?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
61
+ "sampling_params": {
62
+ "max_new_tokens": 48,
63
+ "n": n,
64
+ **sampling_params,
65
+ },
66
+ "return_logprob": return_logprob,
67
+ "top_logprobs_num": top_logprobs_num,
68
+ "return_text_in_logprobs": return_text,
69
+ "logprob_start_len": 0,
70
+ },
71
+ )
72
+ self.assertEqual(response.status_code, 200)
73
+ print(json.dumps(response.json()))
74
+ print("=" * 100)
75
+
76
+ def test_default_values(self):
77
+ self.run_decode({})
78
+
79
+ def test_frequency_penalty(self):
80
+ self.run_decode({"frequency_penalty": 2})
81
+
82
+ def test_min_new_tokens(self):
83
+ self.run_decode({"min_new_tokens": 16})
84
+
85
+ def test_presence_penalty(self):
86
+ self.run_decode({"presence_penalty": 2})
87
+
88
+ def test_penalty_mixed(self):
89
+ args = [
90
+ {},
91
+ {},
92
+ {},
93
+ {"frequency_penalty": 2},
94
+ {"presence_penalty": 1},
95
+ {"min_new_tokens": 16},
96
+ {"frequency_penalty": 0.2},
97
+ {"presence_penalty": 0.4},
98
+ {"min_new_tokens": 8},
99
+ {"frequency_penalty": 0.4, "presence_penalty": 0.8},
100
+ {"frequency_penalty": 0.4, "min_new_tokens": 12},
101
+ {"presence_penalty": 0.8, "min_new_tokens": 12},
102
+ {"presence_penalty": -0.3, "frequency_penalty": 1.3, "min_new_tokens": 32},
103
+ {"presence_penalty": 0.3, "frequency_penalty": -1.3, "min_new_tokens": 32},
104
+ ]
105
+ random.shuffle(args * 5)
106
+ with ThreadPoolExecutor(8) as executor:
107
+ list(executor.map(self.run_decode, args))
108
+
109
+
110
+ if __name__ == "__main__":
111
+ unittest.main(verbosity=3)
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_ascend_dbrx_instruct.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ci.ci_register import register_npu_ci
5
+ from sglang.test.test_utils import CustomTestCase
6
+
7
+ register_npu_ci(est_time=400, suite="nightly-8-npu-a3", nightly=True)
8
+
9
+
10
+ class TestDbrx(GSM8KAscendMixin, CustomTestCase):
11
+ model = "/root/.cache/modelscope/hub/models/AI-ModelScope/dbrx-instruct"
12
+ accuracy = 0.735
13
+ other_args = [
14
+ "--trust-remote-code",
15
+ "--mem-fraction-static",
16
+ "0.8",
17
+ "--attention-backend",
18
+ "ascend",
19
+ "--disable-cuda-graph",
20
+ "--tp-size",
21
+ "8",
22
+ ]
23
+
24
+
25
+ if __name__ == "__main__":
26
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_ascend_minimax_m2.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import MINIMAX_M2_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(
9
+ est_time=400,
10
+ suite="nightly-8-npu-a3",
11
+ nightly=True,
12
+ )
13
+
14
+
15
+ class TestMiniMaxM2(GSM8KAscendMixin, CustomTestCase):
16
+ """Testcase: Verify that the inference accuracy of the cyankiwi/MiniMax-M2-BF16 model on the GSM8K dataset is no less than 0.9.
17
+
18
+ [Test Category] Model
19
+ [Test Target] cyankiwi/MiniMax-M2-BF16
20
+ """
21
+
22
+ model = MINIMAX_M2_WEIGHTS_PATH
23
+ accuracy = 0.9
24
+ other_args = [
25
+ "--trust-remote-code",
26
+ "--mem-fraction-static",
27
+ "0.9",
28
+ "--attention-backend",
29
+ "ascend",
30
+ "--tp-size",
31
+ "8",
32
+ "--disable-cuda-graph",
33
+ "--disable-radix-cache",
34
+ "--disable-overlap-schedule",
35
+ "--max-running-requests",
36
+ "64",
37
+ "--chunked-prefill-size",
38
+ "-1",
39
+ ]
40
+ timeout_for_server_launch = 1800
41
+
42
+
43
+ if __name__ == "__main__":
44
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_ascend_trinity_mini.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import TRINITY_MINI_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(
9
+ est_time=400,
10
+ suite="nightly-2-npu-a3",
11
+ nightly=True,
12
+ )
13
+
14
+
15
+ class TestTrinityMini(GSM8KAscendMixin, CustomTestCase):
16
+ """Testcase: Verify that the inference accuracy of the arcee-ai/Trinity-Mini model on the GSM8K dataset is no less than 0.85.
17
+
18
+ [Test Category] Model
19
+ [Test Target] arcee-ai/Trinity-Mini
20
+ """
21
+
22
+ model = TRINITY_MINI_WEIGHTS_PATH
23
+ accuracy = 0.85
24
+ other_args = [
25
+ "--trust-remote-code",
26
+ "--mem-fraction-static",
27
+ "0.8",
28
+ "--attention-backend",
29
+ "ascend",
30
+ "--tp-size",
31
+ "2",
32
+ "--disable-cuda-graph",
33
+ "--disable-radix-cache",
34
+ "--disable-overlap-schedule",
35
+ "--context-length",
36
+ "4096",
37
+ "--max-running-requests",
38
+ "128",
39
+ "--chunked-prefill-size",
40
+ "-1",
41
+ "--chat-template",
42
+ f"{model}/chat_template.jinja",
43
+ ]
44
+
45
+
46
+ if __name__ == "__main__":
47
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_afm_4_5b.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import AFM_4_5B_BASE_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="full-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestAFM(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the arcee-ai/AFM-4.5B-Base model on the GSM8K dataset is no less than 0.375.
13
+
14
+ [Test Category] Model
15
+ [Test Target] arcee-ai/AFM-4.5B-Base
16
+ """
17
+
18
+ model = AFM_4_5B_BASE_WEIGHTS_PATH
19
+ accuracy = 0.375
20
+
21
+
22
+ if __name__ == "__main__":
23
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_baichuan2_13b_chat.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import BAICHUAN2_13B_CHAT_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestBaichuan(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the baichuan-inc/Baichuan2-13B-Chat model on the GSM8K dataset is no less than 0.48.
13
+
14
+ [Test Category] Model
15
+ [Test Target] baichuan-inc/Baichuan2-13B-Chat
16
+ """
17
+
18
+ model = BAICHUAN2_13B_CHAT_WEIGHTS_PATH
19
+ accuracy = 0.48
20
+ other_args = [
21
+ "--trust-remote-code",
22
+ "--mem-fraction-static",
23
+ "0.8",
24
+ "--attention-backend",
25
+ "ascend",
26
+ "--disable-cuda-graph",
27
+ "--max-running-requests",
28
+ "128",
29
+ "--disable-radix-cache",
30
+ "--chunked-prefill-size",
31
+ "-1",
32
+ ]
33
+ gsm8k_num_shots = 1
34
+
35
+
36
+ if __name__ == "__main__":
37
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_c4ai_command_r_v01.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import (
5
+ C4AI_COMMAND_R_V01_CHAT_TEMPLATE_PATH,
6
+ C4AI_COMMAND_R_V01_WEIGHTS_PATH,
7
+ )
8
+ from sglang.test.ci.ci_register import register_npu_ci
9
+ from sglang.test.test_utils import CustomTestCase
10
+
11
+ register_npu_ci(est_time=400, suite="full-2-npu-a3", nightly=True)
12
+
13
+
14
+ class TestC4AI(GSM8KAscendMixin, CustomTestCase):
15
+ """Testcase: Verify that the inference accuracy of the CohereForAI/c4ai-command-r-v01 model on the GSM8K dataset is no less than 0.55.
16
+
17
+ [Test Category] Model
18
+ [Test Target] CohereForAI/c4ai-command-r-v01
19
+ """
20
+
21
+ model = C4AI_COMMAND_R_V01_WEIGHTS_PATH
22
+ accuracy = 0.55
23
+ other_args = [
24
+ "--trust-remote-code",
25
+ "--mem-fraction-static",
26
+ "0.8",
27
+ "--attention-backend",
28
+ "ascend",
29
+ "--disable-cuda-graph",
30
+ "--chat-template",
31
+ C4AI_COMMAND_R_V01_CHAT_TEMPLATE_PATH,
32
+ "--tp-size",
33
+ "2",
34
+ "--dtype",
35
+ "bfloat16",
36
+ ]
37
+
38
+
39
+ if __name__ == "__main__":
40
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_chatglm2_6b.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import CHATGLM2_6B_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestChatGlm2(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the ZhipuAI/chatglm2-6b model on the GSM8K dataset is no less than 0.25.
13
+
14
+ [Test Category] Model
15
+ [Test Target] ZhipuAI/chatglm2-6b
16
+ """
17
+
18
+ model = CHATGLM2_6B_WEIGHTS_PATH
19
+ accuracy = 0.25
20
+ other_args = [
21
+ "--trust-remote-code",
22
+ "--mem-fraction-static",
23
+ "0.8",
24
+ "--attention-backend",
25
+ "ascend",
26
+ "--disable-cuda-graph",
27
+ "--dtype",
28
+ "bfloat16",
29
+ ]
30
+
31
+
32
+ if __name__ == "__main__":
33
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_deepseek_v3_2_exp_w8a8.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import DEEPSEEK_V3_2_EXP_W8A8_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-16-npu-a3", nightly=True)
9
+
10
+
11
+ class TestDeepSeekV32(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the vllm-ascend/DeepSeek-V3.2-Exp-W8A8 model on the GSM8K dataset is no less than 0.5.
13
+
14
+ [Test Category] Model
15
+ [Test Target] vllm-ascend/DeepSeek-V3.2-Exp-W8A8
16
+ """
17
+
18
+ model = DEEPSEEK_V3_2_EXP_W8A8_WEIGHTS_PATH
19
+ accuracy = 0.5
20
+ timeout_for_server_launch = 3000
21
+ other_args = [
22
+ "--trust-remote-code",
23
+ "--mem-fraction-static",
24
+ "0.9",
25
+ "--attention-backend",
26
+ "ascend",
27
+ "--disable-cuda-graph",
28
+ "--tp-size",
29
+ "16",
30
+ "--quantization",
31
+ "modelslim",
32
+ "--disable-radix-cache",
33
+ ]
34
+
35
+
36
+ if __name__ == "__main__":
37
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_exaone_3.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import EXAONE_3_5_7_8B_INSTRUCT_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="full-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestEXAONE(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the LGAI-EXAONE/EXAONE-3.5-7.8B-Instruct model on the GSM8K dataset is no less than 0.8.
13
+
14
+ [Test Category] Model
15
+ [Test Target] LGAI-EXAONE/EXAONE-3.5-7.8B-Instruct
16
+ """
17
+
18
+ model = EXAONE_3_5_7_8B_INSTRUCT_WEIGHTS_PATH
19
+ # Allow 1% tolerance for the accuracy threshold
20
+ accuracy = round(0.8 * 0.99, 3)
21
+ other_args = [
22
+ "--trust-remote-code",
23
+ "--mem-fraction-static",
24
+ "0.8",
25
+ "--attention-backend",
26
+ "ascend",
27
+ "--disable-cuda-graph",
28
+ "--dtype",
29
+ "bfloat16",
30
+ ]
31
+
32
+
33
+ if __name__ == "__main__":
34
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_gemma_3_4b_it_llm.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import GEMMA_3_4B_IT_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(
9
+ est_time=400,
10
+ suite="nightly-1-npu-a3",
11
+ nightly=True,
12
+ )
13
+
14
+
15
+ class TestGemma34B(GSM8KAscendMixin, CustomTestCase):
16
+ """Testcase: Verify that the inference accuracy of the google/gemma-3-4b-it model on the GSM8K dataset is no less than 0.7.
17
+
18
+ [Test Category] Model
19
+ [Test Target] google/gemma-3-4b-it
20
+ """
21
+
22
+ model = GEMMA_3_4B_IT_WEIGHTS_PATH
23
+ accuracy = 0.7
24
+ other_args = [
25
+ "--trust-remote-code",
26
+ "--mem-fraction-static",
27
+ "0.8",
28
+ "--attention-backend",
29
+ "ascend",
30
+ "--disable-cuda-graph",
31
+ "--disable-radix-cache",
32
+ "--chunked-prefill-size",
33
+ "-1",
34
+ ]
35
+
36
+
37
+ if __name__ == "__main__":
38
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_glm4_9b_chat.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import GLM_4_9B_CHAT_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(
9
+ est_time=400,
10
+ suite="nightly-1-npu-a3",
11
+ nightly=True,
12
+ )
13
+
14
+
15
+ class TestGLM49BChat(GSM8KAscendMixin, CustomTestCase):
16
+ """Testcase: Verify that the inference accuracy of the ZhipuAI/glm-4-9b-chat model on the GSM8K dataset is no less than 0.77.
17
+
18
+ [Test Category] Model
19
+ [Test Target] ZhipuAI/glm-4-9b-chat
20
+ """
21
+
22
+ model = GLM_4_9B_CHAT_WEIGHTS_PATH
23
+ accuracy = 0.77
24
+
25
+
26
+ if __name__ == "__main__":
27
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_granite_3_0_3b_a800m.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import (
5
+ GRANITE_3_0_3B_A800M_INSTRUCT_WEIGHTS_PATH,
6
+ )
7
+ from sglang.test.ci.ci_register import register_npu_ci
8
+ from sglang.test.test_utils import CustomTestCase
9
+
10
+ register_npu_ci(est_time=400, suite="full-1-npu-a3", nightly=True)
11
+
12
+
13
+ class TestGranite(GSM8KAscendMixin, CustomTestCase):
14
+ """Testcase: Verify that the inference accuracy of the ibm-granite/granite-3.0-3b-a800m-instruct model on the GSM8K dataset is no less than 0.38.
15
+
16
+ [Test Category] Model
17
+ [Test Target] ibm-granite/granite-3.0-3b-a800m-instruct
18
+ """
19
+
20
+ model = GRANITE_3_0_3B_A800M_INSTRUCT_WEIGHTS_PATH
21
+ accuracy = 0.38
22
+
23
+
24
+ if __name__ == "__main__":
25
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_granite_3_1_8b.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import GRANITE_3_1_8B_INSTRUCT_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="full-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestGranite(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the ibm-granite/granite-3.1-8b-instruct model on the GSM8K dataset is no less than 0.695.
13
+
14
+ [Test Category] Model
15
+ [Test Target] ibm-granite/granite-3.1-8b-instruct
16
+ """
17
+
18
+ model = GRANITE_3_1_8B_INSTRUCT_WEIGHTS_PATH
19
+ accuracy = 0.695
20
+
21
+
22
+ if __name__ == "__main__":
23
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_grok_2.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ci.ci_register import register_npu_ci
5
+ from sglang.test.test_utils import CustomTestCase
6
+
7
+ register_npu_ci(
8
+ est_time=400,
9
+ suite="full-16-npu-a3",
10
+ nightly=True,
11
+ )
12
+
13
+
14
+ class TestGrok2(GSM8KAscendMixin, CustomTestCase):
15
+ model = "/root/.cache/modelscope/hub/models/huihui-ai/grok-2"
16
+ accuracy = 0.91
17
+ other_args = [
18
+ "--trust-remote-code",
19
+ "--mem-fraction-static",
20
+ "0.8",
21
+ "--attention-backend",
22
+ "ascend",
23
+ "--disable-radix-cache",
24
+ "--disable-cuda-graph",
25
+ "--tokenizer-path",
26
+ "/root/.cache/modelscope/hub/models/huihui-ai/grok-2/tokenizer.tok.json",
27
+ "--tp-size",
28
+ "16",
29
+ ]
30
+
31
+
32
+ if __name__ == "__main__":
33
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_internlm2_7b.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import unittest
3
+
4
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
5
+ from sglang.test.ascend.test_ascend_utils import INTERNLM2_7B_WEIGHTS_PATH
6
+ from sglang.test.ci.ci_register import register_npu_ci
7
+ from sglang.test.test_utils import CustomTestCase
8
+
9
+ register_npu_ci(
10
+ est_time=400,
11
+ suite="nightly-1-npu-a3",
12
+ nightly=True,
13
+ )
14
+
15
+
16
+ class TestInternlm2(GSM8KAscendMixin, CustomTestCase):
17
+ """Testcase: Verify that the inference accuracy of the Shanghai_AI_Laboratory/internlm2-7b model on the GSM8K dataset is no less than 0.585.
18
+
19
+ [Test Category] Model
20
+ [Test Target] Shanghai_AI_Laboratory/internlm2-7b
21
+ """
22
+
23
+ os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
24
+ model = INTERNLM2_7B_WEIGHTS_PATH
25
+ accuracy = 0.585
26
+
27
+
28
+ if __name__ == "__main__":
29
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_ling_lite.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import LING_LITE_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="full-2-npu-a3", nightly=True)
9
+
10
+
11
+ class TestLingLite(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the inclusionAI/Ling-lite model on the GSM8K dataset is no less than 0.75.
13
+
14
+ [Test Category] Model
15
+ [Test Target] inclusionAI/Ling-lite
16
+ """
17
+
18
+ model = LING_LITE_WEIGHTS_PATH
19
+ accuracy = 0.75
20
+ other_args = [
21
+ "--trust-remote-code",
22
+ "--mem-fraction-static",
23
+ "0.8",
24
+ "--attention-backend",
25
+ "ascend",
26
+ "--disable-cuda-graph",
27
+ "--tp-size",
28
+ "2",
29
+ ]
30
+
31
+
32
+ if __name__ == "__main__":
33
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_llama4_scount_17b_16e.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import (
5
+ LLAMA_4_SCOUT_17B_16E_INSTRUCT_WEIGHTS_PATH,
6
+ )
7
+ from sglang.test.ci.ci_register import register_npu_ci
8
+ from sglang.test.test_utils import CustomTestCase
9
+
10
+ register_npu_ci(est_time=400, suite="nightly-4-npu-a3", nightly=True)
11
+
12
+
13
+ class TestLlama4(GSM8KAscendMixin, CustomTestCase):
14
+ """Testcase: Verify that the inference accuracy of the meta-llama/Llama-4-Scout-17B-16E-Instruct model on the GSM8K dataset is no less than 0.9.
15
+
16
+ [Test Category] Model
17
+ [Test Target] meta-llama/Llama-4-Scout-17B-16E-Instruct
18
+ """
19
+
20
+ model = LLAMA_4_SCOUT_17B_16E_INSTRUCT_WEIGHTS_PATH
21
+ accuracy = 0.9
22
+ timeout_for_server_launch = 1000
23
+ other_args = [
24
+ "--chat-template",
25
+ "llama-4",
26
+ "--tp-size",
27
+ 4,
28
+ "--mem-fraction-static",
29
+ "0.9",
30
+ "--context-length",
31
+ "8192",
32
+ "--attention-backend",
33
+ "ascend",
34
+ "--disable-cuda-graph",
35
+ "--disable-radix-cache",
36
+ ]
37
+
38
+
39
+ if __name__ == "__main__":
40
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_llama_2_7b.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import LLAMA_2_7B_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestLlama(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the LLM-Research/Llama-2-7B model on the GSM8K dataset is no less than 0.18.
13
+
14
+ [Test Category] Model
15
+ [Test Target] LLM-Research/Llama-2-7B
16
+ """
17
+
18
+ model = LLAMA_2_7B_WEIGHTS_PATH
19
+ accuracy = 0.18
20
+
21
+
22
+ if __name__ == "__main__":
23
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_llama_2_7b_communications_compression.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import LLAMA_2_7B_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-2-npu-a3")
9
+
10
+
11
+ class TestLlama(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the LLM-Research/Llama-2-7B model on the GSM8K dataset with tp communications quantization is no less than 0.18.
13
+
14
+ [Test Category] Model
15
+ [Test Target] LLM-Research/Llama-2-7B
16
+ """
17
+
18
+ model = LLAMA_2_7B_WEIGHTS_PATH
19
+ accuracy = 0.18
20
+ other_args = [
21
+ "--trust-remote-code",
22
+ "--mem-fraction-static",
23
+ 0.8,
24
+ "--max-running-requests",
25
+ 32,
26
+ "--attention-backend",
27
+ "ascend",
28
+ "--cuda-graph-max-bs-decode",
29
+ 32,
30
+ "--tp-size",
31
+ 2,
32
+ "--enable-quant-communications",
33
+ ]
34
+
35
+
36
+ if __name__ == "__main__":
37
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_mimo_7b_rl.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import MIMO_7B_RL_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="full-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestMiMo7BRL(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the XiaomiMiMo/MiMo-7B-RL model on the GSM8K dataset is no less than 0.75.
13
+
14
+ [Test Category] Model
15
+ [Test Target] XiaomiMiMo/MiMo-7B-RL
16
+ """
17
+
18
+ model = MIMO_7B_RL_WEIGHTS_PATH
19
+ accuracy = 0.75
20
+
21
+
22
+ if __name__ == "__main__":
23
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_minicpm3_4b.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import MINICPM3_4B_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestMiniCPM3(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the OpenBMB/MiniCPM3-4B model on the GSM8K dataset is no less than 0.69.
13
+
14
+ [Test Category] Model
15
+ [Test Target] OpenBMB/MiniCPM3-4B
16
+ """
17
+
18
+ model = MINICPM3_4B_WEIGHTS_PATH
19
+ accuracy = 0.69
20
+ other_args = [
21
+ "--trust-remote-code",
22
+ "--mem-fraction-static",
23
+ "0.8",
24
+ "--attention-backend",
25
+ "ascend",
26
+ "--disable-cuda-graph",
27
+ "--disable-radix-cache",
28
+ "--disable-overlap-schedule",
29
+ "--max-running-requests",
30
+ "128",
31
+ "--chunked-prefill-size",
32
+ "-1",
33
+ ]
34
+
35
+
36
+ if __name__ == "__main__":
37
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_mistral_7b.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import MISTRAL_7B_INSTRUCT_V0_2_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestMistral7B(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the mistralai/Mistral-7B-Instruct-v0.2 model on the GSM8K dataset is no less than 0.375.
13
+
14
+ [Test Category] Model
15
+ [Test Target] mistralai/Mistral-7B-Instruct-v0.2
16
+ """
17
+
18
+ model = MISTRAL_7B_INSTRUCT_V0_2_WEIGHTS_PATH
19
+ accuracy = 0.375
20
+
21
+
22
+ if __name__ == "__main__":
23
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_persimmon_8b_chat.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import unittest
3
+
4
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
5
+ from sglang.test.ascend.test_ascend_utils import PERSIMMON_8B_CHAT_WEIGHTS_PATH
6
+ from sglang.test.ci.ci_register import register_npu_ci
7
+ from sglang.test.test_utils import CustomTestCase
8
+
9
+ register_npu_ci(
10
+ est_time=400,
11
+ suite="full-1-npu-a3",
12
+ nightly=True,
13
+ )
14
+
15
+
16
+ class TestPersimmon8BChat(GSM8KAscendMixin, CustomTestCase):
17
+ """Testcase: Verify that the inference accuracy of the Howeee/persimmon-8b-chat model on the GSM8K dataset is no less than 0.17.
18
+
19
+ [Test Category] Model
20
+ [Test Target] Howeee/persimmon-8b-chat
21
+ """
22
+
23
+ os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
24
+ model = PERSIMMON_8B_CHAT_WEIGHTS_PATH
25
+ accuracy = 0.17
26
+
27
+
28
+ if __name__ == "__main__":
29
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_phi_4_multimodal_llm.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import PHI_4_MULTIMODAL_INSTRUCT_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestPhi4(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the microsoft/Phi-4-multimodal-instruct model on the GSM8K dataset is no less than 0.8.
13
+
14
+ [Test Category] Model
15
+ [Test Target] microsoft/Phi-4-multimodal-instruct
16
+ """
17
+
18
+ model = PHI_4_MULTIMODAL_INSTRUCT_WEIGHTS_PATH
19
+ accuracy = 0.8
20
+
21
+
22
+ if __name__ == "__main__":
23
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_0_6b.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import QWEN3_0_6B_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
9
+
10
+
11
+ class TestQwen306B(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the Qwen/Qwen3-0.6B model on the GSM8K dataset is no less than 0.38.
13
+
14
+ [Test Category] Model
15
+ [Test Target] Qwen/Qwen3-0.6B
16
+ """
17
+
18
+ model = QWEN3_0_6B_WEIGHTS_PATH
19
+ accuracy = 0.38
20
+ other_args = [
21
+ "--chunked-prefill-size",
22
+ 256,
23
+ "--attention-backend",
24
+ "ascend",
25
+ "--disable-cuda-graph",
26
+ ]
27
+
28
+
29
+ if __name__ == "__main__":
30
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_1_7b_gptq_int8.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import QWEN3_1_7B_GPTQ_INT8_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="per-commit-1-npu-a2")
9
+
10
+
11
+ class TestQwen317BGPTQInt8(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the Qwen/Qwen3-1.7B-GPTQ-Int8 model on the GSM8K dataset is no less than 0.65.
13
+
14
+ [Test Category] Model
15
+ [Test Target] Qwen/Qwen3-1.7B-GPTQ-Int8
16
+ """
17
+
18
+ model = QWEN3_1_7B_GPTQ_INT8_WEIGHTS_PATH
19
+ accuracy = 0.65
20
+ other_args = [
21
+ "--trust-remote-code",
22
+ "--mem-fraction-static",
23
+ "0.8",
24
+ "--attention-backend",
25
+ "ascend",
26
+ "--quantization",
27
+ "gptq",
28
+ ]
29
+
30
+
31
+ if __name__ == "__main__":
32
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_235b_a22b_w8a8.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import QWEN3_235B_A22B_W8A8_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-8-npu-a3", nightly=True)
9
+
10
+
11
+ class TestQwen3235BA22BW8A8(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the vllm-ascend/Qwen3-235B-A22B-W8A8 model on the GSM8K dataset is no less than 0.955.
13
+
14
+ [Test Category] Model
15
+ [Test Target] vllm-ascend/Qwen3-235B-A22B-W8A8
16
+ """
17
+
18
+ model = QWEN3_235B_A22B_W8A8_WEIGHTS_PATH
19
+ accuracy = 0.955
20
+ timeout_for_server_launch = 3000
21
+ other_args = [
22
+ "--trust-remote-code",
23
+ "--mem-fraction-static",
24
+ "0.8",
25
+ "--attention-backend",
26
+ "ascend",
27
+ "--disable-cuda-graph",
28
+ "--tp-size",
29
+ "8",
30
+ "--quantization",
31
+ "modelslim",
32
+ ]
33
+
34
+
35
+ if __name__ == "__main__":
36
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_30b.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import (
5
+ QWEN3_30B_A3B_INSTRUCT_2507_WEIGHTS_PATH,
6
+ )
7
+ from sglang.test.ci.ci_register import register_npu_ci
8
+ from sglang.test.test_utils import CustomTestCase
9
+
10
+ register_npu_ci(est_time=400, suite="nightly-2-npu-a3", nightly=True)
11
+
12
+
13
+ class TestQwen330B(GSM8KAscendMixin, CustomTestCase):
14
+ """Testcase: Verify that the inference accuracy of the Qwen/Qwen3-30B-A3B-Instruct-2507 model on the GSM8K dataset is no less than 0.90.
15
+
16
+ [Test Category] Model
17
+ [Test Target] Qwen/Qwen3-30B-A3B-Instruct-2507
18
+ """
19
+
20
+ model = QWEN3_30B_A3B_INSTRUCT_2507_WEIGHTS_PATH
21
+ accuracy = 0.90
22
+ other_args = [
23
+ "--trust-remote-code",
24
+ "--mem-fraction-static",
25
+ 0.7,
26
+ "--max-running-requests",
27
+ 32,
28
+ "--attention-backend",
29
+ "ascend",
30
+ "--disable-cuda-graph",
31
+ "--cuda-graph-max-bs-decode",
32
+ 32,
33
+ "--tp-size",
34
+ 2,
35
+ ]
36
+
37
+
38
+ if __name__ == "__main__":
39
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_30b_attn_cp.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import unittest
3
+
4
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
5
+ from sglang.test.ascend.test_ascend_utils import QWEN3_30B_A3B_WEIGHTS_PATH
6
+ from sglang.test.ci.ci_register import register_npu_ci
7
+ from sglang.test.test_utils import CustomTestCase
8
+
9
+ register_npu_ci(est_time=500, suite="nightly-4-npu-a3", nightly=True)
10
+
11
+
12
+ class TestQwen330BAttnCP(GSM8KAscendMixin, CustomTestCase):
13
+ """GSM8K accuracy test for Qwen3-30B-A3B mixed deployment on 4 NPUs.
14
+
15
+ The test uses:
16
+ - TP = 4
17
+ - MOE_DP = 2
18
+ - ATTN_CP = 2
19
+ - prefill context parallel enabled
20
+
21
+ This is the mixed/co-located deployment variant and reuses the Ascend
22
+ environment variables from the PD GSM8K test.
23
+ """
24
+
25
+ model = QWEN3_30B_A3B_WEIGHTS_PATH
26
+ other_args = [
27
+ "--trust-remote-code",
28
+ "--mem-fraction-static",
29
+ "0.7",
30
+ "--max-running-requests",
31
+ "32",
32
+ "--attention-backend",
33
+ "ascend",
34
+ "--tp-size",
35
+ "4",
36
+ "--moe-dp-size",
37
+ "2",
38
+ "--attn-cp-size",
39
+ "2",
40
+ "--cuda-graph-max-bs-decode",
41
+ "32",
42
+ "--enable-prefill-context-parallel",
43
+ ]
44
+
45
+ env = {**os.environ, "ASCEND_USE_FIA": "1"}
46
+
47
+ # GSM8K Configs
48
+ accuracy = 0.92 # GSM8K accuracy ≥0.92
49
+ gsm8k_parallel = 32
50
+ num_questions = 100
51
+ gsm8k_num_shots = 5
52
+
53
+
54
+ if __name__ == "__main__":
55
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_30b_w4a4.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import QWEN3_30B_MODELSLIM_INT4_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="per-commit-2-npu-a2")
9
+
10
+
11
+ class TestQwen317BGPTQInt8(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the Eco-Tech/Qwen3-30B-A3B-w4a4-LAOS model on the GSM8K dataset is no less than 0.85.
13
+
14
+ [Test Category] Model
15
+ [Test Target] Qwen/Qwen3-1.7B-GPTQ-Int8
16
+ """
17
+
18
+ model = QWEN3_30B_MODELSLIM_INT4_WEIGHTS_PATH
19
+ accuracy = 0.85
20
+ other_args = [
21
+ "--trust-remote-code",
22
+ "--mem-fraction-static",
23
+ 0.8,
24
+ "--max-running-requests",
25
+ 32,
26
+ "--attention-backend",
27
+ "ascend",
28
+ "--disable-cuda-graph",
29
+ "--cuda-graph-max-bs-decode",
30
+ 32,
31
+ "--tp-size",
32
+ 2,
33
+ ]
34
+
35
+
36
+ if __name__ == "__main__":
37
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_32b.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import QWEN3_32B_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(
9
+ est_time=400,
10
+ suite="nightly-4-npu-a3",
11
+ nightly=True,
12
+ )
13
+
14
+
15
+ class TestQwen332B(GSM8KAscendMixin, CustomTestCase):
16
+ """Testcase: Verify that the inference accuracy of the Qwen/Qwen3-32B model on the GSM8K dataset is no less than 0.86.
17
+
18
+ [Test Category] Model
19
+ [Test Target] Qwen/Qwen3-32B
20
+ """
21
+
22
+ model = QWEN3_32B_WEIGHTS_PATH
23
+ accuracy = 0.86
24
+ other_args = [
25
+ "--trust-remote-code",
26
+ "--mem-fraction-static",
27
+ "0.8",
28
+ "--attention-backend",
29
+ "ascend",
30
+ "--disable-cuda-graph",
31
+ "--tp-size",
32
+ "4",
33
+ ]
34
+
35
+
36
+ if __name__ == "__main__":
37
+ unittest.main()
asian_ai/performance/SGLang/test/registered/ascend/llm_models/test_npu_qwen3_8b_communications_quantization.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
4
+ from sglang.test.ascend.test_ascend_utils import QWEN3_8B_WEIGHTS_PATH
5
+ from sglang.test.ci.ci_register import register_npu_ci
6
+ from sglang.test.test_utils import CustomTestCase
7
+
8
+ register_npu_ci(est_time=400, suite="nightly-2-npu-a3")
9
+
10
+
11
+ class TestQwen38BCommQuantization(GSM8KAscendMixin, CustomTestCase):
12
+ """Testcase: Verify that the inference accuracy of the Qwen/Qwen3-8B model with TP communications quantization on the GSM8K dataset is no less than 0.85.
13
+
14
+ [Test Category] Model
15
+ [Test Target] Qwen/Qwen3-8B
16
+ """
17
+
18
+ model = QWEN3_8B_WEIGHTS_PATH
19
+ accuracy = 0.85
20
+ other_args = [
21
+ "--trust-remote-code",
22
+ "--mem-fraction-static",
23
+ 0.8,
24
+ "--max-running-requests",
25
+ 32,
26
+ "--attention-backend",
27
+ "ascend",
28
+ "--cuda-graph-max-bs-decode",
29
+ 32,
30
+ "--tp-size",
31
+ 2,
32
+ "--enable-quant-communications",
33
+ ]
34
+
35
+
36
+ if __name__ == "__main__":
37
+ unittest.main()