Skip to content

Conversation

@yf225
Copy link
Contributor

@yf225 yf225 commented Oct 14, 2019

C++ API Module::register_parameter should accept undefined Tensor as parameter, which is equivalent to module.register_parameter("param", None) in Python API.

This unblocks #26082 and #27156.

Will Feng added 2 commits October 14, 2019 19:08
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.

@yf225 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@yf225 merged this pull request in 801b6cd.

@gchanan
Copy link
Contributor

gchanan commented Oct 16, 2019

why do it this way instead of optional<Tensor>? Which is our plan for user-facing APIs that may take None, consistent with all our other types that take None.

@yf225
Copy link
Contributor Author

yf225 commented Oct 16, 2019

@gchanan I feel that I need to make this consistent with how we represent a nullable Tensor within a C++ module, and I think there are two issues with using optional<Tensor> as nullable Tensor within a module:

  1. If a user implements their own custom C++ module that has both nullable Tensors (e.g. torch::nn::Linear has nullable Tensor) and non-nullable Tensors, there will be two types of Tensors in their module (Tensor and optional<Tensor>), which I feel that it's not great from API simplicity point of view.
  2. Custom autograd functions won't be able to use variable_list to represent inputs / outputs anymore (because some of those Tensors can be null). To address this we can add an optional_variable_list type, but I am a bit unsure if there is any other obstacle to this. cc. @ezyang

@gchanan
Copy link
Contributor

gchanan commented Oct 16, 2019

  1. Idk that seems good. It says exactly what the state is. It's much clearer than what an "undefined tensor" means.
  2. Yah, that's a good point. I don't know if there will be a noticeable performance difference in using optionals in those lists.

thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
…#27948)

Summary:
C++ API `Module::register_parameter` should accept undefined Tensor as parameter, which is equivalent to `module.register_parameter("param", None)` in Python API.

This unblocks pytorch#26082 and pytorch#27156.
Pull Request resolved: pytorch#27948

Differential Revision: D17931739

Pulled By: yf225

fbshipit-source-id: 21bdfc88e66e3dc39f3caf608a6a3de48c510fa9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants