MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / forward

Method forward

deepspeed/compression/utils.py:195–217  ·  view source on GitHub ↗

Args: inputs (`torch.FloatTensor`) The input which needs to be quantized num_bits (int) Dummy variable min_value/max_value (torch.FloatTensor) Used for static activation quantization; for now they are dummy

(ctx, input, num_bits, min_value=None, max_value=None, num_groups=1)

Source from the content-addressed store, hash-verified

193
194 @staticmethod
195 def forward(ctx, input, num_bits, min_value=None, max_value=None, num_groups=1):
196 """
197 Args:
198 inputs (`torch.FloatTensor`)
199 The input which needs to be quantized
200 num_bits (int)
201 Dummy variable
202 min_value/max_value (torch.FloatTensor)
203 Used for static activation quantization; for now they are dummy variable
204 num_groups (int)
205 How many groups to partition the quantization into
206 Returns:
207 quantized_input (`torch.FloatTensor`)
208 Quantized input
209 """
210
211 assert (min_value is None and max_value is None)
212 input_flat = input.reshape(num_groups, -1)
213 n = input_flat.shape[1]
214 m = input_flat.norm(p=1, dim=1, keepdim=True).div(n)
215 output = input_flat.sign().mul(m)
216 output = output.reshape(input.shape).contiguous()
217 return output
218
219 @staticmethod
220 def backward(ctx, grad_output):

Callers

nothing calls this directly

Calls 1

reshapeMethod · 0.45

Tested by

no test coverage detected