feat: add live endpoint benchmark runner

This commit is contained in:
Dobromir Popov
2026-07-14 22:46:11 +03:00
parent e6f6782995
commit a508768e8a
3 changed files with 136 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import json
from unittest.mock import MagicMock, patch
from meshnet_node.performance_contract import (
BENCHMARK_SCHEMA_VERSION,
@@ -10,6 +11,7 @@ from meshnet_node.performance_contract import (
SCHEMA_VERSION,
main,
run_performance_benchmark,
run_real_model_endpoint_benchmark,
)
@@ -165,3 +167,37 @@ def test_contract_cli_writes_benchmark_report(tmp_path, capsys):
output = capsys.readouterr().out
assert str(contract_out) in output
assert str(benchmark_out) in output
def test_real_model_endpoint_benchmark_uses_lane_specific_endpoints_and_shared_schema():
"""The live client path fans out to one endpoint per CPU/GPU lane.
Tags: performance, benchmark, live
"""
response = MagicMock()
response.read.return_value = json.dumps({"choices": [{"message": {"content": "mesh activation"}}]}).encode()
response.headers.get.return_value = "lane-session"
response.__enter__.return_value = response
endpoints = {
"transformers-safetensors-cpu": "http://cpu-safetensors",
"llama-cpp-gguf-cpu": "http://cpu-gguf",
"transformers-safetensors-gpu": "http://gpu-safetensors",
"llama-cpp-gguf-gpu": "http://gpu-gguf",
}
with patch("meshnet_node.performance_contract.urllib.request.urlopen", return_value=response) as urlopen:
report = run_real_model_endpoint_benchmark(endpoints=endpoints, model="deepseek-ai/DeepSeek-V2-Lite-Chat")
assert report["source"] == "real-model-endpoints"
assert report["model_target"] == DEFAULT_CONTRACT.model_target.to_dict()
assert set(report["comparisons"]) == {"cpu", "gpu"}
assert urlopen.call_count == len(endpoints)
called_urls = [call.args[0].full_url for call in urlopen.call_args_list]
assert called_urls == [f"{url}/v1/chat/completions" for url in endpoints.values()]
for lane in report["lanes"]:
assert lane["results"][0]["metrics"]["decode_tok_per_sec"] > 0
assert lane["results"][0]["metrics"]["ttft_ms"] > 0
assert lane["output_tokens"] == ["mesh", "activation"]
assert report["comparisons"]["cpu"]["gguf_lane"] == "llama-cpp-gguf-cpu"
assert report["comparisons"]["gpu"]["gguf_lane"] == "llama-cpp-gguf-gpu"