alexbooth opened a new issue #4588: [RELAY][BUG] Quantize calibrate 
relay.build_module.build(...) returns empty graph
URL: https://github.com/apache/incubator-tvm/issues/4588
 
 
   I'm having an issue getting quantization working with a calibration dataset. 
I'm looking at _calibrate.py and if I print  ```graph``` after the line  
```graph, lib, params = _build_module.build(func, target=target)``` then I just 
see the following output regardless of the input.
   ```{
     "nodes": [], 
     "arg_nodes": [], 
     "heads": [], 
     "attrs": {
       "dltype": [
         "list_str", 
         []
       ], 
       "shape": [
         "list_shape", 
         []
       ], 
       "storage_id": [
         "list_int", 
         []
       ]
     }, 
     "node_row_ptr": [0]
   }
   ```
   ```mod["main"]``` still contains the correct main function for my network, 
but I see another function added to the module which looks like 
   ```
   v0.0.4
   fn () {
     ()
   }
   v0.0.4
   def @main(...)  {
     ...
     ... # my main function
     ...
   }
   
   ```
   This happens after the line  ```func = 
_quantize.CreateStatsCollector(func)```. 
   ```python
   def collect_stats(mod, dataset):
       """Given an annotated graph, create a profile graph to collect profile 
data from the
       calibration dataset. This pass collects simulated_quantize op input into 
a tuple.
       Simulated_quantize ops are rewritten to identity mode. The tuple is the 
output of the profile
       graph.
   
       Parameters
       ----------
       mod: Module
           The simulation graph after annotation.
   
       Returns
       -------
       ret: list of ndarray
           List of output data of each layer
       """
   
       logging.info("collecting statistics for calibration...")
       func = mod['main']
       func = _quantize.CreateStatsCollector(func)
   
       if tvm.target.current_target():
           target = tvm.target.current_target()
           ctx = tvm.context(target.target_name)
       else:
           target = 'llvm'
           ctx = tvm.context(target)
   
       with _transform.build_config(opt_level=3):
           graph, lib, params = _build_module.build(func, target=target)
       outputs = []
       runtime = graph_runtime.create(graph, lib, ctx)
       runtime.set_input(**params)
   
       num_outputs = runtime.get_num_outputs()
       outputs = [[] for i in range(num_outputs)]
   
       for batch in dataset:
           runtime.set_input(**batch)
           runtime.run()
           for i in range(num_outputs):
               output = runtime.get_output(i).asnumpy()
               outputs[i].append(output)
       for i in range(num_outputs):
           outputs[i] = np.concatenate(outputs[i]).reshape(-1)
       return outputs
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to