Skip to content

Adding HistogramObserver #2049

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_observer(self) -> "torch.quantization.FakeQuantize":

@validator("strategy")
def validate_strategy(cls, value):
valid_scopes = ["tensor", "channel"]
valid_scopes = ["tensor", "channel", "histogram"]
if value not in valid_scopes:
raise ValueError(f"`strategy` must be one of {valid_scopes}, got {value}")
return value
Expand Down Expand Up @@ -307,6 +307,14 @@ def get_observer(
qscheme=qscheme,
reduce_range=reduce_range,
)
elif strategy == "histogram":
qscheme = torch.per_tensor_symmetric if symmetric else torch.per_tensor_affine
observer_cls = torch_quantization.HistogramObserver
observer_kwargs = dict(
dtype=dtype,
qscheme=qscheme,
reduce_range=reduce_range,
)
else: # default to tensor strategy
qscheme = torch.per_tensor_symmetric if symmetric else torch.per_tensor_affine
observer_cls = torch_quantization.MovingAverageMinMaxObserver
Expand Down