Skip to content

[C++ API] Fix Sequential::clone()#9372

Closed
goldsborough wants to merge 2 commits intopytorch:masterfrom
goldsborough:seq-clone
Closed

[C++ API] Fix Sequential::clone()#9372
goldsborough wants to merge 2 commits intopytorch:masterfrom
goldsborough:seq-clone

Conversation

@goldsborough
Copy link
Contributor

I noticed that Sequential::clone() does not work. This is because Sequential does not use reset() which is normally where modules have to initialize and register its submodules. Further, this is because of the way Sequential allows its modules to be passed in the constructor, which doesn't work with reset() (since it does "late" initialization).

I've added some better error messages inside Cloneable::clone() which makes this kind of mistake clearer for other users, and tests for Sequential::clone().

I also had to give AnyModule a deep clone() method.

@ebetica @ezyang

This comment was marked as off-topic.

@goldsborough
Copy link
Contributor Author

@pytorchbot retest this please

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goldsborough has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

/// own.
/// Special cloning function for `Sequential` because it does not use
/// `reset()`.
std::shared_ptr<Module> clone() const override {

This comment was marked as off-topic.

This comment was marked as off-topic.

@goldsborough goldsborough deleted the seq-clone branch July 17, 2018 17:16
goldsborough added a commit to goldsborough/pytorch that referenced this pull request Jul 20, 2018
Summary:
I noticed that `Sequential::clone()` does not work. This is because `Sequential` does not use `reset()` which is normally where modules have to initialize and register its submodules. Further, this is because of the way `Sequential` allows its modules to be passed in the constructor, which doesn't work with `reset()` (since it does "late" initialization).

I've added some better error messages inside `Cloneable::clone()` which makes this kind of mistake clearer for other users, and tests for `Sequential::clone()`.

I also had to give `AnyModule` a deep `clone()` method.

ebetica ezyang
Pull Request resolved: pytorch#9372

Differential Revision: D8865189

Pulled By: goldsborough

fbshipit-source-id: b81586e0d3157cd3c4265b19ac8dd87c5d8dcf94
jramseyer pushed a commit to jramseyer/pytorch that referenced this pull request Jul 30, 2018
Summary:
I noticed that `Sequential::clone()` does not work. This is because `Sequential` does not use `reset()` which is normally where modules have to initialize and register its submodules. Further, this is because of the way `Sequential` allows its modules to be passed in the constructor, which doesn't work with `reset()` (since it does "late" initialization).

I've added some better error messages inside `Cloneable::clone()` which makes this kind of mistake clearer for other users, and tests for `Sequential::clone()`.

I also had to give `AnyModule` a deep `clone()` method.

ebetica ezyang
Pull Request resolved: pytorch#9372

Differential Revision: D8865189

Pulled By: goldsborough

fbshipit-source-id: b81586e0d3157cd3c4265b19ac8dd87c5d8dcf94
goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
Summary:
I noticed that `Sequential::clone()` does not work. This is because `Sequential` does not use `reset()` which is normally where modules have to initialize and register its submodules. Further, this is because of the way `Sequential` allows its modules to be passed in the constructor, which doesn't work with `reset()` (since it does "late" initialization).

I've added some better error messages inside `Cloneable::clone()` which makes this kind of mistake clearer for other users, and tests for `Sequential::clone()`.

I also had to give `AnyModule` a deep `clone()` method.

ebetica ezyang
Pull Request resolved: pytorch#9372

Differential Revision: D8865189

Pulled By: goldsborough

fbshipit-source-id: b81586e0d3157cd3c4265b19ac8dd87c5d8dcf94
@ezyang ezyang added the merged label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants