question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deep copy error on modules implementing MessagePassing

See original GitHub issue

🐛 Bug

Since pytorch_geometric version 1.4 modules derived from the class MessagePassing cannot be deep copied (no issues with older versions).

To Reproduce

Just run the following lines (same issue occurring with any other layer derived from MessagePassing)

import copy
import torch_geometric
gconv = torch_geometric.nn.GCNConv(1,1)
copy.deepcopy(gconv)

which produce:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/opt/conda/lib/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/opt/conda/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/opt/conda/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/opt/conda/lib/python3.6/copy.py", line 169, in deepcopy
    rv = reductor(4)
TypeError: can't pickle mappingproxy objects

Expected behavior

Should have produced a new deep copy of the object instead.

Environment

Nvidia DGX station

Virtual environment with:

  • torch 1.4
  • torch_geometric 1.4.1

Additional context

A deep copy is necessary in order to copy models or parts of models whose weighs are later altered.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
rusty1scommented, Feb 18, 2020

Fixed with 1.4.2.

0reactions
tjiagoMcommented, Feb 14, 2020

Awesome!! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deep copy error on modules implementing MessagePassing
Bug Since pytorch_geometric version 1.4 modules derived from the class MessagePassing cannot be deep copied (no issues with older versions).
Read more >
copy.deepcopy raises TypeError on objects with self- ...
one problem is that deepcopy and copy have no way of knowing which arguments to pass to __new__ , therefore they only work...
Read more >
Shallow and deep copy operations
This module provides generic shallow and deep copy operations (explained below). ... The latter is called to implement the deep copy operation; it...
Read more >
copy – Duplicate objects - Python Module of the Week
Any member attributes that need to be deep-copied should be passed to copy.deepcopy(), along with the memo dictionary, to control for recursion (see...
Read more >
OMNeT++ - Simulation Manual - Index of - omnetpp.org
The depth of module nesting is not limited. Modules communicate through message passing, where messages may carry arbitrary data structures. Modules can pass ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found