question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about linear quantization

See original GitHub issue

I figure out the procedure of linear quantization and reproduce the experiments,

  1. Search the quantization strategy on the imagenet100 dataset.
  2. Finetune the model on the whole imagenet dataset with the strategy obtained from step 1.

It seems like the final accuracy of the quantized model is more dependent on the fine-tuning. Another question is why the bit reduction process starts from the last layer as the _final_action_wall function shows.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

2reactions
frankinwicommented, Nov 23, 2022

@alan303138

  1. The QConv2d inherits from the QModule base class. https://github.com/mit-han-lab/haq/blob/8228d126c800446fdc1cc263555d1e5aed7d9dfd/lib/utils/quantize_utils.py#L363 The construction function of QConv2d initializes the w_bit=-1, which will first initialize the self._w_bit = w_bit in QModule, i.e., self._w_bit = w_bit=-1 https://github.com/mit-han-lab/haq/blob/8228d126c800446fdc1cc263555d1e5aed7d9dfd/lib/utils/quantize_utils.py#L366

  2. When running the forward function of QConv2d, it will first call self._quantize_activation(inputs=inputs) then self._quantize_weight(weight=weight). https://github.com/mit-han-lab/haq/blob/8228d126c800446fdc1cc263555d1e5aed7d9dfd/lib/utils/quantize_utils.py#L395

  3. Take self._quantize_weight(weight=weight) as example, now self._w_bit = w_bit=-1, it will jump to line 315 and return weights without quantization. https://github.com/mit-han-lab/haq/blob/8228d126c800446fdc1cc263555d1e5aed7d9dfd/lib/utils/quantize_utils.py#L287 https://github.com/mit-han-lab/haq/blob/8228d126c800446fdc1cc263555d1e5aed7d9dfd/lib/utils/quantize_utils.py#L315

Putting them all together, if we do not use half-precision (fp16, see --half flag) and do not specify the w_bit and a_bit for each QConv2d and QLinear layer, the qmobilenetv2 will not be quantized.

According to run_pretrain.sh and pretrain.py, the pre-trained file mobiletv2-150.pth.tar seems to use fp16. Therefore, the mobiletv2-150.pth.tar file might be unsuitable for linear quantization. You can load the mobiletv2-150.pth.tar and insert some prints before https://github.com/mit-han-lab/haq/blob/8228d126c800446fdc1cc263555d1e5aed7d9dfd/models/mobilenetv2.py#L192 to check it out.

2reactions
frankinwicommented, Oct 8, 2020

@87Candy I have not encountered this error. self._build_state_embedding() function is used to build the ten-dimensional feature vector as the paper section 3.1 shows, you can check it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

QUANTIZATION questions & answers for quizzes ... - Quizizz
Q. Select the quantization techniques.. answer choices. Linear quantization. Uniform quantization.
Read more >
What is the difference between Linear Quantization and Non ...
It's pretty simple really. With linear quantization every increment in the sampled value corresponds to a fixed size analogue increment.
Read more >
Quantization (signal processing) - Wikipedia
Quantization, in mathematics and digital signal processing, is the process of mapping input values from a large set (often a continuous set) to...
Read more >
Linear quantization in quantum electrodynamics?
Quantization is done for the free theory, without interactions, and this free theory is linear. For a scalar boson, for instance, each composant ......
Read more >
Linear Quantization by Effective Resistance Sampling
QUANTIZED LINEAR SENSING. ❖ The linear model: ❖ The quantized sensing problem: ✴ Measurements of y cannot be made in arbitrary precision.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found