Xilinx / pyxir

Apache License 2.0
37 stars 14 forks source link

Compiling MaskRCNN from Torchvision model zoo issues #78

Open abdulazizm opened 2 years ago

abdulazizm commented 2 years ago

JIT traced maskrcnn model from model zoo and provided desired layouts but couldn't avoid Attribute error. Any workarounds for this?

mod, params = relay.frontend.from_pytorch(script_module, shape_list)

mod = relay.transform.InferType()(mod)
mod["main"] = bind_params_by_name(mod["main"], params)
mod = transform.RemoveUnusedFunctions()(mod)

# no warnings when included these in desired layouts
#desired_layouts = {'nn.conv2d': ['NHWC', 'default'], 'image.resize2d': ['NHWC'], 'vision.roi_align': ['NHWC','default'], 'nn.conv2d_transpose':['NHWC','default']}

desired_layouts = {'nn.conv2d': ['NHWC', 'default']}
seq = tvm.transform.Sequential([relay.transform.RemoveUnusedFunctions(),
                                relay.transform.ConvertLayout(desired_layouts),
                                relay.transform.FoldConstant()])
with tvm.transform.PassContext(opt_level=3):
    mod = seq(mod)

mod = relay.transform.DynamicToStatic()(mod)

# getting below mentioned here even after using DynamicToStatic() 
mod = partition_for_vitis_ai(mod, params, dpu=target)

print(mod['main'])

AttributeError: <class 'tvm.tir.expr.Any'> has no attribute value

@jornt-xilinx Any suggestion on this?

abdulazizm commented 2 years ago

Noticed that relay.transform.DynamicToStatic() helped to fix the issue as mentioned here -> https://githubmemory.com/repo/Xilinx/pyxir/issues/63

But not in my case

abdulazizm commented 2 years ago

With recent version of TVM (main branch) and Pyxir (0.3.1) getting below error. Hope both implies same ( and inf is not handled which while casting throws overflow err)

My case: DEBUG:pyxir:relay shape: [-1, 1, 0] numerator: 159882 denominator: 0 -> inf

File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/pyxir-0.3.1-py3.6-linux-x86_64.egg/pyxir/frontend/tvm/relay_tools/relay_l3_math_and_transform.py", line 348, in reshape
    newshape.append(int(np.prod(input_shape[j:]) / np.prod(relayshape[i+1:])))
OverflowError: cannot convert float infinity to integer
(vitis-ai-tensorflow) Vitis-AI /home/aziza/01_Perception/xilinx/apachetvm_flow/tvm/my_workspace/MaskRCNN > pip show tvm pyxir
Name: tvm
Version: 0.9.dev185+gc7ddb4134
Summary: TVM: An End to End Tensor IR/DSL Stack for Deep Learning Systems
Home-page: https://github.com/apache/tvm
Author: None
Author-email: None
License: UNKNOWN
Location: /home/aziza/01_Perception/xilinx/apachetvm_flow/tvm/python
Requires: attrs, cloudpickle, decorator, numpy, psutil, scipy, synr, tornado
Required-by:
---
Name: pyxir
Version: 0.3.1
Summary: # PyXIR
Home-page: None
Author: None
Author-email: None
License: None
Location: /opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/pyxir-0.3.1-py3.6-linux-x86_64.egg
Requires: numpy, packaging, pydot, h5py
Required-by:

@jornt-xilinx

abdulazizm commented 2 years ago

@jornt-xilinx Seems apache tvm compiles mask rcnn with relay VM. Is it possible to have relayVM with VITIS AI workflow?

https://discuss.tvm.apache.org/t/frontend-pytorch-convert-rcnn-model-from-torch-vision-model/7525/6 masahi confirmed that apache tvm compiles maskrcnn but he is just not sure what VITIS AI does