ngraph icon indicating copy to clipboard operation
ngraph copied to clipboard

About int 8bit support

Open WilliamTambellini opened this issue 8 years ago • 6 comments

Hello I have looked at ngraph sources/examples/tests and the support for integer 8bit seems quite unclear:

  • the 8bit int are typed in element_type.hpp :
    extern const Type i8;
    extern const Type u8;

  • they are correctly map to mkl types in mkldnn_utils.hpp : {element::i8, mkldnn::memory::data_type::s8}, {element::u8, mkldnn::memory::data_type::u8},

  • I presume the cpu backend supports 8 bit via mkldnn : at least mkldnn seems to already implement forward conv :
    repos/ngraph/build/third-party/mkldnn/src/src/cpu/gemm_u8s8s32x_convolution.hpp and gemm_u8s8s32x_convolution.cpp

  • the cuda support of int8 in ngraph is also unclear at least the kernel builder typedef it : void runtime::gpu::CudaKernelBuilder::add_pod_typedefs(codegen::CodeWriter& writer) { writer << "typedef signed char int8_t;\n"; but I am not sure that would be enough to take advantage of native support (DP4A and DP2A) for these gpus capable to run some mixed precision ops (TitanX, Volta, ...) unless through cudnn :
    https://devblogs.nvidia.com/mixed-precision-programming-cuda-8

Could anyone summarize the current 8bit integer support for inference with ngraph ?

Kind

Ref : https://software.intel.com/en-us/mkl-developer-reference-c-cblas-gemm-1 https://software.intel.com/en-us/mkl-developer-reference-c-cblas_gemm_s8u8s32x https://intel.github.io/mkl-dnn/ex_int8_simplenet.html

WilliamTambellini avatar May 21 '18 23:05 WilliamTambellini

On the CPU backend, we have only enabled FP32 mkldnn apis so far. Next quarter, we plan to add support for int8 MKLDNN APIs.

jbobba avatar May 21 '18 23:05 jbobba

Hi @WilliamTambellini. The situation is similar for the GPU backend. We are currently targeting FP32 but are considering int8 inference support for mixed precision in the future. There is a question of coverage and which ops to begin enabling int8 support for first -- likely int8 convolution. Do you have a use case or requirements you'd like to see nGraph support?

csullivan avatar May 22 '18 14:05 csullivan

Hi @csullivan
My use case is the typical low precision inference doable after quantization. Example: https://arxiv.org/pdf/1804.05038.pdf So the requirement would be at least the typical linear layer meaning at least matrix multiplication, in theory s8 matmul s8 to s32 but perhaps the mkl s8u8s32 could do the job (checking). In ngraph, perhaps it would mean the matmul_bias.cpp/hpp. W.

WilliamTambellini avatar May 22 '18 16:05 WilliamTambellini

We are working on something that will work with the various ways different frameworks and devices support quantization, so of which seem to change from week to week,

diyessi avatar Oct 08 '18 18:10 diyessi

@diyessi any updates on this issue?

skariel avatar Jun 19 '19 13:06 skariel

Take a look at op/experimental, the ops with Quant in their names.

diyessi avatar Jun 19 '19 14:06 diyessi