Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译模型的时候出现error: failed to legalize operation 'MGB.ConvBias' #46

Open
BobbyXue666 opened this issue Feb 22, 2023 · 6 comments

Comments

@BobbyXue666
Copy link

dump代码如下
@jit.trace(symbolic=True, capture_as_const=True)
def fun(data, *, net):
pred = net(data)
return pred

fun(data, net=model)
fun.dump("test.mge", arg_names=["data"],optimize_for_inference=False, enable_fuse_conv_bias_nonlinearity=False, enable_fuse_conv_bias_with_z=False)

@chenqy4933
Copy link
Collaborator

麻烦提供一下MegEngine的版本,以及最小复现,就目前的信息很难定位问题。

@BobbyXue666
Copy link
Author

MegEngine 1.12.1+cu114
megfile 2.0.0.post2
最小复现如下:

class TestModel(M.Module):

    def __init__(self,):

        super().__init__()
        self.conv1 = M.Conv2d(2,16,kernel_size=3, stride=2, padding=1, bias=False)
        self.bn1 = M.BatchNorm2d(16)
        self.relu1 = M.ReLU()
        self.conv2 = M.Conv2d(16,4,kernel_size=3, stride=2, padding=1, bias=False)
        self.bn2 = M.BatchNorm2d(4)
        self.relu2 = M.ReLU()
        self.conv3 = M.Conv2d(4,1,kernel_size = 5, stride=1, padding=0, bias=False )
        self.ac3 = M.Sigmoid()

    def forward(self, x):

        out = self.relu1(self.bn1(self.conv1(x)))
        out = self.relu2(self.bn2(self.conv2(out)))
        out = self.ac3(self.conv3(out))

        return out



model = TestModel()
model.eval()
data = tensor(np.random.random([1, 2, 20, 20]).astype(np.float32))
print(model(data))

@jit.trace(symbolic=True, capture_as_const=True)
def fun(data, *, net):
    pred = net(data)
    return pred


fun(data, net=model)
fun.dump("test.mge", arg_names=["data"],optimize_for_inference=False, enable_fuse_conv_bias_nonlinearity=False, enable_fuse_conv_bias_with_z=False)

@chenqy4933
Copy link
Collaborator

用你上面的代码和对应的MegEngine的版本,我这边测试没有问题的。

@BobbyXue666
Copy link
Author

这是我的json文件

{
    "dump_dir":"./batch_dump/",
    "models":[
        {
            "model_name":"test",
            "model_path":"./example/test.mge",
            "input_shape_str":"data=(1,2,20,20)",
            "enable_nchw44":true
        }
    ],
    "cv":{
        "transpose":["ui8"],
        "roicopy":["ui8"],
        "rotate":["ui8"],
        "flip":["ui8"],
        "resize_linear":["ui8"],
        "warp_affine_replicate_linear":["ui8"],
        "rgb2bgr":["ui8"],
        "yuv2bgr_nv21":["ui8"],
        "rgb2yuv":["ui8"]
    }
}

这是生成模型的命令
./script/ppl_gen.sh ./bin/mgb-to-tinynn ./example/demo.json test --arm64

@BobbyXue666
Copy link
Author

将bias去掉可以编过,想知道是为什么
self.conv1 = M.Conv2d(2,16,kernel_size=3, stride=2, padding=1)

@haolongzhangm
Copy link
Collaborator

@BobbyXue666 optimize_for_inference=False 这个写成 true 试试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants