Skip to content

Conversation

@goldsborough
Copy link
Contributor

@goldsborough goldsborough commented Jul 10, 2018

To allow our C++ customers to use our initialization methods as well, this PR moves some of the code from torch.nn.init to ATen, calls it from Python, and adds equivalent code to the C++ frontend.

Notes:

  1. Happy to hear thoughts on whether it's ok to have e.g. torch.nn.init.dirac_ and torch.dirac_ (the former has a no_grad guard). We have this for ones_ and stuff too, so I don't mind it.
  2. I left the exception checking in Python because they throw ValueErrors while ATen errors show as RuntimeErrors. I imagine this would break users' error handling if someone were to have a try-except handler for ValueError (or maybe it's a far fetch)

EDIT: After discussions with @zdevito, the PR now simply duplicates the code in C++ exclusively for the C++ API, and we leave the Python code as-is (to make it easier for people to read/modify).

@ebetica @ezyang @apaszke

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@goldsborough goldsborough changed the title [WIP] Move some initialization methods to ATen [C++ API] Initialization functions Jul 10, 2018
@goldsborough
Copy link
Contributor Author

@pytorchbot retest this please

Tensor sparse_(Tensor tensor, double sparsity, double std = 0.01);
Tensor uniform_(Tensor tensor, double low = 0, double high = 1);
Tensor xavier_normal_(Tensor tensor, double gain = 1.0);
Tensor xavier_uniform_(Tensor tensor, double gain = 1.0);

This comment was marked as off-topic.

This comment was marked as off-topic.

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

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

Looks good.

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

goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
Summary:
To allow our C++  customers to use our initialization methods as well, this PR moves some of the code from `torch.nn.init` to ATen, calls it from Python, and adds equivalent code to the C++ frontend.

Notes:
1. Happy to hear thoughts on whether it's ok to have e.g. `torch.nn.init.dirac_` *and* `torch.dirac_` (the former has a `no_grad` guard). We have this for `ones_` and stuff too, so I don't mind it.
2. I left the exception checking in Python because they throw `ValueError`s while ATen errors show as `RuntimeError`s. I imagine this would break users' error handling if someone were to have a `try`-`except` handler for `ValueError` (or maybe it's a far fetch)

EDIT: After discussions with zdevito, the PR now simply duplicates the code in C++ exclusively for the C++ API, and we leave the Python code as-is (to make it easier for people to read/modify).

ebetica ezyang apaszke
Pull Request resolved: pytorch#9295

Differential Revision: D8813793

Pulled By: goldsborough

fbshipit-source-id: 4b969f3f75952c1be4e837e19e23b8098e5fbd4b
@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.

7 participants