(self, inputs)
| 100 | return output |
| 101 | |
| 102 | def quantize_tenary(self, inputs): |
| 103 | input_flat = inputs.reshape(self.q_groups, -1) |
| 104 | n = input_flat.shape[1] |
| 105 | m = input_flat.norm(p=1, dim=1).div(n) |
| 106 | thres = (0.7 * m).view(-1, 1) #.expand_as(input_flat) |
| 107 | pos = (input_flat > thres).type(inputs.type()) |
| 108 | neg = (input_flat < -thres).type(inputs.type()) |
| 109 | mask = (input_flat.abs() > thres).type(inputs.type()) |
| 110 | alpha = ((mask * input_flat).abs().sum(dim=1) / mask.sum(dim=1)).view(-1, 1) |
| 111 | output = alpha * pos - alpha * neg |
| 112 | output = output.reshape(inputs.shape).contiguous() |
| 113 | return output |
| 114 | |
| 115 | def quantize_binary(self, inputs): |
| 116 | input_flat = inputs.reshape(self.q_groups, -1) |
no test coverage detected