Skip to content

Commit a558e2a

Browse files
authored
Merge pull request #1397 from pytorch/minor_fix
chore: minor fixes
2 parents 3f1a655 + b73796b commit a558e2a

19 files changed

+75
-81
lines changed

BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pkg_tar(
2222
"//core/lowering:include",
2323
"//core/lowering/passes:include",
2424
"//core/partitioning:include",
25-
"//core/partitioning/segmentedblock:include",
26-
"//core/partitioning/partitioninginfo:include",
2725
"//core/partitioning/partitioningctx:include",
26+
"//core/partitioning/partitioninginfo:include",
27+
"//core/partitioning/segmentedblock:include",
2828
"//core/plugins:impl_include",
2929
"//core/plugins:include",
3030
"//core/runtime:include",

tests/core/partitioning/test_conditionals.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ TEST(Partitioning, FallbackInplaceOPInConditionalsCorrectly) {
7171
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor();
7272
auto trt_mod = torch_tensorrt::core::CompileGraph(mod, cfg);
7373
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor();
74-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results, trt_results, 2e-6));
74+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results));
7575
}

tests/core/partitioning/test_fallback_graph_output.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TEST(Partitioning, ComputeResNet50FallbackGraphCorrectly) {
3434
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor();
3535
auto trt_mod = torch_tensorrt::core::CompileGraph(mod, cfg);
3636
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor();
37-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results, 0.99));
37+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results));
3838
}
3939

4040
TEST(Partitioning, ComputeMobileNetFallbackGraphCorrectly) {
@@ -64,6 +64,6 @@ TEST(Partitioning, ComputeMobileNetFallbackGraphCorrectly) {
6464
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor();
6565
auto trt_mod = torch_tensorrt::core::CompileGraph(mod, cfg);
6666
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor();
67-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results, 0.99));
67+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results));
6868
}
6969
#endif

tests/core/partitioning/test_loop_fallback.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TEST(Partitioning, CheckLoopFallbackEvalCompilesCorrectly) {
3030
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor();
3131
auto trt_mod = torch_tensorrt::core::CompileGraph(mod, cfg);
3232
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor();
33-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results, trt_results, 2e-6));
33+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results));
3434
}
3535

3636
TEST(Partitioning, CheckLoopFallbackNoEvalCompilesCorrectly) {
@@ -58,5 +58,5 @@ TEST(Partitioning, CheckLoopFallbackNoEvalCompilesCorrectly) {
5858
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor();
5959
auto trt_mod = torch_tensorrt::core::CompileGraph(mod, cfg);
6060
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor();
61-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results, trt_results, 2e-6));
61+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results));
6262
}

tests/core/partitioning/test_resolve_nontensor_inputs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ TEST(Partitioning, ResolveNonTensorInputsForIFBlockCorrectly) {
8787
auto jit_results = mod.forward({jit_in0, jit_in1});
8888
auto trt_results = new_mod.forward({trt_in0, trt_in1});
8989

90-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results.toTensor(), trt_results.toTensor(), 2e-6));
90+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results.toTensor(), trt_results.toTensor()));
9191
}
9292

9393
TEST(Partitioning, ResolveNonTensorInputsCorrectly) {

tests/cpp/cpp_api_test.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "torch/script.h"
77
#include "torch_tensorrt/torch_tensorrt.h"
88

9-
using PathAndInput = std::tuple<std::string, std::vector<std::vector<int64_t>>, std::vector<c10::ScalarType>, float>;
9+
using PathAndInput = std::tuple<std::string, std::vector<std::vector<int64_t>>, std::vector<c10::ScalarType>>;
1010

1111
class CppAPITests : public testing::TestWithParam<PathAndInput> {
1212
public:
@@ -22,7 +22,6 @@ class CppAPITests : public testing::TestWithParam<PathAndInput> {
2222
}
2323
input_shapes = std::get<1>(params);
2424
input_types = std::get<2>(params);
25-
threshold = std::get<3>(params);
2625
}
2726

2827
void TearDown() {
@@ -34,5 +33,4 @@ class CppAPITests : public testing::TestWithParam<PathAndInput> {
3433
torch::jit::script::Module mod;
3534
std::vector<std::vector<int64_t>> input_shapes;
3635
std::vector<c10::ScalarType> input_types;
37-
float threshold;
3836
};

tests/cpp/test_collections.cpp

+15-18
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ TEST(CppAPITests, TestCollectionStandardTensorInput) {
4242
auto trt_mod = torch_tensorrt::torchscript::compile(mod, compile_settings);
4343
auto trt_out = trt_mod.forward(inputs_);
4444

45-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(out.toTensor(), trt_out.toTensor(), 0.99));
45+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(out.toTensor(), trt_out.toTensor()));
4646
}
4747

4848
TEST(CppAPITests, TestCollectionTupleInput) {
@@ -85,7 +85,7 @@ TEST(CppAPITests, TestCollectionTupleInput) {
8585
auto trt_mod = torch_tensorrt::torchscript::compile(mod, compile_settings);
8686
auto trt_out = trt_mod.forward(complex_inputs);
8787

88-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(out.toTensor(), trt_out.toTensor(), 0.99));
88+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(out.toTensor(), trt_out.toTensor()));
8989
}
9090

9191
TEST(CppAPITests, TestCollectionListInput) {
@@ -144,7 +144,7 @@ TEST(CppAPITests, TestCollectionListInput) {
144144
LOG_DEBUG("Finish compile");
145145
auto trt_out = trt_mod.forward(complex_inputs);
146146

147-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(out.toTensor(), trt_out.toTensor(), 0.99));
147+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(out.toTensor(), trt_out.toTensor()));
148148
}
149149

150150
TEST(CppAPITests, TestCollectionTupleInputOutput) {
@@ -178,23 +178,20 @@ TEST(CppAPITests, TestCollectionTupleInputOutput) {
178178
torch::jit::IValue complex_input_shape(input_shape_tuple);
179179
std::tuple<torch::jit::IValue> input_tuple2(complex_input_shape);
180180
torch::jit::IValue complex_input_shape2(input_tuple2);
181-
// torch::jit::IValue complex_input_shape(list);
182181

183182
auto compile_settings = torch_tensorrt::ts::CompileSpec(complex_input_shape2);
184183
compile_settings.min_block_size = 1;
185184

186-
// compile_settings.torch_executed_ops.push_back("prim::TupleConstruct");
187-
188185
// // FP16 execution
189186
compile_settings.enabled_precisions = {torch::kHalf};
190187
// // Compile module
191188
auto trt_mod = torch_tensorrt::torchscript::compile(mod, compile_settings);
192189
auto trt_out = trt_mod.forward(complex_inputs);
193190

194-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
195-
out.toTuple()->elements()[0].toTensor(), trt_out.toTuple()->elements()[0].toTensor(), 1e-5));
196-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
197-
out.toTuple()->elements()[1].toTensor(), trt_out.toTuple()->elements()[1].toTensor(), 1e-5));
191+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
192+
out.toTuple()->elements()[0].toTensor(), trt_out.toTuple()->elements()[0].toTensor()));
193+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
194+
out.toTuple()->elements()[1].toTensor(), trt_out.toTuple()->elements()[1].toTensor()));
198195
}
199196

200197
TEST(CppAPITests, TestCollectionListInputOutput) {
@@ -252,10 +249,10 @@ TEST(CppAPITests, TestCollectionListInputOutput) {
252249
auto trt_mod = torch_tensorrt::torchscript::compile(mod, compile_settings);
253250
auto trt_out = trt_mod.forward(complex_inputs);
254251

255-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
256-
out.toList().vec()[0].toTensor(), trt_out.toList().vec()[0].toTensor(), 1e-5));
257-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
258-
out.toList().vec()[1].toTensor(), trt_out.toList().vec()[1].toTensor(), 1e-5));
252+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
253+
out.toList().vec()[0].toTensor(), trt_out.toList().vec()[0].toTensor()));
254+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
255+
out.toList().vec()[1].toTensor(), trt_out.toList().vec()[1].toTensor()));
259256
}
260257

261258
TEST(CppAPITests, TestCollectionComplexModel) {
@@ -313,8 +310,8 @@ TEST(CppAPITests, TestCollectionComplexModel) {
313310
auto trt_mod = torch_tensorrt::torchscript::compile(mod, compile_settings);
314311
auto trt_out = trt_mod.forward(complex_inputs);
315312

316-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
317-
out.toTuple()->elements()[0].toTensor(), trt_out.toTuple()->elements()[0].toTensor(), 1e-5));
318-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
319-
out.toTuple()->elements()[1].toTensor(), trt_out.toTuple()->elements()[1].toTensor(), 1e-5));
313+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
314+
out.toTuple()->elements()[0].toTensor(), trt_out.toTuple()->elements()[0].toTensor()));
315+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
316+
out.toTuple()->elements()[1].toTensor(), trt_out.toTuple()->elements()[1].toTensor()));
320317
}

tests/cpp/test_compiled_modules.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ TEST_P(CppAPITests, CompiledModuleIsClose) {
4141
}
4242

4343
for (size_t i = 0; i < trt_results.size(); i++) {
44-
ASSERT_TRUE(
45-
torch_tensorrt::tests::util::cosineSimEqual(jit_results[i], trt_results[i].reshape_as(jit_results[i]), 0.99));
44+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results[i], trt_results[i].reshape_as(jit_results[i])));
4645
}
4746
}
4847

@@ -52,10 +51,10 @@ INSTANTIATE_TEST_SUITE_P(
5251
CompiledModuleForwardIsCloseSuite,
5352
CppAPITests,
5453
testing::Values(
55-
PathAndInput({"tests/modules/resnet18_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 2e-5}),
56-
PathAndInput({"tests/modules/mobilenet_v2_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 2e-5}),
57-
PathAndInput({"tests/modules/efficientnet_b0_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 8e-3}),
58-
PathAndInput({"tests/modules/bert_base_uncased_traced.jit.pt", {{1, 14}, {1, 14}}, {at::kInt, at::kInt}, 8e-2}),
59-
PathAndInput({"tests/modules/vit_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 8e-2})));
54+
PathAndInput({"tests/modules/resnet18_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}}),
55+
PathAndInput({"tests/modules/mobilenet_v2_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}}),
56+
PathAndInput({"tests/modules/efficientnet_b0_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}}),
57+
PathAndInput({"tests/modules/bert_base_uncased_traced.jit.pt", {{1, 14}, {1, 14}}, {at::kInt, at::kInt}}),
58+
PathAndInput({"tests/modules/vit_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}})));
6059

6160
#endif

tests/cpp/test_default_input_types.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,4 @@ TEST_P(CppAPITests, InputsRespectUserSettingFP32WeightsFP16In) {
116116
INSTANTIATE_TEST_SUITE_P(
117117
CompiledModuleForwardIsCloseSuite,
118118
CppAPITests,
119-
testing::Values(
120-
PathAndInput({"tests/modules/resnet18_traced.jit.pt", {{1, 3, 224, 224}}, {at::kFloat} /*unused*/, 2e-5})));
119+
testing::Values(PathAndInput({"tests/modules/resnet18_traced.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}})));

tests/cpp/test_example_tensors.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ TEST_P(CppAPITests, InputsFromTensors) {
2121
INSTANTIATE_TEST_SUITE_P(
2222
CompiledModuleForwardIsCloseSuite,
2323
CppAPITests,
24-
testing::Values(PathAndInput({"tests/modules/resnet18_traced.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 2e-5})));
24+
testing::Values(PathAndInput({"tests/modules/resnet18_traced.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}})));

tests/cpp/test_module_fallback.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TEST(CppAPITest, ResNetModuleFallbacksCorrectly) {
3030
auto jit_results = mod.forward(jit_inputs_ivalues).toTensor();
3131
auto trt_mod = torch_tensorrt::ts::compile(mod, cfg);
3232
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor();
33-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results, 0.99));
33+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results));
3434
}
3535

3636
TEST(CppAPITest, MobileNetModuleFallbacksCorrectlyWithOneEngine) {
@@ -69,6 +69,6 @@ TEST(CppAPITest, MobileNetModuleFallbacksCorrectlyWithOneEngine) {
6969
ASSERT_TRUE(trt_count == 1);
7070

7171
auto trt_results = trt_mod.forward(trt_inputs_ivalues).toTensor();
72-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results, 0.99));
72+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results, trt_results));
7373
}
7474
#endif

tests/cpp/test_modules_as_engines.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ TEST_P(CppAPITests, ModuleAsEngineIsClose) {
1414
jit_results.push_back(jit_results_ivalues.toTensor());
1515
auto trt_results = torch_tensorrt::tests::util::RunModuleForwardAsEngine(mod, inputs);
1616

17-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
18-
jit_results[0], trt_results[0].reshape_as(jit_results[0]), threshold));
17+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(jit_results[0], trt_results[0].reshape_as(jit_results[0])));
1918
}
2019

2120
#ifndef DISABLE_TEST_IN_CI
@@ -24,8 +23,8 @@ INSTANTIATE_TEST_SUITE_P(
2423
ModuleAsEngineForwardIsCloseSuite,
2524
CppAPITests,
2625
testing::Values(
27-
PathAndInput({"tests/modules/resnet18_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 0.99}),
28-
PathAndInput({"tests/modules/mobilenet_v2_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 0.99}),
29-
PathAndInput({"tests/modules/efficientnet_b0_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 0.99}),
30-
PathAndInput({"tests/modules/vit_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 0.99})));
26+
PathAndInput({"tests/modules/resnet18_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}}),
27+
PathAndInput({"tests/modules/mobilenet_v2_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}}),
28+
PathAndInput({"tests/modules/efficientnet_b0_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}}),
29+
PathAndInput({"tests/modules/vit_scripted.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}})));
3130
#endif

tests/cpp/test_multi_gpu_serde.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ TEST_P(CppAPITests, CompiledModuleIsClose) {
2424

2525
for (size_t i = 0; i < trt_results.size(); i++) {
2626
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
27-
jit_results[i], trt_results[i].reshape_as(jit_results[i]).to(torch::Device("cuda:0")), threshold));
27+
jit_results[i], trt_results[i].reshape_as(jit_results[i]).to(torch::Device("cuda:0"))));
2828
}
2929
}
3030

3131
INSTANTIATE_TEST_SUITE_P(
3232
CompiledModuleForwardIsCloseSuite,
3333
CppAPITests,
34-
testing::Values(PathAndInput({"tests/modules/resnet18_traced.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 0.99})));
34+
testing::Values(PathAndInput({"tests/modules/resnet18_traced.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}})));

tests/cpp/test_multiple_registered_engines.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ TEST(CppAPITest, CanRunMultipleEngines) {
5656
trt2_results.push_back(trt2_results_ivalues.toTensor());
5757

5858
for (size_t i = 0; i < trt1_results.size(); i++) {
59-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
60-
jit1_results[i], trt1_results[i].reshape_as(jit1_results[i]), 0.99));
59+
ASSERT_TRUE(
60+
torch_tensorrt::tests::util::cosineSimEqual(jit1_results[i], trt1_results[i].reshape_as(jit1_results[i])));
6161
}
6262

6363
for (size_t i = 0; i < trt2_results.size(); i++) {
64-
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
65-
jit2_results[i], trt2_results[i].reshape_as(jit2_results[i]), 0.99));
64+
ASSERT_TRUE(
65+
torch_tensorrt::tests::util::cosineSimEqual(jit2_results[i], trt2_results[i].reshape_as(jit2_results[i])));
6666
}
6767
}
6868
#endif

tests/cpp/test_runtime_thread_safety.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ TEST(CppAPITests, RuntimeThreadSafety) {
7878

7979
bool flag = true;
8080
for (int i = 0; i < num_threads; i++) {
81-
bool f = torch_tensorrt::tests::util::almostEqual(out_vec[i].toTensor(), trt_out_vec[i].toTensor(), 1e-2);
81+
bool f = torch_tensorrt::tests::util::cosineSimEqual(out_vec[i].toTensor(), trt_out_vec[i].toTensor());
8282
flag = flag && f;
8383
}
8484
ASSERT_TRUE(flag);

tests/cpp/test_serialization.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ TEST_P(CppAPITests, SerializedModuleIsStillCorrect) {
4242
post_serialized_results.push_back(post_serialized_results_ivalues.toTensor());
4343

4444
for (size_t i = 0; i < pre_serialized_results.size(); i++) {
45-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
46-
post_serialized_results[i], pre_serialized_results[i].reshape_as(post_serialized_results[i]), threshold));
45+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
46+
post_serialized_results[i], pre_serialized_results[i].reshape_as(post_serialized_results[i])));
4747
}
4848
}
4949

@@ -72,14 +72,14 @@ TEST_P(CppAPITests, SerializedDynamicModuleIsStillCorrect) {
7272
post_serialized_results.push_back(post_serialized_results_ivalues.toTensor());
7373

7474
for (size_t i = 0; i < pre_serialized_results.size(); i++) {
75-
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
76-
post_serialized_results[i], pre_serialized_results[i].reshape_as(post_serialized_results[i]), threshold));
75+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
76+
post_serialized_results[i], pre_serialized_results[i].reshape_as(post_serialized_results[i])));
7777
}
7878
}
7979

8080
INSTANTIATE_TEST_SUITE_P(
8181
CompiledModuleForwardIsCloseSuite,
8282
CppAPITests,
8383
testing::Values(
84-
PathAndInput({"tests/modules/resnet18_traced.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}, 2e-5}),
85-
PathAndInput({"tests/modules/pooling_traced.jit.pt", {{1, 3, 10, 10}}, {at::kFloat}, 2e-5})));
84+
PathAndInput({"tests/modules/resnet18_traced.jit.pt", {{1, 3, 224, 224}}, {at::kFloat}}),
85+
PathAndInput({"tests/modules/pooling_traced.jit.pt", {{1, 3, 10, 10}}, {at::kFloat}})));

tests/modules/hub.py

-6
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@
4646
"model": torch.hub.load("pytorch/vision:v0.9.0", "resnet50", pretrained=True),
4747
"path": "both",
4848
},
49-
"ssd": {
50-
"model": torch.hub.load(
51-
"NVIDIA/DeepLearningExamples:torchhub", "nvidia_ssd", model_math="fp32"
52-
),
53-
"path": "trace",
54-
},
5549
"efficientnet_b0": {
5650
"model": timm.create_model("efficientnet_b0", pretrained=True),
5751
"path": "script",

tests/util/util.cpp

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "util.h"
12
#include "core/util/prelude.h"
23
#include "torch/script.h"
34
#include "torch/torch.h"
@@ -6,19 +7,7 @@ namespace torch_tensorrt {
67
namespace tests {
78
namespace util {
89

9-
bool cosineSimEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor, float threshold = 0.99f) {
10-
torch::Tensor cosine_sim = torch::nn::functional::cosine_similarity(
11-
computed_tensor.flatten(), gt_tensor.flatten(), torch::nn::functional::CosineSimilarityFuncOptions().dim(0));
12-
std::ostringstream ss;
13-
ss << computed_tensor << std::endl << gt_tensor << std::endl;
14-
LOG_DEBUG(ss.str());
15-
LOG_DEBUG(std::string("Cosine Similarity score: ") + std::to_string(cosine_sim.item<float>()));
16-
LOG_DEBUG(std::string("Acceptable Threshold: ") + std::to_string(threshold));
17-
18-
return cosine_sim.item<float>() >= threshold;
19-
}
20-
21-
bool almostEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor, float atol = 1e-8, float rtol = 1e-5) {
10+
bool almostEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor, float atol, float rtol) {
2211
std::ostringstream ss;
2312
ss << computed_tensor << std::endl << gt_tensor << std::endl;
2413
ss << " atol: " << atol << " rtol: " << rtol << std::endl;
@@ -37,6 +26,21 @@ bool almostEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor,
3726
return result <= threshold;
3827
}
3928

29+
bool cosineSimEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor, float threshold) {
30+
torch::Tensor cosine_sim = torch::nn::functional::cosine_similarity(
31+
computed_tensor.flatten(), gt_tensor.flatten(), torch::nn::functional::CosineSimilarityFuncOptions().dim(0));
32+
std::ostringstream ss;
33+
ss << computed_tensor << std::endl << gt_tensor << std::endl;
34+
LOG_DEBUG(ss.str());
35+
if (computed_tensor.sum().item<float>() == 0.f || gt_tensor.sum().item<float>() == 0.f) {
36+
return almostEqual(computed_tensor, gt_tensor);
37+
} else {
38+
LOG_DEBUG(std::string("Cosine Similarity score: ") + std::to_string(cosine_sim.item<float>()));
39+
LOG_DEBUG(std::string("Acceptable Threshold: ") + std::to_string(threshold));
40+
return cosine_sim.item<float>() >= threshold;
41+
}
42+
}
43+
4044
bool exactlyEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor) {
4145
LOG_DEBUG(computed_tensor << std::endl << gt_tensor << std::endl);
4246
std::cout << "Max Difference: " << (computed_tensor - gt_tensor).abs().max().item<float>() << std::endl;

0 commit comments

Comments
 (0)