Skip to content

Commit

Permalink
fixes act_order
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianandresgrob committed Nov 15, 2023
1 parent f4c99e5 commit a4ea065
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/brevitas/graph/gpfq.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,22 @@ def single_layer_update(self):
for t in range(weight.shape[-1]):
for group_index in range(self.groups):
U[group_index] += torch.matmul(
weight[group_index, :, t].unsqueeze(1),
weight[group_index, :, perm[t]].unsqueeze(1),
self.float_input[group_index, :,
t].unsqueeze(0)) #[OC/Groups, 1] * [1, INSHAPE[1]]
norm = torch.linalg.norm(self.quantized_input[group_index, :, t], 2) ** 2
perm[t]].unsqueeze(0)) #[OC/Groups, 1] * [1, INSHAPE[1]]
norm = torch.linalg.norm(self.quantized_input[group_index, :, perm[t]], 2) ** 2
if norm > 0:
q_arg = U[group_index].matmul(self.quantized_input[group_index, :, t]) / norm
q_arg = U[group_index].matmul(
self.quantized_input[group_index, :, perm[t]]) / norm
else:
q_arg = torch.zeros_like(U[group_index, :, 0])

weight[group_index, :, t] = q_arg
weight[group_index, :, perm[t]] = q_arg
q = self.get_quant_weights(t, 0, permutation_list)
for group_index in range(self.groups):
U[group_index] -= torch.matmul(
q[group_index].unsqueeze(1),
self.quantized_input[group_index, :, t].unsqueeze(0))
self.quantized_input[group_index, :, perm[t]].unsqueeze(0))

del self.float_input
del self.quantized_input
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
default=3,
type=int,
help='Exponent bit width used with float quantization for activations (default: 3)')
add_bool_arg(parser, 'gptq', default=True, help='GPTQ (default: enabled)')
add_bool_arg(parser, 'gptq', default=False, help='GPTQ (default: disabled)')
add_bool_arg(parser, 'gpfq', default=False, help='GPFQ (default: disabled)')
add_bool_arg(
parser, 'gptq-act-order', default=False, help='GPTQ Act order heuristic (default: disabled)')
Expand Down

0 comments on commit a4ea065

Please sign in to comment.