sb-ai-lab / LightAutoML

Fast and customizable framework for automatic ML model creation (AutoML)
https://developers.sber.ru/portal/products/lightautoml
Apache License 2.0
1.18k stars 51 forks source link

Error during lib import in Kaggle and Colab #89

Closed dexforint closed 1 year ago

dexforint commented 1 year ago

TypeError: cannot set 'get_record_history_wrapper' attribute of immutable type 'object'

Full Error TypeError Traceback (most recent call last) Cell In[4], line 4 1 import pandas as pd 2 from sklearn.metrics import f1_score ----> 4 from lightautoml.automl.presets.tabular_presets import TabularAutoML 5 from lightautoml.tasks import Task File /opt/conda/lib/python3.10/site-packages/lightautoml/__init__.py:16 12 import importlib_metadata 14 __version__ = importlib_metadata.version(__name__) ---> 16 from .addons import * 17 from .addons.utilization import * 18 from .automl import * File /opt/conda/lib/python3.10/site-packages/lightautoml/addons/utilization/__init__.py:2 1 """Tools to configure resources utilization.""" ----> 2 from .utilization import TimeUtilization 4 __all__ = ['TimeUtilization'] File /opt/conda/lib/python3.10/site-packages/lightautoml/addons/utilization/utilization.py:8 4 from typing import Optional, Any, Sequence, Type, Union, Iterable 6 from log_calls import record_history ----> 8 from ...automl.base import AutoML 9 from ...automl.blend import Blender, BestModelSelector 10 from ...automl.presets.base import AutoMLPreset File /opt/conda/lib/python3.10/site-packages/lightautoml/automl/base.py:8 4 from typing import Sequence, Any, Optional, Iterable, Dict, List 6 from log_calls import record_history ----> 8 from .blend import Blender, BestModelSelector 9 from ..dataset.base import LAMLDataset 10 from ..dataset.utils import concatenate File /opt/conda/lib/python3.10/site-packages/lightautoml/automl/blend.py:9 6 from log_calls import record_history 7 from scipy.optimize import minimize_scalar ----> 9 from ..dataset.base import LAMLDataset 10 from ..dataset.np_pd_dataset import NumpyDataset 11 from ..dataset.roles import NumericRole File /opt/conda/lib/python3.10/site-packages/lightautoml/dataset/base.py:8 4 from typing import Any, Optional, Dict, List, Tuple, Sequence, Union, TypeVar 6 from log_calls import record_history ----> 8 from .roles import ColumnRole 9 from ..tasks.base import Task 11 valid_array_attributes = ('target', 'group', 'folds', 'weights') File /opt/conda/lib/python3.10/site-packages/lightautoml/dataset/roles.py:15 9 Dtype = Union[Callable, type, str] 12 # valid_features_str_names = [] 14 @record_history(enabled=False) ---> 15 class ColumnRole: 16 """Abstract class for column role. 17 18 Role type defines column dtype, (...) 22 23 """ 24 dtype = object File /opt/conda/lib/python3.10/site-packages/log_calls/log_calls.py:1691, in _deco_base.__call__(self, f_or_klass) 1684 self.cls = klass 1686 if klass: 1687 #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+* 1688 # 0.3.0 -- case "f_or_klass is a class" -- namely, klass 1689 #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+* -> 1691 self._class__call__(klass) # modifies klass (methods & inner classes) (if not builtin) 1692 self._add_class_attrs(klass) # v0.3.0v20 traps TypeError for builtins 1693 return klass File /opt/conda/lib/python3.10/site-packages/log_calls/log_calls.py:1482, in _deco_base._class__call__(self, klass) 1479 new_only = deco_obj._only or self._only 1480 new_omit += deco_obj._omit -> 1482 new_class = self.__class__( 1483 settings=new_settings, 1484 only=new_only, 1485 omit=new_omit 1486 )(item) 1487 # and replace in class dict 1488 setattr(klass, name, new_class) File /opt/conda/lib/python3.10/site-packages/log_calls/log_calls.py:1692, in _deco_base.__call__(self, f_or_klass) 1686 if klass: 1687 #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+* 1688 # 0.3.0 -- case "f_or_klass is a class" -- namely, klass 1689 #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+* 1691 self._class__call__(klass) # modifies klass (methods & inner classes) (if not builtin) -> 1692 self._add_class_attrs(klass) # v0.3.0v20 traps TypeError for builtins 1693 return klass 1695 elif not f: 1696 #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+* 1697 # 0.3.0 -- case "f_or_klass is a callable but not a function" (...) 1701 # Callable builtins e.g. len are not functions in the isfunction sense, 1702 # can't deco anyway. Just give up (quietly): File /opt/conda/lib/python3.10/site-packages/log_calls/log_calls.py:2138, in _deco_base._add_class_attrs(self, klass) 2136 this_deco_class = self.__class__ 2137 this_deco_class_name = this_deco_class.__name__ -> 2138 setattr( 2139 klass, 2140 'get_' + this_deco_class_name + '_wrapper', 2141 classmethod(partial(_get_deco_wrapper, this_deco_class)) 2142 ) 2143 # Make it even easier for methods to find their own log_calls wrappers, 2144 # via `get_own_log_calls_wrapper(fname)` 2145 # or `get_own_record_history_wrapper(fname)` 2146 # This can be called on a deco'd class or on an instance thereof. 2147 this_deco_class = self.__class__ TypeError: cannot set 'get_record_history_wrapper' attribute of immutable type 'object'
kehuydietlatoi commented 1 year ago

i got the same issue but in local environment with python 3.10 and here is the relevant issue https://github.com/sb-ai-lab/LightAutoML/issues/87

sumantabasak commented 1 year ago

Same issue I'm having

Ina612 commented 1 year ago

🐛 Bug when importing the following:

TypeError for all of them: cannot set 'get_record_history_wrapper' attribute of immutable type 'object'

The platforms where the issue occured:

Example:

from lightautoml.report.report_deco import ReportDeco

The error message:

TypeError                                 Traceback (most recent call last)
Cell In[14], line 1
----> 1 from lightautoml.report.report_deco import ReportDeco

File /opt/conda/lib/python3.10/site-packages/lightautoml/__init__.py:16
     12     import importlib_metadata
     14 __version__ = importlib_metadata.version(__name__)
---> 16 from .addons import *
     17 from .addons.utilization import *
     18 from .automl import *

File /opt/conda/lib/python3.10/site-packages/lightautoml/addons/utilization/__init__.py:2
      1 """Tools to configure resources utilization."""
----> 2 from .utilization import TimeUtilization
      4 __all__ = ['TimeUtilization']

File /opt/conda/lib/python3.10/site-packages/lightautoml/addons/utilization/utilization.py:8
      4 from typing import Optional, Any, Sequence, Type, Union, Iterable
      6 from log_calls import record_history
----> 8 from ...automl.base import AutoML
      9 from ...automl.blend import Blender, BestModelSelector
     10 from ...automl.presets.base import AutoMLPreset

File /opt/conda/lib/python3.10/site-packages/lightautoml/automl/base.py:8
      4 from typing import Sequence, Any, Optional, Iterable, Dict, List
      6 from log_calls import record_history
----> 8 from .blend import Blender, BestModelSelector
      9 from ..dataset.base import LAMLDataset
     10 from ..dataset.utils import concatenate

File /opt/conda/lib/python3.10/site-packages/lightautoml/automl/blend.py:9
      6 from log_calls import record_history
      7 from scipy.optimize import minimize_scalar
----> 9 from ..dataset.base import LAMLDataset
     10 from ..dataset.np_pd_dataset import NumpyDataset
     11 from ..dataset.roles import NumericRole

File /opt/conda/lib/python3.10/site-packages/lightautoml/dataset/base.py:8
      4 from typing import Any, Optional, Dict, List, Tuple, Sequence, Union, TypeVar
      6 from log_calls import record_history
----> 8 from .roles import ColumnRole
      9 from ..tasks.base import Task
     11 valid_array_attributes = ('target', 'group', 'folds', 'weights')

File /opt/conda/lib/python3.10/site-packages/lightautoml/dataset/roles.py:15
      9 Dtype = Union[Callable, type, str]
     12 # valid_features_str_names = []
     14 @record_history(enabled=False)
---> 15 class ColumnRole:
     16     """Abstract class for column role.
     17 
     18     Role type defines column dtype,
   (...)
     22 
     23     """
     24     dtype = object

File /opt/conda/lib/python3.10/site-packages/log_calls/log_calls.py:1691, in _deco_base.__call__(self, f_or_klass)
   1684 self.cls = klass
   1686 if klass:
   1687     #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
   1688     # 0.3.0 -- case "f_or_klass is a class" -- namely, klass
   1689     #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
-> 1691     self._class__call__(klass)      # modifies klass (methods & inner classes) (if not builtin)
   1692     self._add_class_attrs(klass)    # v0.3.0v20 traps TypeError for builtins
   1693     return klass

File /opt/conda/lib/python3.10/site-packages/log_calls/log_calls.py:1482, in _deco_base._class__call__(self, klass)
   1479     new_only = deco_obj._only or self._only
   1480     new_omit += deco_obj._omit
-> 1482 new_class = self.__class__(
   1483     settings=new_settings,
   1484     only=new_only,
   1485     omit=new_omit
   1486 )(item)
   1487 # and replace in class dict
   1488 setattr(klass, name, new_class)

File /opt/conda/lib/python3.10/site-packages/log_calls/log_calls.py:1692, in _deco_base.__call__(self, f_or_klass)
   1686 if klass:
   1687     #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
   1688     # 0.3.0 -- case "f_or_klass is a class" -- namely, klass
   1689     #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
   1691     self._class__call__(klass)      # modifies klass (methods & inner classes) (if not builtin)
-> 1692     self._add_class_attrs(klass)    # v0.3.0v20 traps TypeError for builtins
   1693     return klass
   1695 elif not f:
   1696     #+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
   1697     # 0.3.0 -- case "f_or_klass is a callable but not a function"
   (...)
   1701     # Callable builtins e.g. len are not functions in the isfunction sense,
   1702     # can't deco anyway. Just give up (quietly):

File /opt/conda/lib/python3.10/site-packages/log_calls/log_calls.py:2138, in _deco_base._add_class_attrs(self, klass)
   2136 this_deco_class = self.__class__
   2137 this_deco_class_name = this_deco_class.__name__
-> 2138 setattr(
   2139     klass,
   2140     'get_' + this_deco_class_name + '_wrapper',
   2141     classmethod(partial(_get_deco_wrapper, this_deco_class))
   2142 )
   2143 # Make it even easier for methods to find their own log_calls wrappers,
   2144 # via `get_own_log_calls_wrapper(fname)`
   2145 # or `get_own_record_history_wrapper(fname)`
   2146 # This can be called on a deco'd class or on an instance thereof.
   2147 this_deco_class = self.__class__

TypeError: cannot set 'get_record_history_wrapper' attribute of immutable type 'object'

Why it may occur: It may be due to an incompatibility between the log_calls library and the lightautoml library.

The log_calls library is attempting to set the 'get_record_history_wrapper' of an immutable object. Immutable objects cannot have their attributes modified once they are defined.

sumantabasak commented 1 year ago

@dev-rinchin is this issue resolved now? Is there a workout? I'm still facing this challenge.

alexmryzhkov commented 1 year ago

@dexforint @sumantabasak @kehuydietlatoi @Ina612 ,

please try to use the latest lightautoml version:

pip install -U lightautoml==0.3.8b1

This will fix your problem.

Alex