How to write scale and zero_point to fp32 tensor without doing quantization?

username: alanzhai219
cooked: <p>In PyTorch1.3, float-tensor has scale and zero_point. Could I set value to scale and zero_point to a float32 tensor without coverting fp32 tensor to quant?</p>

username: dskhudia
cooked: <p>May I know the reason for doing this?</p>

username: Zafar
cooked: <blockquote>
<p>In PyTorch1.3, float-tensor has scale and zero_point. Could I set value to scale and zero_point to a float32 tensor without coverting fp32 tensor to quant?</p>
</blockquote>
<p><code>q_scale</code> and <code>q_zero_point</code> exist in FP tensor, but they do not make sense outside of the quantization context. That’s why, if you try accessing those methods on a FP tensor, you are supposed to get an error:</p>
<pre data-code-wrap="python"><code class="lang-python">&gt;&gt;&gt; import torch
&gt;&gt;&gt; x = torch.tensor([1, 2, 3])
&gt;&gt;&gt; x.q_scale()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-13-a850e3e1a3e9&gt; in &lt;module&gt;
----&gt; 1 x.q_scale()

RuntimeError: Could not run 'aten::q_scale' with arguments from the 'CPUTensorId' backend. 'aten::q_scale' is only available for these backends: [QuantizedCPUTensorId, VariableTensorId].

&gt;&gt;&gt; x.q_zero_point()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-15-6cbfbea33d3d&gt; in &lt;module&gt;
----&gt; 1 x.q_zero_point()

RuntimeError: Could not run 'aten::q_zero_point' with arguments from the 'CPUTensorId' backend. 'aten::q_zero_point' is only available for these backends: [QuantizedCPUTensorId, VariableTensorId].

</code></pre>
<p>As <a class="mention" href="/u/dskhudia">@dskhudia</a> asked, is there a specific reason you would want to do that? Maybe there is another way of accomplish what you are trying to do</p>

username: alanzhai219
cooked: <p>Thanks for your reply. It is because our operation quantization compiler has too much rules.</p>

username: Zafar
cooked: <p>I don’t think I can suggest an alternative, as I don’t know what rules you are referring to. Generally, to answer your question, we don’t allow setting scale and zero_point for a float tensor, and frankly can’t even imagine a use case <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:">.</p>

username: jerryzh168
cooked: <aside class="quote no-group" data-username="Zafar" data-post="3" data-topic="64868">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zafar/48/11532_2.png" class="avatar"> Zafar:</div>
<blockquote>
<p><code>q_scale</code> and <code>q_zero_point</code> exist in FP tensor, but they do not make sense outside of the quantization context. That’s why, if you try accessing those methods on a FP tensor, you are supposed to get an error:</p>
<pre><code class="lang-auto">
</code></pre>
</blockquote>
</aside>
<p>are you saying you want to have floating point zero_point? I think we’ll have quantizer support for that</p>