MCPcopy Create free account
hub / github.com/OpenGVLab/EfficientQAT / TruncateFunction

Class TruncateFunction

quantize/utils.py:81–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79
80
81class TruncateFunction(torch.autograd.Function):
82 @staticmethod
83 def forward(ctx, input, threshold):
84 truncated_tensor = input.clone()
85 truncated_tensor[truncated_tensor.abs() < threshold] = truncated_tensor[truncated_tensor.abs() < threshold].sign() * threshold
86 return truncated_tensor
87
88
89 @staticmethod
90 def backward(ctx, grad_output):
91 grad_input = grad_output.clone()
92 return grad_input, None
93
94
95def truncate_number(number, threshold=1e-2):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected