mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
torch::nn::GLU and F::glu (#29922)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/29922 * #29920 [C++ API] torch::nn::GroupNorm and F::group_norm Test Plan: Imported from OSS Differential Revision: D18558818 Pulled By: yf225 fbshipit-source-id: ff80d634309fcb55f53db8dcf86eb9cf8161b37e
This commit is contained in:
committed by
Facebook Github Bot
parent
d5bf51b684
commit
689b4bea7b
@@ -752,6 +752,19 @@ TEST_F(FunctionalTest, SELU) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, GLU) {
|
||||
int64_t dim = 1;
|
||||
auto input = torch::randn({4, 2}, torch::requires_grad());
|
||||
auto output = F::glu(input, dim);
|
||||
auto input_size = input.sizes()[dim] / 2;
|
||||
auto first_half = input.narrow(dim, 0, input_size);
|
||||
auto second_half = input.narrow(dim, input_size, input_size);
|
||||
auto expected = first_half * torch::sigmoid(second_half);
|
||||
|
||||
ASSERT_TRUE(output.allclose(expected));
|
||||
ASSERT_TRUE(F::glu(input).allclose(expected));
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, GELU) {
|
||||
GELU model;
|
||||
const auto x = torch::linspace(-3.0, 3.0, 100);
|
||||
|
||||
Reference in New Issue
Block a user