mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Breakup test_misc so that a test for a file is in test_filename. I think we might want to wait on moving test files into the source directory, since that would involve moving some tests over to the C10 folder, and this goes 99% of the way for test discoverability IMO anyway. I added a file test_utils for common functions invoked in the tests. Pull Request resolved: https://github.com/pytorch/pytorch/pull/18071 Differential Revision: D14485787 Pulled By: eellison fbshipit-source-id: dcb20d1978d490999d435ea20c1d0503413a5c80
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "test/cpp/jit/test_base.h"
|
|
#include "test/cpp/jit/test_utils.h"
|
|
#include "torch/csrc/jit/graph_executor.h"
|
|
|
|
namespace torch {
|
|
namespace jit {
|
|
namespace test {
|
|
|
|
void testGraphExecutor() {
|
|
constexpr int batch_size = 4;
|
|
constexpr int input_size = 256;
|
|
|
|
int hidden_size = 2 * input_size;
|
|
|
|
auto v = [](at::Tensor t) { return autograd::make_variable(t, false); };
|
|
|
|
auto input = at::randn({batch_size, input_size}, at::kCUDA);
|
|
auto hx = at::randn({batch_size, hidden_size}, at::kCUDA);
|
|
auto cx = at::randn({batch_size, hidden_size}, at::kCUDA);
|
|
auto w_ih = t_def(at::randn({4 * hidden_size, input_size}, at::kCUDA));
|
|
auto w_hh = t_def(at::randn({4 * hidden_size, hidden_size}, at::kCUDA));
|
|
|
|
auto g = build_lstm();
|
|
GraphExecutor executor(g);
|
|
auto stack = createStack({v(input), v(hx), v(cx), v(w_ih), v(w_hh)});
|
|
executor.run(stack);
|
|
ASSERT_EQ(stack.size(), 2);
|
|
at::Tensor r0, r1;
|
|
std::tie(r0, r1) = lstm(input, hx, cx, w_ih, w_hh);
|
|
ASSERT_TRUE(almostEqual(Variable(stack[0].toTensor()).data(), r0));
|
|
ASSERT_TRUE(almostEqual(Variable(stack[1].toTensor()).data(), r1));
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace jit
|
|
} // namespace torch
|