Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Fix dorefa bnn #3247

Merged
merged 6 commits into from
Jan 5, 2021
Merged

Fix dorefa bnn #3247

merged 6 commits into from
Jan 5, 2021

Conversation

linbinskn
Copy link
Contributor

Because of the modification of compressor to solve the grad error, BNN and Dorefa can't operate normally on current code. This PR fixes this problem.

@linbinskn linbinskn changed the base branch from master to v2.0 January 1, 2021 02:28
@QuanluZhang QuanluZhang requested review from Cjkkkk and J-shang January 2, 2021 15:51
@@ -148,6 +157,7 @@ def __init__(self, model, config_list, optimizer=None):
types of nn.module you want to apply quantization, eg. 'Conv2d'
"""
super().__init__(model, config_list, optimizer)
self.quant_grad = QATGrad
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where we use self.quant_grad?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
This is used to clip backward gradient between wmin and wmax.

@liuzhe-lz liuzhe-lz mentioned this pull request Jan 4, 2021
77 tasks
0: "input",
1: "weight",
2: "output"
}

class QuantGrad(torch.autograd.Function):
Copy link
Contributor

@Cjkkkk Cjkkkk Jan 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best way to accomplish the quantization gradient calculation is to add quant_weight_grad, quant_input_grad, quant_output_grad method to quantizer class and QuantGrad class only calls this methods instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this will take us time to discuss a new design and quantizer may be refactored in another pr. In this pr, we only fix dorefa and bnn unfit problem.

@linbinskn linbinskn requested review from Cjkkkk and J-shang January 4, 2021 03:35
@QuanluZhang QuanluZhang merged commit 3b1d5cd into microsoft:v2.0 Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants