Skip to content

Commit

Permalink
decorate fake quant with torch.no_grad (#8)
Browse files Browse the repository at this point in the history
gradients shouldn't be computed for Q/DQ in QAT
  • Loading branch information
bfineran authored Apr 15, 2024
1 parent 129770e commit 0ac6f60
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sparsetensors/quantization/lifecycle/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
__all__ = ["wrap_module_forward_quantized"]


@torch.no_grad()
def quantize(
x: torch.Tensor,
scale: torch.Tensor,
Expand All @@ -39,6 +40,7 @@ def quantize(
)


@torch.no_grad()
def dequantize(
x_q: torch.Tensor,
scale: torch.Tensor,
Expand All @@ -47,6 +49,7 @@ def dequantize(
return (x_q - zero_point) * scale


@torch.no_grad()
def fake_quantize(
x: torch.Tensor,
scale: torch.Tensor,
Expand Down

0 comments on commit 0ac6f60

Please sign in to comment.