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 Serialization Mangles NllLossBackward Objects in Tensor Objects #86696

Closed
dkostecki mannequin opened this issue Dec 2, 2020 · 2 comments
Closed

Pickle Serialization Mangles NllLossBackward Objects in Tensor Objects #86696

dkostecki mannequin opened this issue Dec 2, 2020 · 2 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dkostecki
Copy link
Mannequin

dkostecki mannequin commented Dec 2, 2020

BPO 42530
Nosy @serhiy-storchaka, @dkostecki

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-12-02.06:27:14.348>
created_at = <Date 2020-12-02.06:23:16.322>
labels = ['3.8', 'type-bug', 'library']
title = 'Pickle Serialization Mangles NllLossBackward Objects in Tensor Objects'
updated_at = <Date 2020-12-02.06:27:14.346>
user = 'https://github.com/dkostecki'

bugs.python.org fields:

activity = <Date 2020-12-02.06:27:14.346>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = True
closed_date = <Date 2020-12-02.06:27:14.348>
closer = 'serhiy.storchaka'
components = ['Library (Lib)']
creation = <Date 2020-12-02.06:23:16.322>
creator = 'dkostecki'
dependencies = []
files = []
hgrepos = []
issue_num = 42530
keywords = []
message_count = 2.0
messages = ['382294', '382295']
nosy_count = 2.0
nosy_names = ['serhiy.storchaka', 'dkostecki']
pr_nums = []
priority = 'normal'
resolution = 'third party'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42530'
versions = ['Python 3.8']

@dkostecki
Copy link
Mannequin Author

dkostecki mannequin commented Dec 2, 2020

torch.nn.functional.nll_loss returns Tensor objects which contain a loss value as well as a grad_fn object. Pickle does not throw an exception when serializing (dumps) the Tensor object. When loading (loads) the serialized data, the grad_fn object is lost and it becomes a requires_grad object.

However, if one attempts to serialize the grad_fn object encapsulated in the Tensor object, Pickle then throws a TypeError (TypeError: cannot pickle 'NllLossBackward' object). This behavior seems inconsistent. Perhaps serialization of NllLossBackward objects should be supported or their encapsulating Tensors should also throw a TypeError.

This behavior should be easily reproducible.

@dkostecki dkostecki mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 2, 2020
@serhiy-storchaka
Copy link
Member

Torch is not the part of the standard Python library. Please file the report on the Torch bug tracker.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant