From ef1fa890fa8f769c62b0611a56e79c79a42ce4d4 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Patel <131133949+ajay-fuji@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:26:58 +0530 Subject: [PATCH] Fix: Do not import onedal when OFF_ONEDAL_IFACE=1 (#1744) * Fix: Do not import onedal when OFF_ONEDAL_IFACE=1 * Added copyright * Update condition code to unset OFF_ONEDAL_IFACE when set to 0 * Update and add Copyright * Update to os.environ.get(..) for uniformity --------- Co-authored-by: Darshan Patel Co-authored-by: Ajay Kumar Patel --- setup.py | 3 ++- sklearnex/__init__.py | 14 ++++++++------ sklearnex/dispatcher.py | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index a1d25568d7..4d6f92a202 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ #! /usr/bin/env python # ============================================================================== # Copyright 2014 Intel Corporation +# Copyright 2024 Fujitsu Limited # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -72,7 +73,7 @@ ONEDAL_2021_3 = 2021 * 10000 + 3 * 100 ONEDAL_2023_0_1 = 2023 * 10000 + 0 * 100 + 1 is_onedal_iface = ( - os.environ.get("OFF_ONEDAL_IFACE") is None and ONEDAL_VERSION >= ONEDAL_2021_3 + os.environ.get("OFF_ONEDAL_IFACE", "0") == "0" and ONEDAL_VERSION >= ONEDAL_2021_3 ) d4p_version = ( diff --git a/sklearnex/__init__.py b/sklearnex/__init__.py index c3f9e586e6..f9d8b21d1d 100755 --- a/sklearnex/__init__.py +++ b/sklearnex/__init__.py @@ -1,5 +1,6 @@ # ============================================================================== # Copyright 2021 Intel Corporation +# Copyright 2024 Fujitsu Limited # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,7 +15,7 @@ # limitations under the License. # ============================================================================== -from onedal.common.hyperparameters import get_hyperparameters +import os from . import utils from ._config import config_context, get_config, set_config @@ -50,12 +51,13 @@ "unpatch_sklearn", "utils", ] +onedal_iface_flag = os.environ.get("OFF_ONEDAL_IFACE", "0") +if onedal_iface_flag == "0": + from onedal import _is_spmd_backend + from onedal.common.hyperparameters import get_hyperparameters - -from onedal import _is_spmd_backend - -if _is_spmd_backend: - __all__.append("spmd") + if _is_spmd_backend: + __all__.append("spmd") from ._utils import set_sklearn_ex_verbose diff --git a/sklearnex/dispatcher.py b/sklearnex/dispatcher.py index 04bf07fe1f..a5194bc551 100644 --- a/sklearnex/dispatcher.py +++ b/sklearnex/dispatcher.py @@ -1,5 +1,6 @@ # ============================================================================== # Copyright 2021 Intel Corporation +# Copyright 2024 Fujitsu Limited # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,7 +23,7 @@ def _is_new_patching_available(): - return os.environ.get("OFF_ONEDAL_IFACE") is None and daal_check_version( + return os.environ.get("OFF_ONEDAL_IFACE", "0") == "0" and daal_check_version( (2021, "P", 300) )