Skip to content

[C++ API] Change behavior of clone to clone to a device#9609

Closed
goldsborough wants to merge 1 commit intopytorch:masterfrom
goldsborough:clone-to
Closed

[C++ API] Change behavior of clone to clone to a device#9609
goldsborough wants to merge 1 commit intopytorch:masterfrom
goldsborough:clone-to

Conversation

@goldsborough
Copy link
Contributor

@goldsborough goldsborough commented Jul 20, 2018

@ebetica made me aware that nn::Module::clone() always clones to the current device (usually CPU) instead of preserving the device of each parameter. This PR changes the signature of clone from

shared_ptr<Module> clone()

to

shared_ptr<Module> clone(optional<Device> device = nullopt)

with semantics of:

  1. If a device is given, all parameters/buffers are moved to that device,
  2. If no device is supplied (default), parameters/buffers retain their device.

@ezyang @apaszke @ebetica

@goldsborough goldsborough changed the title [C++ ]Change behavior of clone to clone to a device [C++] Change behavior of clone to clone to a device Jul 20, 2018
@goldsborough goldsborough changed the title [C++] Change behavior of clone to clone to a device [C++ API] Change behavior of clone to clone to a device Jul 20, 2018
@goldsborough
Copy link
Contributor Author

@pytorchbot retest this please

1 similar comment
@ezyang
Copy link
Contributor

ezyang commented Jul 23, 2018

@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.

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 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

jramseyer pushed a commit to jramseyer/pytorch that referenced this pull request Jul 30, 2018
Summary:
ebetica made me aware that `nn::Module::clone()` always clones to the current device (usually CPU) instead of preserving the device of each parameter. This PR changes the signature of `clone` from

`shared_ptr<Module> clone()`

to

`shared_ptr<Module> clone(optional<Device> device = nullopt)`

with semantics of:

1. If a `device` is given, all parameters/buffers are moved to that device,
2. If no `device` is supplied (default), parameters/buffers retain their device.

ezyang apaszke ebetica
Pull Request resolved: pytorch#9609

Differential Revision: D8957367

Pulled By: goldsborough

fbshipit-source-id: 0d409ae645ed2b8d97d6fc060240de2f3d4bc6c8
goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
Summary:
ebetica made me aware that `nn::Module::clone()` always clones to the current device (usually CPU) instead of preserving the device of each parameter. This PR changes the signature of `clone` from

`shared_ptr<Module> clone()`

to

`shared_ptr<Module> clone(optional<Device> device = nullopt)`

with semantics of:

1. If a `device` is given, all parameters/buffers are moved to that device,
2. If no `device` is supplied (default), parameters/buffers retain their device.

ezyang apaszke ebetica
Pull Request resolved: pytorch#9609

Differential Revision: D8957367

Pulled By: goldsborough

fbshipit-source-id: 0d409ae645ed2b8d97d6fc060240de2f3d4bc6c8
@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