microsoft / hummingbird

Hummingbird compiles trained ML models into tensor computation for faster inference.
MIT License
3.34k stars 278 forks source link

AttributeError: 'NoneType' object has no attribute 'split' #706

Closed dintellect closed 1 year ago

dintellect commented 1 year ago

Hi Team,

My model conversion was working fine using 0.4.7 version of hummingbird-ml. When I am trying the same code to convert my XGBoost model, I am getting the below error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/5m/0j5rt4rj5_z6qtfd26q32cfm0000gn/T/ipykernel_11483/362657488.py in <module>
      1 from hummingbird.ml import convert
----> 2 hb_model = convert(clf, 'torch')

~/opt/anaconda3/lib/python3.9/site-packages/hummingbird/ml/convert.py in convert(model, backend, test_input, device, extra_config)
    442     """
    443     assert constants.REMAINDER_SIZE not in extra_config
--> 444     return _convert_common(model, backend, test_input, device, extra_config)
    445 
    446 

~/opt/anaconda3/lib/python3.9/site-packages/hummingbird/ml/convert.py in _convert_common(model, backend, test_input, device, extra_config)
    392 
    393     if type(model) in xgb_operator_list:
--> 394         return _convert_xgboost(model, backend_formatted, test_input, device, extra_config)
    395 
    396     if type(model) in lgbm_operator_list:

~/opt/anaconda3/lib/python3.9/site-packages/hummingbird/ml/convert.py in _convert_xgboost(model, backend, test_input, device, extra_config)
    151                 Please pass some test_input to the converter."
    152         )
--> 153     return _convert_sklearn(model, backend, test_input, device, extra_config)
    154 
    155 

~/opt/anaconda3/lib/python3.9/site-packages/hummingbird/ml/convert.py in _convert_sklearn(model, backend, test_input, device, extra_config)
     99     """
    100     assert model is not None
--> 101     if type(model).__name__ in [e[0] for e in all_estimators()]:
    102         assert check_is_fitted(estimator=model) is None
    103     assert_torch_installed()

~/opt/anaconda3/lib/python3.9/site-packages/sklearn/utils/discovery.py in all_estimators(type_filter)
     40     # lazy import to avoid circular imports from sklearn.base
     41     from . import IS_PYPY
---> 42     from ._testing import ignore_warnings
     43     from ..base import (
     44         BaseEstimator,

~/opt/anaconda3/lib/python3.9/site-packages/sklearn/utils/_testing.py in <module>
    398     fails_if_pypy = pytest.mark.xfail(IS_PYPY, reason="not compatible with PyPy")
    399     fails_if_unstable_openblas = pytest.mark.xfail(
--> 400         _in_unstable_openblas_configuration(),
    401         reason="OpenBLAS is unstable for this configuration",
    402     )

~/opt/anaconda3/lib/python3.9/site-packages/sklearn/utils/__init__.py in _in_unstable_openblas_configuration()
     88     import scipy  # noqa
     89 
---> 90     modules_info = threadpool_info()
     91 
     92     open_blas_used = any(info["internal_api"] == "openblas" for info in modules_info)

~/opt/anaconda3/lib/python3.9/site-packages/sklearn/utils/fixes.py in threadpool_info()
    160         return controller.info()
    161     else:
--> 162         return threadpoolctl.threadpool_info()
    163 
    164 

~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py in threadpool_info()
    122     In addition, each module may contain internal_api specific entries.
    123     """
--> 124     return _ThreadpoolInfo(user_api=_ALL_USER_APIS).todicts()
    125 
    126 

~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py in __init__(self, user_api, prefixes, modules)
    338 
    339             self.modules = []
--> 340             self._load_modules()
    341             self._warn_if_incompatible_openmp()
    342         else:

~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py in _load_modules(self)
    369         """Loop through loaded libraries and store supported ones"""
    370         if sys.platform == "darwin":
--> 371             self._find_modules_with_dyld()
    372         elif sys.platform == "win32":
    373             self._find_modules_with_enum_process_module_ex()

~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py in _find_modules_with_dyld(self)
    426 
    427             # Store the module if it is supported and selected
--> 428             self._make_module_from_path(filepath)
    429 
    430     def _find_modules_with_enum_process_module_ex(self):

~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py in _make_module_from_path(self, filepath)
    513             if prefix in self.prefixes or user_api in self.user_api:
    514                 module_class = globals()[module_class]
--> 515                 module = module_class(filepath, prefix, user_api, internal_api)
    516                 self.modules.append(module)
    517 

~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py in __init__(self, filepath, prefix, user_api, internal_api)
    604         self.internal_api = internal_api
    605         self._dynlib = ctypes.CDLL(filepath, mode=_RTLD_NOLOAD)
--> 606         self.version = self.get_version()
    607         self.num_threads = self.get_num_threads()
    608         self._get_extra_info()

~/opt/anaconda3/lib/python3.9/site-packages/threadpoolctl.py in get_version(self)
    644                              lambda: None)
    645         get_config.restype = ctypes.c_char_p
--> 646         config = get_config().split()
    647         if config[0] == b"OpenBLAS":
    648             return config[1].decode("utf-8")

AttributeError: 'NoneType' object has no attribute 'split' 

Can you please help with this?

interesaaat commented 1 year ago

It looks that this is a problem with threadpoolctl in sklearn. Can you open an issue with them?

dintellect commented 1 year ago

Thanks @interesaaat for a quick response. I will raise this issue to the sklearn. Do you think there are some modifications made on the sklearn end as I am using the same versions of all the libraries?

dintellect commented 1 year ago

Hey @interesaaat this issue is resolved by externally downloading the threadpoolctl package

!pip install threadpoolctl

interesaaat commented 1 year ago

Glad you were able to fix it!