@@ -203,7 +203,8 @@ auto reduce_registrations TORCHTRT_UNUSED =
203
203
return true ;
204
204
}})
205
205
.pattern(
206
- {" aten::min(Tensor self) -> Tensor" , [](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
206
+ {" aten::min(Tensor self) -> Tensor" ,
207
+ [](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
207
208
auto in_tensor = args[0 ].ITensorOrFreeze (ctx);
208
209
auto in_dims = util::toVec (in_tensor->getDimensions ());
209
210
@@ -216,6 +217,38 @@ auto reduce_registrations TORCHTRT_UNUSED =
216
217
min_layer->setName (util::node_info (n).c_str ());
217
218
auto out_tensor = ctx->AssociateValueAndTensor (n->outputs ()[0 ], min_layer->getOutput (0 ));
218
219
220
+ LOG_DEBUG (" Output shape: " << out_tensor->getDimensions ());
221
+ return true ;
222
+ }})
223
+ .pattern(
224
+ {" aten::any.dim(Tensor self, int dim, bool keepdim=False) -> Tensor" ,
225
+ [](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
226
+ auto in_tensor = args[0 ].ITensorOrFreeze (ctx);
227
+ auto in_dims = in_tensor->getDimensions ();
228
+ auto dim = args[1 ].unwrapToInt ();
229
+ LOG_DEBUG (" Dim to reduce (original): " << dim);
230
+ dim = dim < 0 ? (in_dims.nbDims + dim) : dim;
231
+ LOG_DEBUG (" Dim to reduce (converted): " << dim);
232
+
233
+ uint32_t axis_mask = 1 << dim;
234
+ LOG_DEBUG (" Axis Mask: " << std::bitset<32 >(axis_mask));
235
+
236
+ auto keepdim = args[2 ].unwrapToBool ();
237
+ LOG_DEBUG (" Keep dims: " << keepdim);
238
+
239
+ // Reduce does not work on bool inputs
240
+ if (in_tensor->getType () == nvinfer1::DataType::kBOOL ) {
241
+ in_tensor =
242
+ castITensor (ctx, in_tensor, nvinfer1::DataType::kINT32 , (util::node_info (n) + " _in" ).c_str ());
243
+ }
244
+ auto sum_layer = ctx->net ->addReduce (*in_tensor, nvinfer1::ReduceOperation::kSUM , axis_mask, keepdim);
245
+
246
+ TORCHTRT_CHECK (sum_layer, " Unable to create sum layer from node: " << *n);
247
+
248
+ sum_layer->setName (util::node_info (n).c_str ());
249
+ auto out_tensor = castITensor (
250
+ ctx, sum_layer->getOutput (0 ), nvinfer1::DataType::kBOOL , (util::node_info (n) + " _out" ).c_str ());
251
+ out_tensor = ctx->AssociateValueAndTensor (n->outputs ()[0 ], out_tensor);
219
252
LOG_DEBUG (" Output shape: " << out_tensor->getDimensions ());
220
253
return true ;
221
254
}});
0 commit comments