Issue about static quantization (prepare and convert)

cokespace2: <h2><a name="background-1" class="anchor" href="#background-1"></a>Background</h2>
<p>I tried to quantize a simple model like ResNet18 (from <code>torchvision</code>), and didn’t like to fuse conv-bn-relu pattern, so I comment the fusing part in <code>convert_fx.py</code>, by which I can get a model like:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/7/c78002a64de0239b08b54be676c5290e294a7c12.png" data-download-href="https://discuss.pytorch.org/uploads/default/c78002a64de0239b08b54be676c5290e294a7c12" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/c/7/c78002a64de0239b08b54be676c5290e294a7c12.png" alt="image" data-base62-sha1="ssRhcP4f825OoyBMYq2u3iA92LM" width="690" height="167" data-dominant-color="2E3038"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">925×225 15 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
(As one can see, the <code>Conv2d</code> modules have been replaced to the referenced ones)</p>
<p>and the graph is like:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/e/0e25524f3b3add27339d97489c37e46e71466402.png" data-download-href="https://discuss.pytorch.org/uploads/default/0e25524f3b3add27339d97489c37e46e71466402" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/0/e/0e25524f3b3add27339d97489c37e46e71466402.png" alt="image" data-base62-sha1="218E1B8EOayDHuRmeMtJhEvxkVY" width="690" height="125" data-dominant-color="252A32"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1361×247 8.41 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
(As one can see, the conv-bn-relu is not fused and there also has no observer between them)</p>
<h2><a name="issue-2" class="anchor" href="#issue-2"></a>Issue</h2>
<p>Once I run <code>convert</code> function to convert this <code>prepared_model</code> to quantized one, the graph would be like:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/4/640ade1128b6c0e20917027416be44664d7b0e3c.png" data-download-href="https://discuss.pytorch.org/uploads/default/640ade1128b6c0e20917027416be44664d7b0e3c" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/6/4/640ade1128b6c0e20917027416be44664d7b0e3c.png" alt="image" data-base62-sha1="eh11T2xvTNnkVhZPTQwuAqcwu5e" width="690" height="182" data-dominant-color="20252D"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1530×404 16 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>As expected, the reference convolution would be convert to QuantConv and there would be some nodes like <code>conv1_scale_0</code> and <code>conv1_zero_point_0</code>, so when acting <code>lower_to_fbgemm()</code> these reference modules would not be convert to QuantConv, is something missing or some configs I set are wrong?</p>

supriyar: <p>The output of the convert is the reference quantized model so you wouldn’t see the actual quantized ops in the graph. I’m not sure exactly what your question is.<br>
Can you share a simple repro (maybe with a Conv+BN+Relu module) along with the quantization API calls you use, that exhibits the same issue you are describing?</p>
<p>cc <a class="mention" href="/u/jerryzh168">@jerryzh168</a></p>

cokespace2: <p>I simplified my question as here: <a href="https://discuss.pytorch.org/t/question-about-prepare-fx/177439/2" class="inline-onebox">Question about prepare_fx - #2 by supriyar</a></p>
<p>Thanks anyway!</p>