mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
Make Module::register_module / register_parameter / register_buffer public (#23196)
Summary: In Python, `register_module` / `register_parameter` / `register_buffer` method in `nn.Module` is public. This PR makes those APIs public for C++ `nn::Module` as well. Closes https://github.com/pytorch/pytorch/issues/23140. Pull Request resolved: https://github.com/pytorch/pytorch/pull/23196 Differential Revision: D16440239 Pulled By: yf225 fbshipit-source-id: e0eff6e1db592961fba891ec417dc74fa765e968
This commit is contained in:
committed by
Facebook Github Bot
parent
24601daa12
commit
8a77098247
+6
-18
@@ -77,9 +77,7 @@ TEST_F(ModuleTest, ZeroGradWithUndefined) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, RegisterModuleThrowsForEmptyOrDottedName) {
|
||||
struct TestModel : public torch::nn::Module {
|
||||
using torch::nn::Module::register_module;
|
||||
};
|
||||
struct TestModel : public torch::nn::Module {};
|
||||
ASSERT_THROWS_WITH(
|
||||
TestModel{}.register_module("name.with.dot", torch::nn::Linear(3, 4)),
|
||||
"Submodule name must not contain a dot (got 'name.with.dot')");
|
||||
@@ -89,9 +87,7 @@ TEST_F(ModuleTest, RegisterModuleThrowsForEmptyOrDottedName) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, RegisterModuleThrowsForDuplicateModuleName) {
|
||||
struct TestModel : public torch::nn::Module {
|
||||
using torch::nn::Module::register_module;
|
||||
};
|
||||
struct TestModel : public torch::nn::Module {};
|
||||
TestModel model;
|
||||
model.register_module("linear", torch::nn::Linear(3, 4));
|
||||
ASSERT_THROWS_WITH(
|
||||
@@ -120,9 +116,7 @@ TEST_F(ModuleTest, ReplaceModule) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, RegisterParameterThrowsForEmptyOrDottedName) {
|
||||
struct TestModel : public torch::nn::Module {
|
||||
using torch::nn::Module::register_parameter;
|
||||
};
|
||||
struct TestModel : public torch::nn::Module {};
|
||||
ASSERT_THROWS_WITH(
|
||||
TestModel{}.register_parameter("name.with.dot", torch::ones(5)),
|
||||
"Parameter name must not contain a dot (got 'name.with.dot')");
|
||||
@@ -132,9 +126,7 @@ TEST_F(ModuleTest, RegisterParameterThrowsForEmptyOrDottedName) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, RegisterParameterThrowsForDuplicateModuleName) {
|
||||
struct TestModel : public torch::nn::Module {
|
||||
using torch::nn::Module::register_parameter;
|
||||
};
|
||||
struct TestModel : public torch::nn::Module {};
|
||||
TestModel model;
|
||||
model.register_parameter("p", torch::ones(5));
|
||||
ASSERT_THROWS_WITH(
|
||||
@@ -143,9 +135,7 @@ TEST_F(ModuleTest, RegisterParameterThrowsForDuplicateModuleName) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, RegisterBufferThrowsForEmptyOrDottedName) {
|
||||
struct TestModel : public torch::nn::Module {
|
||||
using torch::nn::Module::register_buffer;
|
||||
};
|
||||
struct TestModel : public torch::nn::Module {};
|
||||
ASSERT_THROWS_WITH(
|
||||
TestModel{}.register_buffer("name.with.dot", torch::ones(5)),
|
||||
"Buffer name must not contain a dot (got 'name.with.dot')");
|
||||
@@ -155,9 +145,7 @@ TEST_F(ModuleTest, RegisterBufferThrowsForEmptyOrDottedName) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, RegisterBufferThrowsForDuplicateModuleName) {
|
||||
struct TestModel : public torch::nn::Module {
|
||||
using torch::nn::Module::register_buffer;
|
||||
};
|
||||
struct TestModel : public torch::nn::Module {};
|
||||
TestModel model;
|
||||
model.register_buffer("p", torch::ones(5));
|
||||
ASSERT_THROWS_WITH(
|
||||
|
||||
Reference in New Issue
Block a user