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

WQ的max_val为什么是 (1 << self.bits) - 2)? #104

Open
xingyueye opened this issue Jan 25, 2022 · 0 comments
Open

WQ的max_val为什么是 (1 << self.bits) - 2)? #104

xingyueye opened this issue Jan 25, 2022 · 0 comments

Comments

@xingyueye
Copy link

你好,我注意到IAO的quantizer中,weights的max_val被设置为 (1 << self.bits) - 2 ,而activation是(1 << self.bits) - 1)。不知道为什么这样设置,两者不应该都是255(8bit)吗?

class UnsignedQuantizer(Quantizer):
    def __init__(self, *args, **kwargs):
        super(UnsignedQuantizer, self).__init__(*args, **kwargs)
        if self.activation_weight_flag == 0:  # weight
            self.register_buffer(
                "quant_min_val", torch.tensor((0), dtype=torch.float32)
            )
            self.register_buffer(
                "quant_max_val",
                torch.tensor(((1 << self.bits) - 2), dtype=torch.float32),
            )
        elif self.activation_weight_flag == 1:  # activation
            self.register_buffer(
                "quant_min_val", torch.tensor((0), dtype=torch.float32)
            )
            self.register_buffer(
                "quant_max_val",
                torch.tensor(((1 << self.bits) - 1), dtype=torch.float32),
            )
        else:
            print("activation_weight_flag error")
@xingyueye xingyueye changed the title WQ的max_val为什么是 (1 << self.bits) - 1)? WQ的max_val为什么是 (1 << self.bits) - 2)? Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant