You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When upgrading pandas from 1.2.5 to the next version 1.3.0, self.save_hyperparameters() finally raises an error as (the previously working) yaml.dump(<pd.DataFrame>) does not work anymore.
See the traceback, but the error raises inside save_hparams_to_yaml(hparams_file, self.hparams) when yaml.dump() is called.
I see as possibilities
Exclude the dataframe parameters completely from saving
Traceback (most recent call last):
File "XXXX/01_MWE/hyperparameter/02_ptl_pandasissue_save_hyperparameter/main.py", line 65, in <module>
run()
File "XXXX/01_MWE/hyperparameter/02_ptl_pandasissue_save_hyperparameter/main.py", line 61, in run
trainer.fit(model, train_dataloaders=train_data, val_dataloaders=val_data)
File "XXX\.conda\envs\rmme_II\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 553, in fit
self._run(model)
File "XXX\.conda\envs\rmme_II\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 912, in _run
self._pre_dispatch()
File "XXX\.conda\envs\rmme_II\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 941, in _pre_dispatch
self._log_hyperparams()
File "XXX\.conda\envs\rmme_II\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 970, in _log_hyperparams
self.logger.save()
File "XXX\.conda\envs\rmme_II\lib\site-packages\pytorch_lightning\utilities\distributed.py", line 48, in wrapped_fn
return fn(*args, **kwargs)
File "XXX\.conda\envs\rmme_II\lib\site-packages\pytorch_lightning\loggers\tensorboard.py", line 249, in save
save_hparams_to_yaml(hparams_file, self.hparams)
File "XXX\.conda\envs\rmme_II\lib\site-packages\pytorch_lightning\core\saving.py", line 405, in save_hparams_to_yaml
yaml.dump(v)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\__init__.py", line 290, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\__init__.py", line 278, in dump_all
dumper.represent(data)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 27, in represent
node = self.represent_data(data)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 52, in represent_data
node = self.yaml_multi_representers[data_type](self, data)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 342, in represent_object
return self.represent_mapping(
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 118, in represent_mapping
node_value = self.represent_data(item_value)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 52, in represent_data
node = self.yaml_multi_representers[data_type](self, data)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 346, in represent_object
return self.represent_sequence(tag+function_name, args)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 92, in represent_sequence
node_item = self.represent_data(item)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 48, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 286, in represent_tuple
return self.represent_sequence('tag:yaml.org,2002:python/tuple', data)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 92, in represent_sequence
node_item = self.represent_data(item)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 52, in represent_data
node = self.yaml_multi_representers[data_type](self, data)
File "XXX\.conda\envs\rmme_II\lib\site-packages\yaml\representer.py", line 331, in represent_object
if function.__name__ == '__newobj__':
AttributeError: 'functools.partial' object has no attribute '__name__'
Process finished with exit code 1
The text was updated successfully, but these errors were encountered:
Like Thomas I am also not sure what can be done here. If an object passed into the constructor is not serializable then we have to explicitly ignore it (with the ignore argument in the save_hyperparameters). This is quite common for example when we pass in a backbone (nn.Module) which we also don't want to include as hyperparameter.
In your use case, did you actually intend to save the data frame or was it just accidental in the sense that you called save_hyperparameters() unconditionally out of habit?
In my usecase it was mainly out of habit. Actually, I do not really need it anymore as I moved to hydra for hyperparameter settings.
In principle I am totally fine removing the hyperparameter, maybe even removing the hyperparameter saving, but if I remember correctly I used those hyperparameters when training, stopping and go on learning again. But I am not sure about that.
However, the pandas issue got reopened, so maybe there will be a fix anyway.
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team!
🐛 Bug
I reported this issue already at pandas-dev/pandas#42748 and yaml/pyyaml#540 but both say that is not their problem.
When upgrading pandas from
1.2.5
to the next version1.3.0
,self.save_hyperparameters()
finally raises an error as (the previously working)yaml.dump(<pd.DataFrame>)
does not work anymore.See the traceback, but the error raises inside
save_hparams_to_yaml(hparams_file, self.hparams)
whenyaml.dump()
is called.I see as possibilities
yaml.dump(<pd.DataFrame>.to_dict())
To Reproduce
Expected behavior
Environment
conda
,pip
, source): piptorch.__config__.show()
:Additional context
Complete package list
Traceback
The text was updated successfully, but these errors were encountered: