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

_pickle.PicklingError: Can't pickle <class 'boto3.resources.factory.s3.ServiceResource'>: attribute lookup s3.ServiceResource on boto3.resources.factory failed #2741

Closed
karliesama opened this issue Jan 27, 2021 · 6 comments
Assignees
Labels
duplicate This issue is a duplicate. feature-request This issue requests a feature.

Comments

@karliesama
Copy link

karliesama commented Jan 27, 2021

I want to try my model. The data is saved in AWS. I use boto3 simply like

        self.s3_img = S3Images(boto3.resource('s3'))
        self.s3_obj = S3GetObjects()

I met this error when I feed the data and model in to the pytorch training pipeline.

The code looks like

import pytorch_lightning as pl
from pytorch_lightning import Trainer
trainer = Trainer(
        checkpoint_callback=checkpoint_callback,
        callbacks=get_callbacks(chkpt_path),
        fast_dev_run=False,
        max_epochs=100,
        resume_from_checkpoint=checkpoint_path
    )
trainer.fit(model)

The error is

  File "main.py", line 191, in <module>
    train()
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/hydra/main.py", line 20, in decorated_main
    run_hydra(
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/hydra/_internal/utils.py", line 171, in run_hydra
    hydra.run(
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/hydra/_internal/hydra.py", line 82, in run
    return run_job(
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/hydra/plugins/common/utils.py", line 109, in run_job
    ret.return_value = task_function(task_cfg)
  File "main.py", line 176, in train
    trainer.fit(model)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/pytorch_lightning/trainer/states.py", line 48, in wrapped_fn
    result = fn(self, *args, **kwargs)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1084, in fit
    results = self.accelerator_backend.train(model)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/pytorch_lightning/accelerators/cpu_backend.py", line 39, in train
    results = self.trainer.run_pretrain_routine(model)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1224, in run_pretrain_routine
    self._run_sanity_check(ref_model, model)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1257, in _run_sanity_check
    eval_results = self._evaluate(model, self.val_dataloaders, max_batches, False)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/pytorch_lightning/trainer/evaluation_loop.py", line 305, in _evaluate
    for batch_idx, batch in enumerate(dataloader):
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 352, in __iter__
    return self._get_iterator()
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 294, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 801, in __init__
    w.start()
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Users/admin/opt/anaconda3/envs/kk/lib/python3.8/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'boto3.resources.factory.s3.ServiceResource'>: attribute lookup s3.ServiceResource on boto3.resources.factory failed

Can anyone tell me what's the meaning of this error and how to solve it? Thanks for any suggestions and help!

@karliesama karliesama added the needs-triage This issue or PR still needs to be triaged. label Jan 27, 2021
@swetashre swetashre self-assigned this Jan 27, 2021
@swetashre
Copy link
Contributor

@karliesama - Boto3 resources are not pickleable/serializable. This would be a feature request. We are tracking this feature request under the issue #678

@swetashre
Copy link
Contributor

I found this stack overflow post which might be useful
https://stackoverflow.com/questions/11658511/pickling-dynamically-generated-classes

@swetashre swetashre added feature-request This issue requests a feature. duplicate This issue is a duplicate. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 28, 2021
@karliesama
Copy link
Author

Hi! I found that I won't have this error if I use python 3.7 but got this error with 3.8. 3.8 includes a new way to pickle objects.

@swetashre swetashre assigned kdaily and unassigned swetashre Mar 25, 2021
@isvogor-foi
Copy link

Any updates on this?

@kdaily
Copy link
Member

kdaily commented Sep 1, 2021

Hi @isvogor-foi,

No updates to provide. However as previously mentioned, we should track this under #678. Closing this out now!

@kdaily kdaily closed this as completed Sep 1, 2021
@github-actions
Copy link

github-actions bot commented Sep 1, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue is a duplicate. feature-request This issue requests a feature.
Projects
None yet
Development

No branches or pull requests

4 participants