@@ -10,7 +10,7 @@ namespace trtorch {
10
10
namespace core {
11
11
namespace conversion {
12
12
13
- // Defined in core/conversion/conversion_blacklist.cpp
13
+ // Defined in core/conversion/conversion_blacklist.cpp
14
14
bool isNodeConversionBlacklisted (const torch::jit::Node* n);
15
15
16
16
bool OpSupported (const torch::jit::Node* n) {
@@ -24,8 +24,8 @@ c10::optional<torch::jit::IValue> EvaluateNode(ConversionCtx* ctx, const torch::
24
24
// Also probably a better way to deal with the two error cases;
25
25
TRTORCH_CHECK (level < limit, " Failed to evaluate node: " << *n \
26
26
<< " Reason: Exceeded evaluation stack limit (limit=" \
27
- << limit << " )" );
28
-
27
+ << limit << " )" );
28
+
29
29
LOG_DEBUG (ctx->logger , " Evaluating " << util::node_info (n));
30
30
evaluators::kwargs eval_args;
31
31
for (auto eval_in : n->inputs ()) {
@@ -55,7 +55,7 @@ c10::optional<torch::jit::IValue> EvaluateNode(ConversionCtx* ctx, const torch::
55
55
return eval;
56
56
}
57
57
58
- bool AddLayer (ConversionCtx* ctx, const torch::jit::Node* n) {
58
+ void AddLayer (ConversionCtx* ctx, const torch::jit::Node* n) {
59
59
LOG_INFO (ctx->logger ,
60
60
" Adding Layer " << util::node_info (n) << " (ctx.AddLayer)" );
61
61
converters::args node_args;
@@ -87,36 +87,34 @@ bool AddLayer(ConversionCtx* ctx, const torch::jit::Node* n) {
87
87
TRTORCH_THROW_ERROR (" Unable to retrieve all node inputs for node: " \
88
88
<< util::node_info (n) << " (ctx.AddLayer)\n Specifically failed to retrieve value for input: " \
89
89
<< *input_node);
90
- return false ;
91
90
}
92
-
93
91
}
94
92
95
93
if (n->inputs ().size () != node_args.size ()) {
96
94
TRTORCH_THROW_ERROR (" Unable to retrieve all node inputs for node: " << *n);
97
- return false ;
98
95
}
99
96
100
-
97
+
101
98
auto schema = n->maybeSchema ();
102
99
TRTORCH_CHECK (schema, " Unable to get schema for Node " << util::node_info (n) \
103
100
<< " (conversion.AddLayer)" );
104
-
101
+
105
102
auto converter = converters::get_node_converter_for (schema);
106
103
TRTORCH_CHECK (converter, " Unable to convert node: " << util::node_info (n) \
107
104
<< " (conversion.AddLayer)\n Schema: " << *schema
108
105
<< " \n Converter for " << schema->name ()
109
106
<< " requested, but no such converter was found.\n If you need a converter for this operator, you can try implementing one yourself\n "
110
- << " or request a converter: https://www.github.com/NVIDIA/TRTorch/issues" );
111
- converter (ctx, n, node_args);
107
+ << " or request a converter: https://www.github.com/NVIDIA/TRTorch/issues" );
112
108
113
- return true ;
109
+ TRTORCH_CHECK (converter (ctx, n, node_args),
110
+ " Converter for " << *schema << " failed to convert node: "
111
+ << util::node_info (n) << " please report this error to https://www.github.com/NVIDIA/TRTorch/issues" );
114
112
}
115
113
116
- bool AddInputs (ConversionCtx* ctx,
114
+ void AddInputs (ConversionCtx* ctx,
117
115
at::ArrayRef<const torch::jit::Value*> inputs,
118
116
std::vector<InputRange>& input_dims) {
119
-
117
+
120
118
auto type_lut = torch::jit::script::string_to_type_lut ();
121
119
std::vector<const torch::jit::Value*> input_tensors;
122
120
for (auto in : inputs) {
@@ -130,15 +128,15 @@ bool AddInputs(ConversionCtx* ctx,
130
128
input_tensors.push_back (in);
131
129
}
132
130
}
133
-
131
+
134
132
TRTORCH_CHECK (input_tensors.size () == input_dims.size (),
135
133
" Expected dimension specifications for all input tensors" \
136
134
<< " , but found " << input_tensors.size () \
137
135
<< " input tensors and " \
138
136
<< input_dims.size () << " dimension specs (conversion.AddInputs)" );
139
137
140
138
auto profile = ctx->builder ->createOptimizationProfile ();
141
-
139
+
142
140
for (size_t i = 0 ; i < input_tensors.size (); i++) {
143
141
auto in = input_tensors[i];
144
142
auto dims = input_dims[i];
@@ -158,20 +156,23 @@ bool AddInputs(ConversionCtx* ctx,
158
156
}
159
157
160
158
TRTORCH_CHECK (profile->isValid (), " Optimization profile is invalid, please check the input range provided (conversion.AddInputs)" );
161
-
159
+
162
160
ctx->cfg ->addOptimizationProfile (profile);
163
- return true ;
164
161
}
165
162
166
- bool MarkOutputs (ConversionCtx* ctx, at::ArrayRef<const torch::jit::Value*> outputs) {
163
+ void MarkOutputs (ConversionCtx* ctx, at::ArrayRef<const torch::jit::Value*> outputs) {
167
164
for (auto out : outputs) {
168
- ctx->net ->markOutput (*(ctx->value_tensor_map [out]));
165
+ auto it = ctx->value_tensor_map .find (out);
166
+ // Leaves the potential for unused outputs to be populated with nullptr "safely"
167
+ TRTORCH_CHECK (it != ctx->value_tensor_map .end () && it->second ,
168
+ " No corresponding output TRT Tensor found for TorchScript output: " << out->debugName ());
169
+ auto out_tensor = it->second ;
170
+ ctx->net ->markOutput (*out_tensor);
169
171
LOG_INFO (ctx->logger ,
170
172
" Marking Output " << out->debugName () << " (ctx.MarkOutput)" );
171
173
}
172
- return true ;
173
174
}
174
-
175
+
175
176
void AddParamsToCtxValueMap (ConversionCtx* ctx, GraphParams& params) {
176
177
for (auto p : params) {
177
178
ctx->evaluated_value_map [p.first ] = torch::jit::IValue (p.second .clone ());
@@ -191,13 +192,8 @@ void ConvertBlockToNetDef(ConversionCtx* ctx, const torch::jit::Block* b, ExtraI
191
192
bool to_eval = evaluators::shouldEvalAtConversionTime (n);
192
193
bool blacklisted = isNodeConversionBlacklisted (n);
193
194
if (!to_eval && !blacklisted) {
194
- if (!AddLayer (ctx, n)) {
195
- // TODO: Exception things
196
- LOG_ERROR (ctx->logger ,
197
- " Failed to add layer: " << *n \
198
- << " (ctx.AddLayer)" );
199
- return ;
200
- }
195
+ // Should error out if something fails
196
+ AddLayer (ctx, n);
201
197
} else {
202
198
std::string reason = " " ;
203
199
if (to_eval) {
@@ -207,7 +203,13 @@ void ConvertBlockToNetDef(ConversionCtx* ctx, const torch::jit::Block* b, ExtraI
207
203
reason += " (explicitly blacklisted)" ;
208
204
}
209
205
LOG_DEBUG (ctx->logger ,
210
- " Skipping Node: " << (n->kind ().toQualString ()) << reason);
206
+ " Skipping Node: " << util::node_info (n) << reason);
207
+ }
208
+ }
209
+
210
+ for (const auto n : nodes) {
211
+ if (converters::node_is_convertable (n)) {
212
+ ctx->CheckLayerAddition (n);
211
213
}
212
214
}
213
215
@@ -218,7 +220,7 @@ void ConvertBlockToNetDef(ConversionCtx* ctx, const torch::jit::Block* b, ExtraI
218
220
// Converts a already lowered block (blocks with no sub blocks) to
219
221
// a serialized TensorRT engine that can be deserialized and run
220
222
221
- // Probably should consolidate these two functions
223
+ // Probably should consolidate these two functions
222
224
std::string ConvertBlockToEngine (const torch::jit::Block* b, ExtraInfo build_info, GraphParams& static_params) {
223
225
ConversionCtx ctx (build_info.engine_settings );
224
226
ConvertBlockToNetDef (&ctx, b, build_info, static_params);
@@ -247,7 +249,7 @@ bool VerifyConverterSupportForBlock(const torch::jit::Block* b) {
247
249
for (auto s : unsupported_ops) {
248
250
unsupported_msg << " - " << s << std::endl;
249
251
}
250
- unsupported_msg << " You can either implement converters for these ops in your application or file a bug " << std::endl;
252
+ unsupported_msg << " You can either implement converters for these ops in your application or request implementation " << std::endl;
251
253
unsupported_msg << " https://www.github.com/nvidia/TRTorch/issues" << std::endl;
252
254
LOG_ERROR (unsupported_msg.str ());
253
255
}
0 commit comments