-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1148 from pytorch/fix_parsing
fix: fix the parsing related model loading bug
- Loading branch information
Showing
3 changed files
with
61 additions
and
2 deletions.
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
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,39 @@ | ||
#include <string> | ||
#include <unordered_set> | ||
#include "core/compiler.h" | ||
#include "gtest/gtest.h" | ||
#include "tests/util/util.h" | ||
#include "torch/script.h" | ||
|
||
#ifndef DISABLE_TEST_IN_CI | ||
|
||
TEST(Partitioning, ComputeResNet50FallbackGraphCorrectly) { | ||
torch::jit::script::Module mod; | ||
try { | ||
mod = torch::jit::load("tests/modules/conditional_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, 3, 224, 224}}; | ||
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<torch_tensorrt::core::ir::Input> input_ranges{torch_tensorrt::core::ir::Input({1, 3, 224, 224})}; | ||
|
||
torch_tensorrt::core::CompileSpec cfg(input_ranges); | ||
cfg.partition_info.enabled = true; | ||
|
||
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor(); | ||
auto trt_mod = torch_tensorrt::core::CompileGraph(mod, cfg); | ||
trt_mod.save("loading_model.ts"); | ||
auto loaded_model = torch::jit::load("loading_model.ts"); | ||
} | ||
|
||
#endif |