"use strict";(self.webpackChunkrspress_doc_template=self.webpackChunkrspress_doc_template||[]).push([["9140"],{73620:function(e,n,s){s.r(n);var t=s(85893),a=s(50065);function i(e){let n=Object.assign({h1:"h1",a:"a",pre:"pre",code:"code",span:"span",p:"p"},(0,a.ah)(),e.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.h1,{id:"\u4F2A\u91CF\u5316\u7B97\u5B50",children:[(0,t.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u4F2A\u91CF\u5316\u7B97\u5B50",children:"#"}),"\u4F2A\u91CF\u5316\u7B97\u5B50"]}),"\n",(0,t.jsx)(n.pre,{className:"code",children:(0,t.jsx)(n.pre,{className:"shiki css-variables has-line-number",style:{backgroundColor:"var(--shiki-color-background)"},tabIndex:"0",children:(0,t.jsxs)(n.code,{className:"language-python",meta:"",children:[(0,t.jsxs)(n.span,{className:"line line-number",children:[(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"class"}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" horizon_plugin_pytorch"}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:"."}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"quantization"}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:"."}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-function)"},children:"FakeQuantize "}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:"(observer: "}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-constant)"},children:"type"}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:", channel_len: int "}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:" "}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-constant)"},children:"1"}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:", "}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"**"}),(0,t.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:"kwargs)"})]}),"\n"]})})}),"\n",(0,t.jsx)(n.p,{children:"Simulate the quantize and dequantize operations in training time."}),"\n",(0,t.jsx)(n.p,{children:"The output of this module is given by"}),"\n",(0,t.jsx)(n.p,{children:"fake_quant_x = clamp(round(x / scale), quant_min, quant_max) * scale"}),"\n",(0,t.jsx)(n.p,{children:"scale defines the scale factor used for quantization."}),"\n",(0,t.jsx)(n.p,{children:"zero_point specifies the quantized value to which 0 in floating point maps to"}),"\n",(0,t.jsx)(n.p,{children:"quant_min specifies the minimum allowable quantized value."}),"\n",(0,t.jsx)(n.p,{children:"quant_max specifies the maximum allowable quantized value."}),"\n",(0,t.jsx)(n.p,{children:"fake_quant_enabled controls the application of fake quantization on tensors, note that statistics can still be updated."}),"\n",(0,t.jsx)(n.p,{children:"observer_enabled controls statistics collection on tensors"}),"\n",(0,t.jsx)(n.p,{children:"dtype specifies the quantized dtype that is being emulated with fake-quantization, the allowable values is qint8 and qint16. The values of quant_min and quant_max should be chosen to be consistent with the dtype"}),"\n",(0,t.jsx)(n.p,{children:"Parameters:"}),"\n",(0,t.jsx)(n.p,{children:"observer (type) \u2013 Module for observing statistics on input tensors and calculating scale and zero-point."}),"\n",(0,t.jsx)(n.p,{children:"channel_len (int) \u2013 Size of data at channel dim."}),"\n",(0,t.jsx)(n.p,{children:"kwargs \u2013 Arguments for the observer module"})]})}function o(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:n}=Object.assign({},(0,a.ah)(),e.components);return n?(0,t.jsx)(n,Object.assign({},e,{children:(0,t.jsx)(i,e)})):i(e)}n.default=o,o.__RSPRESS_PAGE_META={},o.__RSPRESS_PAGE_META["latest%2Fzh%2Fguide%2Fplugin%2Fplugin_api_reference%2Ffake_quantize.md"]={toc:[],title:"\u4F2A\u91CF\u5316\u7B97\u5B50",frontmatter:{}}}}]);