-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arvind Sridhar <[email protected]>
- Loading branch information
1 parent
2a6f999
commit 01c6952
Showing
3 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <string> | ||
#include <unordered_set> | ||
#include "core/compiler.h" | ||
#include "gtest/gtest.h" | ||
#include "tests/util/util.h" | ||
#include "torch/script.h" | ||
|
||
TEST(Partitioning, CheckLoopFallbackEvalCompilesCorrectly) { | ||
torch::jit::script::Module mod; | ||
try { | ||
mod = torch::jit::load("tests/modules/loop_fallback_eval_scripted.jit.pt"); | ||
} catch (const c10::Error& e) { | ||
std::cerr << "error loading the model\n"; | ||
return; | ||
} | ||
|
||
const std::vector<std::vector<int64_t>> input_shapes = {{1, 10}}; | ||
std::vector<torch::jit::IValue> jit_inputs_ivalues; | ||
std::vector<torch::jit::IValue> trt_inputs_ivalues; | ||
for (auto in_shape : input_shapes) { | ||
auto in = at::randint(5, in_shape, {at::kCUDA}); | ||
jit_inputs_ivalues.push_back(in.clone()); | ||
trt_inputs_ivalues.push_back(in.clone()); | ||
} | ||
|
||
std::vector<trtorch::core::ir::Input> input_ranges{trtorch::core::ir::Input({1, 10})}; | ||
trtorch::core::CompileSpec cfg(input_ranges); | ||
cfg.partition_info.enabled = true; | ||
|
||
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor(); | ||
auto trt_mod = trtorch::core::CompileGraph(mod, cfg); | ||
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor(); | ||
ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results, trt_results, 2e-6)); | ||
} | ||
|
||
TEST(Partitioning, CheckLoopFallbackNoEvalCompilesCorrectly) { | ||
torch::jit::script::Module mod; | ||
try { | ||
mod = torch::jit::load("tests/modules/loop_fallback_no_eval_scripted.jit.pt"); | ||
} catch (const c10::Error& e) { | ||
std::cerr << "error loading the model\n"; | ||
return; | ||
} | ||
|
||
const std::vector<std::vector<int64_t>> input_shapes = {{1, 10}}; | ||
std::vector<torch::jit::IValue> jit_inputs_ivalues; | ||
std::vector<torch::jit::IValue> trt_inputs_ivalues; | ||
for (auto in_shape : input_shapes) { | ||
auto in = at::randint(5, in_shape, {at::kCUDA}); | ||
jit_inputs_ivalues.push_back(in.clone()); | ||
trt_inputs_ivalues.push_back(in.clone()); | ||
} | ||
|
||
std::vector<trtorch::core::ir::Input> input_ranges{trtorch::core::ir::Input({1, 10})}; | ||
trtorch::core::CompileSpec cfg(input_ranges); | ||
cfg.partition_info.enabled = true; | ||
|
||
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor(); | ||
auto trt_mod = trtorch::core::CompileGraph(mod, cfg); | ||
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor(); | ||
ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results, trt_results, 2e-6)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters