From 98b286ace603b72d400c8f689466448d25775747 Mon Sep 17 00:00:00 2001 From: Ilya Matiach Date: Wed, 29 Mar 2023 13:22:56 -0400 Subject: [PATCH] try pickling model instead of failing based on state functions and change to UserConfigValidationException --- .../rai_insights/rai_base_insights.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/responsibleai/responsibleai/rai_insights/rai_base_insights.py b/responsibleai/responsibleai/rai_insights/rai_base_insights.py index 5080b6aaed..f108b41fe3 100644 --- a/responsibleai/responsibleai/rai_insights/rai_base_insights.py +++ b/responsibleai/responsibleai/rai_insights/rai_base_insights.py @@ -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 @@ -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.