[NPU] Add GitHub test summary and deduplicate test code. Part 1 (#23835)
Co-authored-by: Elizaveta Martirosian <elizaveta.martirosian@gmail.com> Co-authored-by: root <root@localhost.localdomain> Co-authored-by: Elizaveta Martirosian <you@example.com> Co-authored-by: ronnie_zheng <zl19940307@163.com>
This commit is contained in:
co-authored by
Elizaveta Martirosian
root
Elizaveta Martirosian
ronnie_zheng
parent
3259a2c789
commit
ebbaab5597
@@ -1,19 +1,22 @@
|
||||
import os
|
||||
import subprocess
|
||||
from abc import ABC
|
||||
from types import SimpleNamespace
|
||||
|
||||
from sglang.srt.utils import kill_process_tree
|
||||
from sglang.test.ascend.test_ascend_utils import write_results_to_github_step_summary
|
||||
from sglang.test.few_shot_gsm8k import run_eval
|
||||
from sglang.test.test_utils import (
|
||||
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
DEFAULT_URL_FOR_TEST,
|
||||
popen_launch_server,
|
||||
write_github_step_summary,
|
||||
)
|
||||
|
||||
|
||||
class GSM8KAscendMixin(ABC):
|
||||
model = ""
|
||||
accuracy = 0.00
|
||||
|
||||
timeout_for_server_launch = DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH
|
||||
other_args = [
|
||||
"--trust-remote-code",
|
||||
@@ -23,48 +26,80 @@ class GSM8KAscendMixin(ABC):
|
||||
"ascend",
|
||||
"--disable-cuda-graph",
|
||||
]
|
||||
server_cmd = ""
|
||||
gsm8k_num_shots = 5
|
||||
num_questions = 200
|
||||
|
||||
env = {
|
||||
**os.environ,
|
||||
"PYTORCH_NPU_ALLOC_CONF": "expandable_segments:True",
|
||||
"ASCEND_MF_STORE_URL": "tcp://127.0.0.1:24666",
|
||||
"HCCL_BUFFSIZE": "200",
|
||||
"SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK": "24",
|
||||
"USE_VLLM_CUSTOM_ALLREDUCE": "1",
|
||||
"HCCL_EXEC_TIMEOUT": "200",
|
||||
"STREAMS_PER_DEVICE": "32",
|
||||
"SGLANG_ENBLE_TORCH_COMILE": "1",
|
||||
"AUTO_USE_UC_MEMORY": "0",
|
||||
"P2P_HCCL_BUFFSIZE": "20",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.base_url = DEFAULT_URL_FOR_TEST
|
||||
os.environ["PYTORCH_NPU_ALLOC_CONF"] = "expandable_segments:True"
|
||||
os.environ["ASCEND_MF_STORE_URL"] = "tcp://127.0.0.1:24666"
|
||||
os.environ["HCCL_BUFFSIZE"] = "200"
|
||||
os.environ["SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK"] = "24"
|
||||
os.environ["USE_VLLM_CUSTOM_ALLREDUCE"] = "1"
|
||||
os.environ["HCCL_EXEC_TIMEOUT"] = "200"
|
||||
os.environ["STREAMS_PER_DEVICE"] = "32"
|
||||
os.environ["SGLANG_ENBLE_TORCH_COMILE"] = "1"
|
||||
os.environ["AUTO_USE_UC_MEMORY"] = "0"
|
||||
os.environ["P2P_HCCL_BUFFSIZE"] = "20"
|
||||
env = os.environ.copy()
|
||||
|
||||
cls.process = popen_launch_server(
|
||||
cls.model,
|
||||
cls.base_url,
|
||||
timeout=cls.timeout_for_server_launch,
|
||||
other_args=cls.other_args,
|
||||
env=env,
|
||||
)
|
||||
try:
|
||||
cls.process = popen_launch_server(
|
||||
cls.model,
|
||||
cls.base_url,
|
||||
timeout=cls.timeout_for_server_launch,
|
||||
other_args=cls.other_args,
|
||||
env=cls.env,
|
||||
)
|
||||
cls.server_cmd = subprocess.list2cmdline(cls.process.args)
|
||||
except Exception as e:
|
||||
write_github_step_summary(f"Failed to launch server for {cls.model}: {e}")
|
||||
raise AssertionError(f"Test failed for {cls.model}: {e}")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
kill_process_tree(cls.process.pid)
|
||||
|
||||
def test_gsm8k(self):
|
||||
args = SimpleNamespace(
|
||||
num_shots=self.gsm8k_num_shots,
|
||||
data_path=None,
|
||||
num_questions=200,
|
||||
max_new_tokens=512,
|
||||
parallel=128,
|
||||
host="http://127.0.0.1",
|
||||
port=int(self.base_url.split(":")[-1]),
|
||||
)
|
||||
metrics = run_eval(args)
|
||||
self.assertGreaterEqual(
|
||||
metrics["accuracy"],
|
||||
self.accuracy,
|
||||
f'Accuracy of {self.model} is {str(metrics["accuracy"])}, is lower than {self.accuracy}',
|
||||
)
|
||||
accuracy_threshold = getattr(self, "accuracy", 0.00)
|
||||
output_throughput_threshold = getattr(self, "output_throughput", 0.00)
|
||||
|
||||
model_metrics = {
|
||||
"server": self.server_cmd,
|
||||
"client": "few_shot_gsm8k",
|
||||
"accuracy_threshold": getattr(self, "accuracy", "N/A"),
|
||||
"output_throughput_threshold": getattr(self, "output_throughput", "N/A"),
|
||||
}
|
||||
|
||||
try:
|
||||
args = SimpleNamespace(
|
||||
num_shots=self.gsm8k_num_shots,
|
||||
data_path=None,
|
||||
num_questions=self.num_questions,
|
||||
max_new_tokens=512,
|
||||
parallel=128,
|
||||
host="http://127.0.0.1",
|
||||
port=int(self.base_url.split(":")[-1]),
|
||||
)
|
||||
metrics = run_eval(args)
|
||||
model_metrics["accuracy"] = metrics["accuracy"]
|
||||
model_metrics["output_throughput"] = metrics["output_throughput"]
|
||||
self.assertGreaterEqual(
|
||||
metrics["accuracy"],
|
||||
accuracy_threshold,
|
||||
f'Accuracy of {self.model} is {str(metrics["accuracy"])}, is lower than {accuracy_threshold}',
|
||||
)
|
||||
self.assertGreaterEqual(
|
||||
metrics["output_throughput"],
|
||||
output_throughput_threshold,
|
||||
f'Output throughput of {self.model} is {str(metrics["output_throughput"])}, is lower than {output_throughput_threshold}',
|
||||
)
|
||||
except Exception as e:
|
||||
model_metrics["error"] = e
|
||||
self.fail(f"Test failed for {self.model}: {e}")
|
||||
finally:
|
||||
write_results_to_github_step_summary({self.model: model_metrics})
|
||||
|
||||
@@ -24,7 +24,9 @@ from sglang.test.test_utils import (
|
||||
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
DEFAULT_URL_FOR_TEST,
|
||||
auto_config_device,
|
||||
is_in_ci,
|
||||
popen_launch_server,
|
||||
write_github_step_summary,
|
||||
)
|
||||
|
||||
# Model weights storage directory
|
||||
@@ -90,6 +92,9 @@ LLAMA_3_2_1B_WEIGHTS_PATH = os.path.join(MODEL_WEIGHTS_DIR, "LLM-Research/Llama-
|
||||
LLAMA_4_SCOUT_17B_16E_INSTRUCT_WEIGHTS_PATH = os.path.join(
|
||||
MODEL_WEIGHTS_DIR, "meta-llama/Llama-4-Scout-17B-16E-Instruct"
|
||||
)
|
||||
LLaDA2_0_MINI_WEIGHTS_PATH = os.path.join(
|
||||
MODEL_WEIGHTS_DIR, "inclusionAI/LLaDA2.0-mini"
|
||||
)
|
||||
META_LLAMA_3_1_8B_INSTRUCT = os.path.join(
|
||||
MODEL_WEIGHTS_DIR, "LLM-Research/Meta-Llama-3.1-8B-Instruct"
|
||||
)
|
||||
@@ -555,3 +560,46 @@ def run_bench_serving(
|
||||
|
||||
assert res["completed"] == num_prompts
|
||||
return res
|
||||
|
||||
|
||||
HEADER = """
|
||||
### Models
|
||||
| Model | Server | Client | Output Throughput | Expected Output Throughput | Latency | Expected Latency | Accuracy | Expected Accuracy | Status |
|
||||
| ----- | ------ | ------ | -------- | ------------------ | ------- | ---------------- | -------- | --------- | ------ |
|
||||
"""
|
||||
|
||||
|
||||
def write_results_to_github_step_summary(results: dict):
|
||||
if not is_in_ci():
|
||||
return
|
||||
|
||||
write_github_step_summary_once(HEADER)
|
||||
|
||||
get_float = lambda metrics, item, precision: (
|
||||
f"{metrics[item]:.{precision}f}"
|
||||
if isinstance(metrics.get(item, "-"), (int, float))
|
||||
else metrics.get(item, "-")
|
||||
)
|
||||
|
||||
summary = ""
|
||||
for model, metrics in results.items():
|
||||
model = model.replace(MODEL_WEIGHTS_DIR, "").replace(HF_MODEL_WEIGHTS_DIR, "")
|
||||
output_throughput = get_float(metrics, "output_throughput", 2)
|
||||
output_throughput_threshold = metrics.get("output_throughput_threshold", "N/A")
|
||||
accuracy = get_float(metrics, "accuracy", 4)
|
||||
accuracy_threshold = metrics.get("accuracy_threshold", "N/A")
|
||||
latency = get_float(metrics, "latency", 4)
|
||||
latency_threshold = metrics.get("latency_threshold", "N/A")
|
||||
server = metrics.get("server", "N/A")
|
||||
client = metrics.get("client", "N/A")
|
||||
error = metrics.get("error", "")
|
||||
status = "✅" if error == "" else "❌ " + str(error)
|
||||
summary += f"| {model} | {server} | {client} | {output_throughput} | {output_throughput_threshold} | {latency} | {latency_threshold} | {accuracy} | {accuracy_threshold} | {status} |\n"
|
||||
write_github_step_summary(summary)
|
||||
|
||||
|
||||
def write_github_step_summary_once(summary: str):
|
||||
if getattr(write_github_step_summary_once, "has_written", False):
|
||||
return
|
||||
write_github_step_summary_once.has_written = True
|
||||
write_github_step_summary(summary)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import subprocess
|
||||
from types import SimpleNamespace
|
||||
|
||||
from sglang.test.ascend.test_ascend_utils import write_results_to_github_step_summary
|
||||
from sglang.test.run_eval import run_eval
|
||||
|
||||
|
||||
class TestMMLU:
|
||||
|
||||
def test_mmlu(self):
|
||||
accuracy_mmlu_threshold = getattr(self, "accuracy_mmlu", 0.00)
|
||||
|
||||
model_metrics = {
|
||||
"server": getattr(
|
||||
self, "server_cmd", subprocess.list2cmdline(map(str, self.other_args))
|
||||
),
|
||||
"client": "simple_eval_mmlu",
|
||||
"accuracy_threshold": getattr(self, "accuracy_mmlu", "N/A"),
|
||||
}
|
||||
|
||||
try:
|
||||
args = SimpleNamespace(
|
||||
base_url=self.base_url,
|
||||
model=self.model,
|
||||
eval_name="mmlu",
|
||||
num_examples=128,
|
||||
num_threads=32,
|
||||
)
|
||||
print("Starting mmlu test...")
|
||||
metrics = run_eval(args)
|
||||
model_metrics["accuracy"] = metrics["score"]
|
||||
self.assertGreater(metrics["score"], accuracy_mmlu_threshold)
|
||||
except Exception as e:
|
||||
model_metrics["error"] = e
|
||||
self.fail(f"Test failed for {self.model}: {e}")
|
||||
finally:
|
||||
write_results_to_github_step_summary({self.model: model_metrics})
|
||||
@@ -4,6 +4,7 @@ import os
|
||||
import subprocess
|
||||
|
||||
from sglang.srt.utils import kill_process_tree
|
||||
from sglang.test.ascend.test_ascend_utils import write_results_to_github_step_summary
|
||||
from sglang.test.test_utils import (
|
||||
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
DEFAULT_URL_FOR_TEST,
|
||||
@@ -96,6 +97,8 @@ class TestVLMModels(CustomTestCase):
|
||||
timeout=3600,
|
||||
)
|
||||
|
||||
return subprocess.list2cmdline(cmd) # Return the command for logging purposes
|
||||
|
||||
def _run_vlm_mmmu_test(
|
||||
self,
|
||||
output_path="./logs",
|
||||
@@ -115,8 +118,15 @@ class TestVLMModels(CustomTestCase):
|
||||
"""
|
||||
print(f"\nTesting model: {self.model}{test_name}")
|
||||
|
||||
model_metrics = {
|
||||
"server": subprocess.list2cmdline(map(str, self.other_args)),
|
||||
"client": "mmmu_eval",
|
||||
"accuracy_threshold": self.mmmu_accuracy,
|
||||
}
|
||||
|
||||
process = None
|
||||
server_output = ""
|
||||
mmmu_accuracy = None
|
||||
|
||||
try:
|
||||
# Prepare environment variables
|
||||
@@ -143,8 +153,10 @@ class TestVLMModels(CustomTestCase):
|
||||
),
|
||||
)
|
||||
|
||||
model_metrics["server"] = subprocess.list2cmdline(process.args)
|
||||
|
||||
# Run evaluation
|
||||
self.run_mmmu_eval(self.model, output_path, limit)
|
||||
model_metrics["client"] = self.run_mmmu_eval(self.model, output_path, limit)
|
||||
|
||||
# Get the result file
|
||||
result_file_path = glob.glob(f"{output_path}/*.json")[0]
|
||||
@@ -163,6 +175,8 @@ class TestVLMModels(CustomTestCase):
|
||||
if capture_output and process:
|
||||
server_output = self._read_output_from_files()
|
||||
|
||||
model_metrics["accuracy"] = mmmu_accuracy
|
||||
|
||||
# Assert performance meets expected threshold
|
||||
self.assertGreaterEqual(
|
||||
mmmu_accuracy,
|
||||
@@ -173,10 +187,12 @@ class TestVLMModels(CustomTestCase):
|
||||
return server_output
|
||||
|
||||
except Exception as e:
|
||||
model_metrics["error"] = e
|
||||
print(f"Error testing {self.model}{test_name}: {e}")
|
||||
self.fail(f"Test failed for {self.model}{test_name}: {e}")
|
||||
|
||||
finally:
|
||||
write_results_to_github_step_summary({self.model: model_metrics})
|
||||
|
||||
# Ensure process cleanup happens regardless of success/failure
|
||||
if process is not None and process.poll() is None:
|
||||
print(f"Cleaning up process {process.pid}")
|
||||
|
||||
Reference in New Issue
Block a user