seanlatias opened a new pull request #5997:
URL: https://github.com/apache/incubator-tvm/pull/5997


   RFC discussion: 
https://discuss.tvm.ai/t/rfc-byoc-data-calibration-flow/7099/15
   
   This PR implements the analysis pass `get_calibration_data` mentioned in the 
RFC. The main functionality of this analysis pass is allowing users to easily 
get the calibration data from any Relay module. The calibration data includes 
the input and output tensor values of each subgraph in the module. Following is 
an example.
   
   The input relay graph that contains two subgraphs:
   ```
   def @dnnl0(%dnnl0_i0: Tensor[(3, 3), float32], %dnnl0_i1: Tensor[(3, 3), 
float32]) -> Tensor[(3, 3), float32] {
     add(%dnnl0_i0, dnnl0_i1) 
   }
   
   def @dnnl1(%dnnl0_i0: Tensor[(3, 3), float32], %dnnl0_i1: Tensor[(3, 3), 
float32]) -> Tensor[(3, 3), float32] {
     sub(%dnnl0_i0, dnnl0_i1) 
   }
   
   def @main(%data0: Tensor[(3, 3), float32], %data1: Tensor[(3, 3), float32], 
%data2: Tensor[(3, 3), float32]) -> Tensor[(3, 3), float32] {
     %0 = @dnnl0(%data0, %data1)
     @dnnl1(%0, %data2)
   }
   ```
   
   The Python API
   ```python
   mod = # the above relay graph
   data = {"data0": ..., "data1": ..., "data2": ...}
   
   calib_data = relay.analysis.get_calibration_data(mod, data)
   print(calib_data)
   ```
   
   The expected output
   ```
   {@dnnl0: {"inputs": [%data0, %data1], "outputs": [%0]},
    @dnnl1: {"inputs": [%0, %data2], "outputs":[%out]}}
   ```
   
   As can be seen, the output calibration data is a two-level dictionary. The 
first level takes in the GlobalVar of a subgraph as a key and the value is the 
second-level dictionary. The second level always has two keys: inputs and 
outputs, which map to the real tensor values of each subgraph. For more complex 
example please refer to the test.
   
   @comaniac @zhiics 


----------------------------------------------------------------
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]


Reply via email to