Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions backends/openvino/tests/ops/base_openvino_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
from executorch.backends.openvino.preprocess import OpenvinoBackend
from executorch.exir import EdgeProgramManager, to_edge_transform_and_lower
from executorch.exir.backend.backend_details import CompileSpec
from executorch.runtime import Runtime

from executorch.extension.pybindings.portable_lib import ( # @manual
_load_for_executorch_from_buffer,
)
from torch.export import export, ExportedProgram


Expand Down Expand Up @@ -67,8 +65,10 @@ def execute_layer_test(
]

# Load model from buffer and execute
executorch_module = _load_for_executorch_from_buffer(exec_prog.buffer)
outputs = executorch_module.run_method("forward", sample_inputs)
runtime = Runtime.get()
program = runtime.load_program(exec_prog.buffer)
method = program.load_method("forward")
outputs = method.execute(sample_inputs)

# Compare the outputs with the reference outputs
self.assertTrue(len(ref_output) == len(outputs))
Expand Down
18 changes: 10 additions & 8 deletions examples/openvino/aot_optimize_and_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
from executorch.backends.openvino.quantizer import quantize_model
from executorch.exir import EdgeProgramManager, to_edge_transform_and_lower
from executorch.exir.backend.backend_details import CompileSpec
from executorch.extension.pybindings.portable_lib import ( # @manual
_load_for_executorch_from_buffer,
)
from executorch.runtime import Runtime
from sklearn.metrics import accuracy_score
from timm.data import resolve_data_config
from timm.data.transforms_factory import create_transform
Expand Down Expand Up @@ -121,17 +119,19 @@ def infer_model(
:return: The average inference timing.
"""
# Load model from buffer
executorch_module = _load_for_executorch_from_buffer(exec_prog.buffer)
runtime = Runtime.get()
program = runtime.load_program(exec_prog.buffer)
method = program.load_method("forward")

# Execute warmup
for _i in range(warmup_iter):
out = executorch_module.run_method("forward", inputs)
out = method.execute(inputs)

# Execute inference and measure timing
time_total = 0.0
for _i in range(num_iter):
time_start = time.time()
out = executorch_module.run_method("forward", inputs)
out = method.execute(inputs)
time_end = time.time()
time_total += time_end - time_start

Expand All @@ -154,15 +154,17 @@ def validate_model(
:return: The accuracy score of the model.
"""
# Load model from buffer
executorch_module = _load_for_executorch_from_buffer(exec_prog.buffer)
runtime = Runtime.get()
program = runtime.load_program(exec_prog.buffer)
method = program.load_method("forward")

# Iterate over the dataset and run the executor
predictions = []
targets = []
for _idx, data in enumerate(calibration_dataset):
feature, target = data
targets.extend(target)
out = executorch_module.run_method("forward", (feature,))
out = method.execute((feature,))
predictions.extend(torch.stack(out).reshape(-1, 1000).argmax(-1))

# Check accuracy
Expand Down
Loading