Unsupported aten::batchnorm

Trying to transform model to NNAPI and getting following

Exception: Unsupported node kind ('aten::batch_norm') in node %input : Tensor = aten::batch_norm(%input.5, %self.2.running_var, %self.2.running_mean, %self.2.running_mean, %self.2.running_var, %11, %24, %23, %10), scope: __module.2 # /home/marat/anaconda3/envs/cexp/lib/python3.7/site-packages/torch/nn/functional.py:2422:0

On following

from torch import nn
import torch
from torch.backends._nnapi.prepare import convert_model_to_nnapi

model = nn.Sequential(nn.Conv2d(3, 3, kernel_size=1), nn.ReLU(), nn.BatchNorm2d(3), nn.ReLU())
# BUT this is OK
#model = nn.Sequential(nn.Conv2d(3, 3, kernel_size=1), nn.BatchNorm2d(3), nn.ReLU())
model.cpu()
model.eval()

input_float = torch.zeros(1, 3, 640, 640)
input_tensor = input_float

input_tensor = input_tensor.contiguous(memory_format=torch.channels_last)
input_tensor.nnapi_nhwc = True

with torch.no_grad():
    traced = torch.jit.trace(model, input_tensor)
nnapi_model = convert_model_to_nnapi(traced, input_tensor)

Looks like some layers are not supported by NNAPI yet. You can check the list of supported ops here:

I also recently found that BatchNorm is not on that list.

@kmitsunami you may try to remove one nn.RelU() before batchnorm and it compiles OK

# BUT this is OK
#model = nn.Sequential(nn.Conv2d(3, 3, kernel_size=1), nn.BatchNorm2d(3), nn.ReLU())

I’ve tried NNAPI conversion of the combination of conv2d, batchnorm2d and relu before, but it failed if I remember correctly. Anyway, thanks for sharing.