From 4ee606603042e431a2480c17a479b1327de82d07 Mon Sep 17 00:00:00 2001 From: Jing Jin <8752427+jinjingforever@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:45:08 -0800 Subject: [PATCH 1/2] Show pytorch adapter even if torch in not impoted. Just realized that it is useful to show that the pytorch adapter is available even if torch is not imported. We will display 'torch not installed' error message when user actually uses the adapter. --- .../package/src/model_explorer/extension_manager.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/server/package/src/model_explorer/extension_manager.py b/src/server/package/src/model_explorer/extension_manager.py index 4cb223a..13ae654 100644 --- a/src/server/package/src/model_explorer/extension_manager.py +++ b/src/server/package/src/model_explorer/extension_manager.py @@ -19,11 +19,6 @@ from importlib import import_module from typing import Any, Dict, Union -try: - import torch -except ImportError: - torch = None - from .adapter_runner import AdapterRunner from .consts import MODULE_NAME from .extension_class_processor import ExtensionClassProcessor @@ -41,9 +36,7 @@ class ExtensionManager(object, metaclass=Singleton): '.builtin_tf_mlir_adapter', '.builtin_tf_direct_adapter', '.builtin_graphdef_adapter', - ] - + (['.builtin_pytorch_exportedprogram_adapter'] if torch else []) - + [ + '.builtin_pytorch_exportedprogram_adapter', '.builtin_mlir_adapter', ] ) From d4cb9db80ace986e8046edbee2d998c62e350b20 Mon Sep 17 00:00:00 2001 From: Jing Jin <8752427+jinjingforever@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:47:09 -0800 Subject: [PATCH 2/2] Reformat --- .../src/model_explorer/extension_manager.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/server/package/src/model_explorer/extension_manager.py b/src/server/package/src/model_explorer/extension_manager.py index 13ae654..cc023b3 100644 --- a/src/server/package/src/model_explorer/extension_manager.py +++ b/src/server/package/src/model_explorer/extension_manager.py @@ -29,17 +29,15 @@ class ExtensionManager(object, metaclass=Singleton): - BUILTIN_ADAPTER_MODULES: list[str] = ( - [ - '.builtin_tflite_flatbuffer_adapter', - '.builtin_tflite_mlir_adapter', - '.builtin_tf_mlir_adapter', - '.builtin_tf_direct_adapter', - '.builtin_graphdef_adapter', - '.builtin_pytorch_exportedprogram_adapter', - '.builtin_mlir_adapter', - ] - ) + BUILTIN_ADAPTER_MODULES: list[str] = [ + '.builtin_tflite_flatbuffer_adapter', + '.builtin_tflite_mlir_adapter', + '.builtin_tf_mlir_adapter', + '.builtin_tf_direct_adapter', + '.builtin_graphdef_adapter', + '.builtin_pytorch_exportedprogram_adapter', + '.builtin_mlir_adapter', + ] CACHED_REGISTERED_EXTENSIONS: Dict[str, RegisteredExtension] = {}