orobix / fwdgrad

Implementation of "Gradients without backpropagation" paper (https://arxiv.org/abs/2202.08587) using functorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: Can't pickle local object 'train_model.<locals>.<lambda>'

ChiragJRana opened this issue · comments

Hello!
I am trying to run the mnist_backprop.py and mnist_fwd_grad.py files on my local repository, But getting this error. If the same repo I run on Google Colab, I do not face the issue. I feel its mostly a version error and hence wanted to know more about the environment details.

The error details message:

d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\site-packages\torch_functorch\deprecated.py:97: UserWarning: We've integrated functorch into PyTorch. As the final step of the integration, functorch.make_functional is deprecated as of PyTorch 2.0 and will be deleted in a future version of PyTorch >= 2.3. Please use torch.func.functional_call instead; see the PyTorch 2.0 release notes and/or the torch.func migration guide for more details https://pytorch.org/docs/master/func.migrating.html
warn_deprecated('make_functional', 'torch.func.functional_call')
Error executing job with overrides: []
Traceback (most recent call last):
File "D:\Masters\Academics\Semester_2\DISML\Project\distributed_fwdgrad\src\fwdgrad\mnist_fwdgrad.py", line 60, in train_model
for i, batch in enumerate(train_loader):
File "d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\site-packages\torch\utils\data\dataloader.py", line 442, in iter
return self._get_iterator()
File "d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\site-packages\torch\utils\data\dataloader.py", line 388, in _get_iterator
return _MultiProcessingDataLoaderIter(self)
File "d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\site-packages\torch\utils\data\dataloader.py", line 1043, in init
w.start()
File "d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\multiprocessing\popen_spawn_win32.py", line 93, in init
reduction.dump(process_obj, to_child)
File "d:\Masters\Academics\Semester_2\DISML\Project.conda\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'train_model..'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

Hi @ChiragJRana, which operating system are you using? Everything i've tested was on Linux OS.
Can you also try out this branch please?

I was testing this out as well and apparently windows doesn't support the use of lambda inside of torchvision.transforms.Lambda()

You need to write a new function to replace the lambda function. This worked for me.

def fuc_flatten(x):
return torch.flatten(x)

and the use transform.append(torchvision.transforms.Lambda(fuc_flatten))