Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QAT recommendation #2451

Closed
shuyuan-wang opened this issue Nov 3, 2022 · 5 comments
Closed

QAT recommendation #2451

shuyuan-wang opened this issue Nov 3, 2022 · 5 comments
Assignees
Labels
question Further information is requested triaged Issue has been triaged by maintainers

Comments

@shuyuan-wang
Copy link

shuyuan-wang commented Nov 3, 2022

In the document docs, It recommends not change quantization representation (scale) during training, at least not too frequently. How exactly do I not change scale during QAT training?

@zerollzeng
Copy link
Collaborator

@ttyio ^ ^ I would also like to learn about this

@zerollzeng zerollzeng added the triaged Issue has been triaged by maintainers label Nov 3, 2022
@ttyio
Copy link
Collaborator

ttyio commented Nov 4, 2022

@shuyuan-wang ,
see https://github.com/NVIDIA/TensorRT/blob/main/tools/pytorch-quantization/examples/torchvision/classification_flow.py#L387, the scale is changed during calibration.

for name, module in model.named_modules():
    if isinstance(module, quant_nn.TensorQuantizer):
        if module._calibrator is not None:
            module.disable_quant()
            module.enable_calib()
        else:
            module.disable()

By call

   module.disable_calib()

The calibration is turned off, and you can call

   module.enable_quant()

to do fine-tuning without change scale.

@ttyio ttyio added question Further information is requested Topic: QAT labels Nov 4, 2022
@shuyuan-wang
Copy link
Author

Thanks

@zsh4614
Copy link

zsh4614 commented Jan 6, 2025

@shuyuan-wang , see https://github.com/NVIDIA/TensorRT/blob/main/tools/pytorch-quantization/examples/torchvision/classification_flow.py#L387, the scale is changed during calibration.

for name, module in model.named_modules():
    if isinstance(module, quant_nn.TensorQuantizer):
        if module._calibrator is not None:
            module.disable_quant()
            module.enable_calib()
        else:
            module.disable()

By call

   module.disable_calib()

The calibration is turned off, and you can call

   module.enable_quant()

to do fine-tuning without change scale.

Sorry, I have a question. During the fine-tuning process of QAT, the model weights will change. If the scale of the weights remains unchanged, is the scale calculated during calibration still reasonable? Should the scale never be updated during fine-tuning? If it can be updated, how should the scale be updated during training? Are there any recommended update strategies?

@shuyuan-wang
Copy link
Author

shuyuan-wang commented Jan 6, 2025

@shuyuan-wang , see https://github.com/NVIDIA/TensorRT/blob/main/tools/pytorch-quantization/examples/torchvision/classification_flow.py#L387, the scale is changed during calibration.

for name, module in model.named_modules():
    if isinstance(module, quant_nn.TensorQuantizer):
        if module._calibrator is not None:
            module.disable_quant()
            module.enable_calib()
        else:
            module.disable()

By call

   module.disable_calib()

The calibration is turned off, and you can call

   module.enable_quant()

to do fine-tuning without change scale.

Sorry, I have a question. During the fine-tuning process of QAT, the model weights will change. If the scale of the weights remains unchanged, is the scale calculated during calibration still reasonable? Should the scale never be updated during fine-tuning? If it can be updated, how should the scale be updated during training? Are there any recommended update strategies?

I would say during QAT, the weight is adjusted based on the the newly calculated scale during PTQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested triaged Issue has been triaged by maintainers
Projects
None yet
Development

No branches or pull requests

4 participants