Skip to content

Commit

Permalink
Drop init message (#3151)
Browse files Browse the repository at this point in the history
### Changes

- As stated in the title.

### Reason for changes

- Follow up #3138

### Related tickets

- N/A

### Tests

- N/A
  • Loading branch information
KodiaqQ authored Dec 19, 2024
1 parent 579a301 commit 939d13e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 122 deletions.
5 changes: 0 additions & 5 deletions nncf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,3 @@
"Please install one of the supported frameworks above in order to use NNCF on top of it.\n"
"See the installation guide at https://github.com/openvinotoolkit/nncf#installation-guide for help."
)
else:
nncf_logger.info(
f"NNCF initialized successfully. Supported frameworks detected: "
f"{', '.join([name for name, loaded in _AVAILABLE_FRAMEWORKS.items() if loaded])}"
)
55 changes: 12 additions & 43 deletions nncf/common/utils/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import importlib
from copy import deepcopy
from enum import Enum
from typing import Any, Callable, List, TypeVar
from typing import Any, Callable, TypeVar

import nncf

Expand All @@ -30,37 +29,12 @@ def result_verifier(func: Callable[[TModel], bool]) -> Callable[..., None]:
def verify_result(*args: Any, **kwargs: Any): # type: ignore
try:
return func(*args, **kwargs)
except AttributeError:
except Exception:
return False

return verify_result


def get_available_backends() -> List[BackendType]:
"""
Returns a list of available backends.
:return: A list of available backends.
"""
frameworks = [
("torch", BackendType.TORCH),
("torch.fx", BackendType.TORCH_FX),
("tensorflow", BackendType.TENSORFLOW),
("onnx", BackendType.ONNX),
("openvino.runtime", BackendType.OPENVINO),
]

available_backends = []
for module_name, backend in frameworks:
try:
importlib.import_module(module_name)
available_backends.append(backend)
except ImportError:
pass

return available_backends


@result_verifier
def is_torch_model(model: TModel) -> bool:
"""
Expand Down Expand Up @@ -147,27 +121,22 @@ def get_backend(model: TModel) -> BackendType:
:param model: The framework-specific model.
:return: A BackendType representing the correct NNCF backend to be used when working with the framework.
"""
available_backends = get_available_backends()

if BackendType.TORCH_FX in available_backends and is_torch_fx_model(model):
return BackendType.TORCH_FX

if BackendType.TORCH in available_backends and is_torch_model(model):
return BackendType.TORCH

if BackendType.TENSORFLOW in available_backends and is_tensorflow_model(model):
return BackendType.TENSORFLOW

if BackendType.ONNX in available_backends and is_onnx_model(model):
return BackendType.ONNX
verify_map = {
is_torch_fx_model: BackendType.TORCH_FX,
is_torch_model: BackendType.TORCH,
is_tensorflow_model: BackendType.TENSORFLOW,
is_onnx_model: BackendType.ONNX,
is_openvino_model: BackendType.OPENVINO,
}

if BackendType.OPENVINO in available_backends and is_openvino_model(model):
return BackendType.OPENVINO
for backend_call, backend in verify_map.items():
if backend_call(model):
return backend

raise nncf.UnsupportedBackendError(
"Could not infer the backend framework from the model type because "
"the framework is not available or corrupted, or the model type is unsupported. "
"The available frameworks found: {}.".format(", ".join([b.value for b in available_backends]))
)


Expand Down
74 changes: 0 additions & 74 deletions tests/common/test_framework_detection.py

This file was deleted.

0 comments on commit 939d13e

Please sign in to comment.