mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/29213 A trivial use of make_variable is one where requires_grad=False. This transformation is not technically semantics preserving, as make_variable will create a shallow copy of the tensor in question; however, I am guessing that we have the invariant that we don't actually make use of this shallow copy in a nontrivial way. There were some cases where the surrounding code expected a Variable proper to be returned; I retained those sites. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Test Plan: Imported from OSS Differential Revision: D18353503 Pulled By: ezyang fbshipit-source-id: 57fe34d82e009c0cc852266fb0b79d6d9c62bb03
33 lines
1006 B
C++
33 lines
1006 B
C++
#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 {
|
|
|
|
void testGraphExecutor() {
|
|
constexpr int batch_size = 4;
|
|
constexpr int input_size = 256;
|
|
|
|
int hidden_size = 2 * input_size;
|
|
|
|
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({input, hx, cx, w_ih, 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(stack[0].toTensor(), r0));
|
|
ASSERT_TRUE(almostEqual(stack[1].toTensor(), r1));
|
|
}
|
|
|
|
} // namespace jit
|
|
} // namespace torch
|