[octoml][azsphere][kws] quantization error

@thierry

I’ve reviewed the the Octoml medium post by Thierry Moreau @thierry , which explains TVM and KWS (keyword spot) using Azure Sphere.

The code is in the below repo.

I am using the latest TVM

When I run the following code that export and quantize, I see an error in the quantization. I have gone through the python functions and cpp functions in the the backtrace and print out the types (got the name_hint is list). It seems that during the quantization tvm::IRModuleNode::LookupTypeDef failed to find the type def. However, I am not sure how to debug the next.

Any help will be appreciated.

# described in https://github.com/octoml/azsphere/blob/master/README.md

$ python3 -m model.kws.kws --export --quantize --global-scale 4.0 -o build --debug

Error back trace

...
WARNING:root:Attribute T is ignored in relay.sym.softmax
WARNING:root:Attribute _output_shapes is ignored in relay.sym.softmax
WARNING:root:Attribute _node_name is ignored in relay.sym.softmax
WARNING:root:Attribute _target_layout is ignored in relay.sym.softmax
INFO: Quantizing...
INFO: Global Scale: 4.0
Traceback (most recent call last):
  File "python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "Github/azsphere/python/model/kws/kws.py", line 327, in <module>
    mod, params = export_module(OPTS)
  File "Github/azsphere/python/model/kws/kws.py", line 120, in export_module
    mod = relay.quantize.quantize(mod, params)
  File "Github/tvm-upstream/python/tvm/relay/quantize/quantize.py", line 371, in quantize
    mod = quantize_seq(mod)
  File "Github/tvm-upstream/python/tvm/ir/transform.py", line 127, in __call__
    return _ffi_transform_api.RunPass(self, mod)
  File "Github/tvm-upstream/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (8) 9   libtvm.dylib                        0x0000000112bb0770 tvm::NodeFunctor<void (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>*) const + 288
  [bt] (7) 8   libtvm.dylib                        0x0000000112e0b104 tvm::relay::ExprVisitor::VisitExpr_(tvm::relay::IfNode const*) + 52
  [bt] (6) 7   libtvm.dylib                        0x0000000112e05ac4 tvm::relay::MixedModeVisitor::VisitExpr(tvm::RelayExpr const&) + 1540
  [bt] (5) 6   libtvm.dylib                        0x0000000112e0543b tvm::relay::MixedModeVisitor::VisitLeaf(tvm::RelayExpr const&) + 59
  [bt] (4) 5   libtvm.dylib                        0x0000000112bb047d tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&) + 173
  [bt] (3) 4   libtvm.dylib                        0x0000000112bb0770 tvm::NodeFunctor<void (tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>*)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>*) const + 288
  [bt] (2) 3   libtvm.dylib                        0x0000000112be2938 tvm::relay::TypeVarEVisitor::VisitExpr_(tvm::ConstructorNode const*) + 56
  [bt] (1) 2   libtvm.dylib                        0x0000000112347515 tvm::IRModuleNode::LookupTypeDef(tvm::GlobalTypeVar const&) const + 469
  [bt] (0) 1   libtvm.dylib                        0x0000000112116d6f dmlc::LogMessageFatal::~LogMessageFatal() + 111
  File tvm-upstream/src/ir/module.cc", line 272
TVMError: 
---------------------------------------------------------------
An internal invariant was violated during the execution of TVM.
Please read TVM's error reporting guidelines.
More details can be found here: https://discuss.tvm.ai/t/error-reporting/7793.