Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try pickling model instead of failing based on state functions and change to UserConfigValidationException #2014

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions responsibleai/responsibleai/rai_insights/rai_base_insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import responsibleai
from responsibleai._internal.constants import (FileFormats, Metadata,
SerializationAttributes)
from responsibleai.exceptions import UserConfigValidationException

_DTYPES = 'dtypes'
_MODEL_PKL = Metadata.MODEL + FileFormats.PKL
Expand Down Expand Up @@ -186,11 +187,16 @@ def _save_model(self, path):
has_setstate = hasattr(self.model, '__setstate__')
has_getstate = hasattr(self.model, '__getstate__')
if not (has_setstate and has_getstate):
raise ValueError(
"Model must be picklable or a custom serializer must"
" be specified")
with open(top_dir / _MODEL_PKL, 'wb') as file:
pickle.dump(self.model, file)
warnings.warn(
"Model does not have __setstate__ and " +
"__getstate__, pickle may fail")
try:
with open(top_dir / _MODEL_PKL, 'wb') as file:
pickle.dump(self.model, file)
except Exception as e:
raise UserConfigValidationException(
"Model must be picklable or a custom serializer must"
" be specified") from e

def _save_managers(self, path):
"""Save the state of individual managers.
Expand Down