Получение TypeError при попытке сохранить Optuna.Study в обратном вызове optimize
Я провожу исследование Optuna, и когда я пытаюсь сохранить его с помощью joblib.dump
, Я получаю следующее:
TypeError: невозможно обработать объект _io.TextIOWrapper
Я также пытаюсь pickle.dump(study, open('name.pkl', 'wb'))
, но я получаю то же самое в обоих случаях РЕДАКТИРОВАТЬ: теперь я понял, что это как-то связано с тем фактом, что я делаю это в обратном вызове, в противном случае это работает Я обучаю пользовательскую модель PyTorch, все остальное, похоже, работает в условия самого исследования.. но когда я пытаюсь его сохранить, я получаю указанную выше ошибку. Я не знаю, как его отлаживать.
Окружающая среда:
- QubeOS с ВМ debian 10
- Python 3.8
- PyTorch 1.5
- Отредактировал Optuna 2.0: это трассировка стека:
File "<ipython-input-3-f2187f915338>", line 1, in <module>
joblib.dump(study, f'{filepath}.pkl')
File "/opt/conda/envs/torch_38/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 480, in dump
NumpyPickler(f, protocol=protocol).dump(value)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 485, in dump
self.save(obj)
File "/opt/conda/envs/torch_38/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 282, in save
return Pickler.save(self, obj)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 601, in save
self.save_reduce(obj=obj, *rv)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 715, in save_reduce
save(state)
File "/opt/conda/envs/torch_38/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 282, in save
return Pickler.save(self, obj)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 558, in save
f(self, obj) # Call unbound method with explicit self
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 969, in save_dict
self._batch_setitems(obj.items())
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 995, in _batch_setitems
save(v)
File "/opt/conda/envs/torch_38/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 282, in save
return Pickler.save(self, obj)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 601, in save
self.save_reduce(obj=obj, *rv)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 715, in save_reduce
save(state)
File "/opt/conda/envs/torch_38/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 282, in save
return Pickler.save(self, obj)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 558, in save
f(self, obj) # Call unbound method with explicit self
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 969, in save_dict
self._batch_setitems(obj.items())
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 995, in _batch_setitems
save(v)
File "/opt/conda/envs/torch_38/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 282, in save
return Pickler.save(self, obj)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 601, in save
self.save_reduce(obj=obj, *rv)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 715, in save_reduce
save(state)
File "/opt/conda/envs/torch_38/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 282, in save
return Pickler.save(self, obj)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 558, in save
f(self, obj) # Call unbound method with explicit self
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 969, in save_dict
self._batch_setitems(obj.items())
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 995, in _batch_setitems
save(v)
File "/opt/conda/envs/torch_38/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 282, in save
return Pickler.save(self, obj)
File "/opt/conda/envs/torch_38/lib/python3.8/pickle.py", line 576, in save
rv = reduce(self.proto)
TypeError: cannot pickle '_io.TextIOWrapper' object