Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Remove outdated API call to OVVP from memory_tests (#33612)

Egor Tyuvaev94634c1a89bf
diff --git a/tests/memory_tests/src/memory_test.hpp b/tests/memory_tests/src/memory_test.hpp
index a1ebe2ac58c..e3dd105b99a 100644
--- a/tests/memory_tests/src/memory_test.hpp
+++ b/tests/memory_tests/src/memory_test.hpp
@@ -144,6 +144,19 @@ inline std::string jsonescape(const std::string &str) {
return newstr;
}
+
+// To be defined in the test
+std::vector<std::string> test_samples();
+
+std::vector<std::string> registered_samples_init() {
+ auto samples = test_samples();
+ samples.emplace_back("unload");
+ return samples;
+}
+
+static std::vector<std::string> registered_samples = registered_samples_init();
+
+
struct TestContext {
std::string model_path;
std::string device;
@@ -159,22 +172,34 @@ struct TestContext {
}
if (argc > 1) {
model_path = argv[1];
- // assert path exists
}
if (argc > 2) {
device = argv[2];
- // assert known string
}
return {model_path, device};
}
+ bool is_sample_registered(std::string &sample_name) {
+ for (auto registered_sample_name: registered_samples) {
+ if (registered_sample_name == sample_name) {
+ return true;
+ }
+ }
+ return false;
+ }
+
void sample(std::string sample_name) {
+ if (!is_sample_registered(sample_name)) {
+ // registered_samples must contain all possible sample names that this
+ // test can yield. It is required to properly report crashed tests
+ std::string error_msg = "sample \"" + sample_name + "\" is not defined in registered_samples";
+ throw std::runtime_error(error_msg);
+ }
samples.emplace_back(std::move(sample_name), MemoryCounters::sample());
}
void report() {
- // auto model_path = json_escape(model_path); // required for Windows
std::cout << "TEST_RESULTS: {"
<< "\"test\": \"" << AS_STR(TEST_NAME) << "\", "
<< "\"model_path\": \"" << jsonescape(model_path) << "\", "
@@ -196,12 +221,27 @@ struct TestContext {
};
+// To be defined in the test
void do_test(TestContext &test);
int main(int argc, char **argv) {
+ if (argc == 2 && std::string("--info") == argv[1]) {
+ std::cout << "TEST_INFO: {\"samples\": [";
+ for (auto &sample_name: registered_samples) {
+ std::cout << "\"" << sample_name << "\"";
+ if (&sample_name != &registered_samples.back()) {
+ std::cout << ", ";
+ }
+ }
+ std::cout << "]}" << std::endl;
+ return 0;
+ }
+
TestContext test = TestContext::from_args(argc, argv);
do_test(test);
test.sample("unload");
test.report();
+
+ return 0;
}
diff --git a/tests/memory_tests/src/test_inference_async.cpp b/tests/memory_tests/src/test_inference_async.cpp
index 38d80233a3d..fcc7ecd72c9 100644
--- a/tests/memory_tests/src/test_inference_async.cpp
+++ b/tests/memory_tests/src/test_inference_async.cpp
@@ -7,6 +7,16 @@
#include "memory_test.hpp"
+std::vector<std::string> test_samples() {
+ return {
+ "start",
+ "compile_model",
+ "fill_inputs",
+ "inference"
+ };
+}
+
+
void do_test(TestContext &test) {
test.sample("start");
diff --git a/tests/memory_tests/src/test_inference_sync.cpp b/tests/memory_tests/src/test_inference_sync.cpp
index 7b88de45657..4098d05eabb 100644
--- a/tests/memory_tests/src/test_inference_sync.cpp
+++ b/tests/memory_tests/src/test_inference_sync.cpp
@@ -7,6 +7,16 @@
#include "memory_test.hpp"
+std::vector<std::string> test_samples() {
+ return {
+ "start",
+ "compile_model",
+ "fill_inputs",
+ "inference"
+ };
+}
+
+
void do_test(TestContext &test) {
test.sample("start");
@@ -22,5 +32,4 @@ void do_test(TestContext &test) {
ireq.infer();
test.sample("inference");
-
}
diff --git a/tests/memory_tests/tools/run_tests.py b/tests/memory_tests/tools/run_tests.py
index b292303e18e..905afe3f918 100644
--- a/tests/memory_tests/tools/run_tests.py
+++ b/tests/memory_tests/tools/run_tests.py
@@ -78,6 +78,8 @@ def run_test_executable_extract_result(command):
for sname, sample in results["samples"].items()
}
return results
+ elif run_out.startswith("TEST_INFO: "):
+ return json.loads(run_out.splitlines()[0].removeprefix("TEST_INFO: "))
return {
"error": "Test did not run correctly",
"returncode": proc.returncode,
@@ -90,7 +92,7 @@ MODELID_RE = re.compile(r"\/?([^\/]+)\/(\w+)\/?[^\/]*\/((OV_)?(FP|INT)\d+(\/INT\
def modelid_assume_info(modelid):
- match = MODELID_RE.match(modelid)
+ match = MODELID_RE.match(modelid.replace("\\", "/"))
if not match:
return None
model, fw, prec, _n1, _n2, _n3, _n4, model2 = match.groups()
@@ -111,12 +113,19 @@ class TestSession:
self.devices = devices
self.report_api = api
self.report_reference = report_reference
+ self.test_info = self.get_test_info()
self.report_metadata = None
- self.reference_values = {}
if self.report_api:
self.detect_report_metadata()
- self.reference_values = self.api_get_reference_values()
+
+ def get_test_info(self):
+ result = run_test_executable_extract_result([self.executable, "--info"])
+ if "error" in result:
+ raise Exception(f"Test executable does not behave correctly: {result}")
+ if "samples" not in result:
+ raise Exception(f"Unexpected test info: {result}")
+ return result
def api(self, method, data=None, **kwargs):
extra_args = {"timeout": 30}
@@ -126,60 +135,24 @@ class TestSession:
if requests is None:
raise Exception("`requests` need to be installed to contact Report API")
endpoint = f"{self.report_api}/api/{method}"
- return requests.post(endpoint, json=data, **extra_args).json()
-
- def api_get_reference_values(self):
- api_response = self.api("v1/reports/memory/root-ref-metrics", [], timeout=5)
- reference_test_values = defaultdict(lambda: defaultdict(dict))
- for ref_item in api_response:
- try:
- test_name, sample = ref_item["test"].split(":")
- network = ref_item["network"]
- except ValueError:
- continue
- reference_test_values[test_name][network][sample] = MemSample.from_dict(ref_item)
- return reference_test_values
-
- def api_push_reference_values(self, modelid, device, result):
- if "error" in result:
- print("Failed result is not going to be uploaded as reference.")
- return
- test_report = []
- test_name = result.get("test", self.test_name)
- model_assumptions = modelid_assume_info(modelid)
- modelname, framework, precision = model_assumptions or (modelid, "unknown", "unknown")
- for sname, sample in result["samples"].items():
- sample_report = {
- "test": f"{test_name}:{sname}",
- "network": modelname,
- "device": result.get("device", device),
- "framework": framework,
- "precision": precision
- }
- sample_report.update(sample.as_dict())
- test_report.append(sample_report)
- response = attempt(self.api, "v1/memory/push-2-db-facade/root-ref-metrics", test_report)
- if response:
- print(f"Push reference to API: {response}")
+ response = requests.post(endpoint, json=data, **extra_args)
+ if not response.ok:
+ print(f"API Error: {response.text}")
+ return response.json()
- def api_push_test_result(self, source, modelid, device, result, refsamples=None):
- if refsamples is None:
- refsamples = {}
- if "error" in result and not refsamples:
- print("Failed result is not going to be uploaded since no reference results were found.")
- return
+ def api_push_test_result(self, source, modelid, device, result):
if not self.report_metadata:
print("No job metadata found, no report will be made.")
return
model_assumptions = modelid_assume_info(modelid)
modelname, framework, precision = model_assumptions or (modelid, "unknown", "unknown")
test_report = []
- sample_names = result.get("samples", refsamples).keys()
+ sample_names = result.get("samples", {}).keys() or self.test_info["samples"]
for sname in sample_names:
sample = result.get("samples", {}).get(sname, MemSample(-1, -1, -1, -1, -1))
sample_report = self.report_metadata.copy()
sample_report.update({
- "test_name": f"{result['test']}:{sname}",
+ "test_name": f"{result.get('test', self.test_name)}:{sname}",
"status": "failed" if "error" in result else "passed",
"source": source,
"log": result.get("stderr", ""),
@@ -234,7 +207,7 @@ class TestSession:
return
found_models.update(new_files)
new_files = sorted(new_files)
- yield from ((path.removeprefix(cache_dir), path) for path in new_files)
+ yield from ((path.removeprefix(cache_dir).replace("\\", "/"), path) for path in new_files)
def generate_test_cases(self):
for ir_cache_dir in self.ir_cache_dirs:
@@ -248,7 +221,7 @@ class TestSession:
print(f" When running test an unexpected error happened: {ex}")
return {"error": "unexpected error", "exception": ex}
- def handle_test_result(self, modelid, device, result, refsamples=None):
+ def handle_test_result(self, modelid, device, result):
status = "error" if "error" in result else "ok"
print(f"TEST {modelid} x {device}: {status}")
if status == "error":
@@ -265,25 +238,14 @@ class TestSession:
print(f" {repr(exception)}")
return
for sname, sample in result["samples"].items():
- refsample = None
- if refsamples:
- refsample = refsamples.get(sname)
- if not refsample:
- print(f" {sname:>15}: {sample}")
- continue
- print(f" sample {sname}:")
- for key, val, ref, diff, diffp in sample.compare(refsample):
- print(f" {key:>8}: {val:>10} (ref: {ref:>10}) {diff:>+8} ({diffp:+.2f}%)")
+ print(f" {sname:>15}: {sample}")
def run(self):
for (modelid, model_path), device in self.generate_test_cases():
result = self.run_test_case(model_path, device)
test_name = result.get("test", self.test_name)
- refsamples = self.reference_values.get(test_name, {}).get(modelid)
- self.api_push_test_result(model_path, modelid, device, result, refsamples)
- if self.report_reference:
- self.api_push_reference_values(modelid, device, result)
- self.handle_test_result(modelid, device, result, refsamples)
+ self.api_push_test_result(model_path, modelid, device, result)
+ self.handle_test_result(modelid, device, result)
if __name__ == "__main__":