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
2 changes: 1 addition & 1 deletion backends/openvino/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def preprocess(
for spec in module_compile_spec:
compile_options[spec.key] = spec.value.decode()

compiled = openvino_compile(edge_program.module(), *args, options=compile_options, executorch=True)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed "executorch" parameter as it will be using TorchFXPythonDecoder with new updates

compiled = openvino_compile(edge_program.module(), *args, options=compile_options)
model_bytes = compiled.export_model()

return PreprocessResult(processed_bytes=model_bytes)
34 changes: 34 additions & 0 deletions backends/openvino/tests/models/test_classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from executorch.backends.openvino.tests.ops.base_openvino_op_test import BaseOpenvinoOpTest
import torch
import timm
import torchvision.models as torchvision_models
from transformers import AutoModel

classifier_params = [
{'model': ['torchvision', 'resnet50', (1, 3, 224, 224)] },
{'model': ['torchvision', 'mobilenet_v2', (1, 3, 224, 224)] },
]

# Function to load a model based on the selected suite
def load_model(suite: str, model_name: str):
if suite == "timm":
return timm.create_model(model_name, pretrained=True)
elif suite == "torchvision":
if not hasattr(torchvision_models, model_name):
raise ValueError(f"Model {model_name} not found in torchvision.")
return getattr(torchvision_models, model_name)(pretrained=True)
elif suite == "huggingface":
return AutoModel.from_pretrained(model_name)
else:
raise ValueError(f"Unsupported model suite: {suite}")

class TestClassifier(BaseOpenvinoOpTest):

def test_classifier(self):
for params in classifier_params:
with self.subTest(params=params):
module = load_model(params['model'][0], params['model'][1])

sample_input = (torch.randn(params['model'][2]),)

self.execute_layer_test(module, sample_input)
13 changes: 11 additions & 2 deletions backends/openvino/tests/test_openvino_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,25 @@ def parse_arguments():
parser.add_argument(
"-p",
"--pattern",
help="Pattern to match test files. Provide complete file name to run individual op tests",
help="Pattern to match test files. Provide complete file name to run individual tests",
type=str,
default="test_*.py",
)
parser.add_argument(
"-t",
"--test_type",
help="Specify the type of tests ('ops' or 'models')",
type=str,
default="ops",
choices={"ops", "models"},
)

args, ns_args = parser.parse_known_args(namespace=unittest)
test_params = {}
test_params["device"] = args.device
test_params["build_folder"] = args.build_folder
test_params["pattern"] = args.pattern
test_params["test_type"] = args.test_type
return test_params

if __name__ == "__main__":
Expand All @@ -60,6 +69,6 @@ def parse_arguments():
test_params = parse_arguments()
loader.suiteClass.test_params = test_params
# Discover all existing op tests in "ops" folder
suite = loader.discover("ops", pattern=test_params['pattern'])
suite = loader.discover(test_params['test_type'], pattern=test_params['pattern'])
# Start running tests
unittest.TextTestRunner().run(suite)