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

Handling AttributeErrors while cleaning params namespace while setting up fit #3771

Closed
chiragraman opened this issue Oct 1, 2020 · 4 comments · Fixed by #4508
Closed

Handling AttributeErrors while cleaning params namespace while setting up fit #3771

chiragraman opened this issue Oct 1, 2020 · 4 comments · Fixed by #4508
Assignees
Labels
bug Something isn't working help wanted Open to be worked on

Comments

@chiragraman
Copy link
Contributor

🐛 Bug

is_picklable in parsing.py does not handle AttributeError thrown by pickle.dumps() - specifically, the following :
AttributeError: Can't pickle local object 'ArgumentParser.__init__.<locals>.identity'

To Reproduce

Here's a stack trace:

Traceback (most recent call last):
  File "/home/chirag/miniconda3/envs/ml/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/chirag/miniconda3/envs/ml/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/chirag/Projects/mingle/social-processes/run/run_synthetic_social.py", line 120, in <module>
    main()
  File "/home/chirag/Projects/mingle/social-processes/run/run_synthetic_social.py", line 116, in main
    trainer.fit(process, datamodule=dm)
  File "/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 425, in fit
    self.train_loop.setup_fit(model, train_dataloader, val_dataloaders, datamodule)
  File "/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/trainer/training_loop.py", line 90, in setup_fit
    parsing.clean_namespace(model.hparams)
  File "/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/parsing.py", line 75, in clean_namespace
    del_attrs = [k for k, v in hparams_dict.items() if not is_picklable(v)]
  File "/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/parsing.py", line 75, in <listcomp>
    del_attrs = [k for k, v in hparams_dict.items() if not is_picklable(v)]
  File "/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/parsing.py", line 62, in is_picklable
    pickle.dumps(obj)
AttributeError: Can't pickle local object 'ArgumentParser.__init__.<locals>.identity'

I forked the repo, found the file, and made the following change to is_picklable:

def is_picklable(obj: object) -> bool:
    """Tests if an object can be pickled"""

    try:
        pickle.dumps(obj)
        return True
    except (pickle.PicklingError, AttributeError):
        return False

I then installed the package from my local repo, ran the same code and got the following warnings:

/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/distributed.py:37: UserWarning: attribute 'trials' removed from hparams because it cannot be pickled
  warnings.warn(*args, **kwargs)
/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/distributed.py:37: UserWarning: attribute 'optimize_parallel' removed from hparams because it cannot be pickled
  warnings.warn(*args, **kwargs)
/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/distributed.py:37: UserWarning: attribute 'optimize_parallel_gpu' removed from hparams because it cannot be pickled
  warnings.warn(*args, **kwargs)
/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/distributed.py:37: UserWarning: attribute 'optimize_parallel_cpu' removed from hparams because it cannot be pickled
  warnings.warn(*args, **kwargs)
/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/distributed.py:37: UserWarning: attribute 'generate_trials' removed from hparams because it cannot be pickled
  warnings.warn(*args, **kwargs)
/home/chirag/miniconda3/envs/ml/lib/python3.8/site-packages/pytorch_lightning/utilities/distributed.py:37: UserWarning: attribute 'optimize_trials_parallel_gpu' removed from hparams because it cannot be pickled
  warnings.warn(*args, **kwargs)

These aren't params added by the end user I believe, and for some reason pickle raises an AttributeError rather than pickling.PicklingError for these.

Environment

  • CUDA:
    - GPU:
    - Quadro P4000
    - available: True
    - version: 10.2
  • Packages:
    - numpy: 1.19.1
    - pyTorch_debug: False
    - pyTorch_version: 1.6.0
    - pytorch-lightning: 0.9.1rc4
    - tqdm: 4.48.2
  • System:
    - OS: Linux
    - architecture:
    - 64bit
    - ELF
    - processor: x86_64
    - python: 3.8.5
    - version: Support of different batch types #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020

Additional context

Not sure if the solution is to also handle AttributeError, or if a more elegant alternative is needed.

@chiragraman chiragraman added bug Something isn't working help wanted Open to be worked on labels Oct 1, 2020
@edenlightning edenlightning modified the milestones: 0.9.x, 1.0, 1.1 Oct 2, 2020
@chiragraman
Copy link
Contributor Author

I believe these are added when using the HyperOptArgumentParser from test_tube.

@edenlightning edenlightning modified the milestones: 1.1, 1.0.3 Oct 19, 2020
@edenlightning
Copy link
Contributor

Thanks for the issue @chiragraman! Any way you can send a PR to fix?

@edenlightning edenlightning removed this from the 1.0.x milestone Oct 22, 2020
@chiragraman
Copy link
Contributor Author

@edenlightning sure thing! Is the suggested solution to also catch AttributeErrors alright?

@edenlightning
Copy link
Contributor

@Borda might have opinions on this

jtamir added a commit to jtamir/pytorch-lightning that referenced this issue Nov 4, 2020
rohitgr7 pushed a commit that referenced this issue Nov 4, 2020
* is_picklable: catch AttributeError (addresses #3771)

* edit

Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: chaton <[email protected]>
SeanNaren pushed a commit that referenced this issue Nov 10, 2020
* is_picklable: catch AttributeError (addresses #3771)

* edit

Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: chaton <[email protected]>
(cherry picked from commit 945d6f5)
SeanNaren pushed a commit that referenced this issue Nov 11, 2020
* is_picklable: catch AttributeError (addresses #3771)

* edit

Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: chaton <[email protected]>
(cherry picked from commit 945d6f5)
rohitgr7 pushed a commit that referenced this issue Nov 21, 2020
* is_picklable: catch AttributeError (addresses #3771)

* edit

Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: chaton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Open to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants