-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathFrameworkInfo.html
More file actions
157 lines (146 loc) · 12.5 KB
/
FrameworkInfo.html
File metadata and controls
157 lines (146 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en" data-content_root="../../../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>FrameworkInfo Class — MCT Documentation: ver 2.6.0</title>
<link rel="stylesheet" type="text/css" href="../../../static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../../static/bizstyle.css?v=5283bb3d" />
<link rel="stylesheet" type="text/css" href="../../../static/css/custom.css?v=01243f34" />
<script src="../../../static/documentation_options.js?v=ae39cb24"></script>
<script src="../../../static/doctools.js?v=9bcbadda"></script>
<script src="../../../static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../../static/bizstyle.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<!--[if lt IE 9]>
<script src="static/css3-mediaqueries.js"></script>
<![endif]-->
</head><body>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="nav-item nav-item-0"><a href="../../../index.html">MCT Documentation: ver 2.6.0</a> »</li>
<li class="nav-item nav-item-this"><a href="">FrameworkInfo Class</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="frameworkinfo-class">
<span id="ug-frameworkinfo"></span><h1>FrameworkInfo Class<a class="headerlink" href="#frameworkinfo-class" title="Link to this heading">¶</a></h1>
<p><strong>The following API can be used to pass MCT framework-related information to use when optimizing the network</strong></p>
<dl class="py class">
<dt class="sig sig-object py" id="model_compression_toolkit.core.FrameworkInfo">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">model_compression_toolkit.core.</span></span><span class="sig-name descname"><span class="pre">FrameworkInfo</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">activation_quantizer_mapping</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">kernel_channels_mapping</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">activation_min_max_mapping</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">layer_min_max_mapping</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">kernel_ops_attributes_mapping</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">out_channel_axis_mapping</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#model_compression_toolkit.core.FrameworkInfo" title="Link to this definition">¶</a></dt>
<dd><p>A class to wrap all information about a specific framework the library needs to quantize a model.
Specifically, FrameworkInfo holds lists of layers by how they should be quantized, and multiple mappings such as
layer to it kernel channels indices, and a layer to its min/max values, etc.
The layers lists are divided into three groups:
kernel_ops: Layers that have coefficients and need to get quantized (e.g., Conv2D, Dense, etc.)
activation_ops: Layers that their outputs should get quantized (e.g., Add, ReLU, etc.)
no_quantization_ops:Layers that should not get quantized (e.g., Reshape, Transpose, etc.)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>activation_quantizer_mapping</strong> (<em>Dict</em><em>[</em><a class="reference internal" href="../modules/target_platform_capabilities.html#model_compression_toolkit.target_platform_capabilities.QuantizationMethod" title="model_compression_toolkit.target_platform_capabilities.QuantizationMethod"><em>QuantizationMethod</em></a><em>, </em><em>Callable</em><em>]</em>) – A dictionary mapping from QuantizationMethod to a quantization function.</p></li>
<li><p><strong>kernel_channels_mapping</strong> (<a class="reference internal" href="DefaultDict.html#model_compression_toolkit.DefaultDict" title="model_compression_toolkit.DefaultDict"><em>DefaultDict</em></a>) – Dictionary from a layer to a tuple of its kernel in/out channels indices.</p></li>
<li><p><strong>activation_min_max_mapping</strong> (<em>Dict</em><em>[</em><em>str</em><em>, </em><em>tuple</em><em>]</em>) – Dictionary from an activation function to its min/max output values.</p></li>
<li><p><strong>layer_min_max_mapping</strong> (<em>Dict</em><em>[</em><em>Any</em><em>, </em><em>tuple</em><em>]</em>) – Dictionary from a layer to its min/max output values.</p></li>
<li><p><strong>kernel_ops_attributes_mapping</strong> (<a class="reference internal" href="DefaultDict.html#model_compression_toolkit.DefaultDict" title="model_compression_toolkit.DefaultDict"><em>DefaultDict</em></a>) – Dictionary from a framework operator to a list of its weights attirbutes to quantize.</p></li>
<li><p><strong>out_channel_axis_mapping</strong> (<a class="reference internal" href="DefaultDict.html#model_compression_toolkit.DefaultDict" title="model_compression_toolkit.DefaultDict"><em>DefaultDict</em></a>) – Dictionary of output channels of the model’s layers (for computing statistics per-channel).</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>When quantizing a Keras model, if we want to quantize the kernels of Conv2D layers only, we can
set, and we know it’s kernel out/in channel indices are (3, 2) respectivly:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">tensorflow</span> <span class="k">as</span> <span class="nn">tf</span>
<span class="gp">>>> </span><span class="n">kernel_ops</span> <span class="o">=</span> <span class="p">[</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">Conv2D</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">kernel_channels_mapping</span> <span class="o">=</span> <span class="n">DefaultDict</span><span class="p">({</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">Conv2D</span><span class="p">:</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">)})</span>
</pre></div>
</div>
<p>Then, we can create a FrameworkInfo object:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">FrameworkInfo</span><span class="p">(</span><span class="n">kernel_channels_mapping</span><span class="p">,</span> <span class="p">{},</span> <span class="p">{})</span>
</pre></div>
</div>
<p>If an activation layer (tf.keras.layers.Activation) should be quantized and we know it’s min/max outputs range in advanced, we can add it to activation_min_max_mapping for saving the statistics collection time. For example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">activation_min_max_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'softmax'</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)}</span>
<span class="gp">>>> </span><span class="n">FrameworkInfo</span><span class="p">(</span><span class="n">kernel_channels_mapping</span><span class="p">,</span> <span class="n">activation_min_max_mapping</span><span class="p">,</span> <span class="p">{})</span>
</pre></div>
</div>
<p>If a layer’s activations should be quantized and we know it’s min/max outputs range in advanced, we can add it to layer_min_max_mapping for saving the statistics collection time. For example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">layer_min_max_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">Softmax</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)}</span>
<span class="gp">>>> </span><span class="n">FrameworkInfo</span><span class="p">(</span><span class="n">kernel_channels_mapping</span><span class="p">,</span> <span class="n">activation_min_max_mapping</span><span class="p">,</span> <span class="n">layer_min_max_mapping</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<div class="line-block">
<div class="line"><br /></div>
</div>
<section id="channelaxis">
<h2>ChannelAxis<a class="headerlink" href="#channelaxis" title="Link to this heading">¶</a></h2>
<p><strong>Enum to select the output channels format in the model:</strong></p>
<dl class="py class">
<dt class="sig sig-object py" id="model_compression_toolkit.core.ChannelAxis">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">model_compression_toolkit.core.</span></span><span class="sig-name descname"><span class="pre">ChannelAxis</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#model_compression_toolkit.core.ChannelAxis" title="Link to this definition">¶</a></dt>
<dd><p>Index of output channels axis:</p>
<p>NHWC - Output channels index is last.</p>
<p>NCHW - Output channels index is 1.</p>
</dd></dl>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">FrameworkInfo Class</a><ul>
<li><a class="reference internal" href="#model_compression_toolkit.core.FrameworkInfo"><code class="docutils literal notranslate"><span class="pre">FrameworkInfo</span></code></a></li>
<li><a class="reference internal" href="#channelaxis">ChannelAxis</a><ul>
<li><a class="reference internal" href="#model_compression_toolkit.core.ChannelAxis"><code class="docutils literal notranslate"><span class="pre">ChannelAxis</span></code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="nav-item nav-item-0"><a href="../../../index.html">MCT Documentation: ver 2.6.0</a> »</li>
<li class="nav-item nav-item-this"><a href="">FrameworkInfo Class</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2022, Sony Semiconductor Solutions.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
</div>
</body>
</html>