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

[auto] fix pickle error, more tolerant #1692

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion gluoncv/auto/estimators/base_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ def save(self, filename):
The file name for storing the full state.
"""
with open(filename, 'wb') as fid:
pickle.dump(self, fid)
try:
pickle.dump(self, fid)
except pickle.PicklingError as e:
self._logger.warning(f"Unable to pickle object due to the reason: {str(e)}. This object is not saved.")
return
self._logger.debug('Pickled to %s', filename)

@classmethod
Expand Down
10 changes: 8 additions & 2 deletions gluoncv/auto/tasks/image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ def _train_image_classification(args, reporter):
'time': time.time() - tic, 'train_acc': -1, 'valid_acc': -1}

if estimator:
result.update({'model_checkpoint': pickle.dumps(estimator)})
try:
result.update({'model_checkpoint': pickle.dumps(estimator)})
except pickle.PicklingError:
result.update({'model_checkpoint': estimator})
result.update({'estimator': estimator_cls})
return result

Expand Down Expand Up @@ -439,7 +442,10 @@ def fit(self, train_data, val_data=None, train_size=0.9, random_state=None, time
if results.get('traceback', '') == 'timeout':
raise TimeoutError(f'Unable to fit a usable model given `time_limit={time_limit}`')
raise RuntimeError(f'Unexpected error happened during fit: {pprint.pformat(results, indent=2)}')
estimator = pickle.loads(results['model_checkpoint'])
if isinstance(results['model_checkpoint'], bytes):
estimator = pickle.loads(results['model_checkpoint'])
else:
estimator = results['model_checkpoint']
return estimator

def fit_summary(self):
Expand Down