-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Closed
Closed
Copy link
Labels
good first issuemodule: cppRelated to C++ APIRelated to C++ APItriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
Description
Context
We would like to add torch::nn::functional::normalize to the C++ API, so that C++ users can easily find the equivalent of Python API torch.nn.functional.normalize.
Steps
- Add
torch::nn::NormalizeOptionstotorch/csrc/api/include/torch/nn/options/normalization.h(add this file if it doesn’t exist), which should include the following parameters (based on https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.normalize)TORCH_ARG(double, p) = 2.0TORCH_ARG(int64_t, dim) = 1TORCH_ARG(double, eps) = 1e-12- NOTE: please make sure to add the same comments for the parameters as in the Python version. For example, for parameter
pwe should saythe exponent value in the norm formulation. Default: 2
- Add
torch::nn::functional::normalize(...)intorch/csrc/api/include/torch/nn/functional/normalization.h(add this file if it doesn’t exist). The function should have the following signature:
namespace torch {
namespace nn {
namespace functional {
inline Tensor normalize(
const Tensor& input,
const NormalizeOptions& options = {},
c10::optional<Tensor> out = c10::nullopt) {
...
}
} // namespace functional
} // namespace nn
} // namespace torch
- Add test for
torch::nn::functional::normalize(...)in test/cpp/api/functional.cpp. It can just contain tests for both “out is null” and “out is non-null” cases, and makes sure that for “out is null” case the function is differentiable. (We should get the expected values from the corresponding Python version.)
Helpful Resources
There are quite a few PRs for adding new functionals / new modules for the C++ API (the list of PRs is in #25883), which can serve as great references. Also please ping @yf225 on this issue if you encounter any problems.
How do I claim this feature request?
Please comment in this issue if you are interested in working on it.
cc @yf225
Metadata
Metadata
Assignees
Labels
good first issuemodule: cppRelated to C++ APIRelated to C++ APItriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module