glow icon indicating copy to clipboard operation
glow copied to clipboard

[GraphOptimizer] Fix wrong layout assumption in OptimizeReduceMean?

Open shajrawi opened this issue 6 years ago • 3 comments

I see the following code in the optimization:

      // In Glow, AvgPool expects NHWC.
      auto *TR1 = F->createTranspose(
          RM->getName().str() + ".transposeNCHW2NHWC", in, NCHW2NHWC);
      auto *AP = F->createAvgPool(RM->getName().str() + ".avgPool", TR1,
                                  kernels, strides, pads);
      auto *TR2 = F->createTranspose(
          RM->getName().str() + ".transposeNHWC2NCHW", AP, NHWC2NCHW);

This looks like a bug to me, the canonical representation in Glow is NHWC. Why do we expect the input to be in NCHW format and doing the two transposes?

shajrawi avatar Sep 10 '19 23:09 shajrawi

cc @vuzelac-cadence

shajrawi avatar Sep 10 '19 23:09 shajrawi

Will this code be ever executed? I see in lowerBatchedReduceMeanNode that ReduceMean can only have one axis. @jfix71, @mciprian13 , any idea how it's better to approach this again? I am thinking of lowering ReduceMean to AvgPool in Lower.cpp, if possible. Or maybe lower to multiple ReduceMean, then find the pattern in OptimizeReduceMean (possible error-prone after future optimizations)?

dspmihai avatar Aug 04 '21 13:08 dspmihai

@dspmihai, lowering is backend controlled. For example, we do use this optimization.

vuzelac-cadence avatar Aug 05 '21 03:08 vuzelac-cadence