quantization for tvm
play

Quantization for TVM Ziheng Jiang TVM Conference, Dec 12th 2018 - PowerPoint PPT Presentation

Quantization for TVM Ziheng Jiang TVM Conference, Dec 12th 2018 Quantization for TVM What is Quantization? source: Han et al Converting weight value to low-bit integer like 8bit precision from float-point without significant accuracy drop.


  1. Quantization for TVM Ziheng Jiang TVM Conference, Dec 12th 2018

  2. Quantization for TVM What is Quantization? source: Han et al Converting weight value to low-bit integer like 8bit precision from float-point without significant accuracy drop.

  3. Quantization for TVM Train Frontend DL Framework Convert Relay: High-Level Graph IR Apply Gain Compression & Acceleration: Quantization - Less storage space - Faster arithmetic operation Deploy - Friendly to accelerator and ultra low-power embedded devices

  4. Quantization for TVM Choice Spaces for Quantization - number of bit - 4bit, 8bit, 16bit - quantization scheme: - symmetric, asymmetric, etc. - hardware constraint: - e.g. prefer integer shift instead of float multiplication Goal Instead of proposing “the only right way to achieve quantization in TVM”, we would like to build a quantization workflow which can be customized flexibly .

  5. Quantization for TVM f32 f32 f32 f32 f32 Batch Original Conv2D ReLU Conv2D Norm f32 f32 f32 f32 f32 f32 Simulated Mul, Add Simulated After Annotate Conv2D Conv2D Quantize ReLu Quantize SimQ simulates the rounding f32 f32 error and saturating error during f32 f32 quantizing. Its argument will get Simulated Simulated W1 W2 tuned during calibrate . Quantize Quantize Clip ( Round ( x r * 2 nbit − sign )) * r SimQ ( nbit , range , sign ) = 2 nbit − sign i32 i32 i8 i32 f32 i8 Mul Clip Mul, Add Shift Clip After Realize Conv2D Conv2D Cast ReLu Cast i8 i8 f32 f32 Mul Clip Mul Clip W1 W2 Cast Cast

  6. Quantization for TVM Code Sample # user can override the annotate function @register_annotate_function("nn.conv2d", override=True) def annotate_conv2d(ref_call, new_args, ctx): lhs, rhs = new_args lhs = attach_simulated_quantize(lhs, sign=False, rounding='round') rhs = attach_simulated_quantize(lhs, sign=False, rounding='stochastic_round') return expr.Call(ref_call.op, [lhs, rhs], ref_call.attrs) # assuming we have an existed mxnet model, convert it to relay graph graph, params = relay.frontend.from_mxnet(mxnet_model) # quantize the relay graph with all kinds of configure with qconfig(nbit_dict={QFieldKind.ACTIVATION: 24}, global_scale=8.0, skip_k_conv=1): qgraph, qparams = quantize(graph, params) # ...build and deploy it locally or remotely with tvm

  7. Quantization for TVM Demonstration with 8bit Symmetric Quantization Global Scale Accuracy Time/ms Cortex A53 VTA 2.0 64.1% ResNet18 4.0 68.1% 307.09 64.87 8.0 69.5% MobileNet 131.14 51.96 16.0 69.6% Accuracy Drop with ResNet18 (original 70.8%) End to End Performance

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend