Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Adding HistogramObserver #2049

Closed
wants to merge 6 commits into from
Closed
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