Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (gpxq): adding input quant to process input #943

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/brevitas/graph/gpfq.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from brevitas.graph.gpxq import StopFwdException
from brevitas.graph.gpxq import SUPPORTED_CONV_OP
import brevitas.nn as qnn
from brevitas.quant_tensor import _unpack_quant_tensor
from brevitas.quant_tensor import QuantTensor


Expand Down Expand Up @@ -163,6 +164,7 @@ def update_batch(self, module, input, current_layer):
is_quant_enabled = module.weight_quant.is_quant_enabled

inp = self.process_input(input)
inp = _unpack_quant_tensor(inp)
batch_size = inp.shape[0]

# Preprocess the input to compute the Hessian
Expand Down Expand Up @@ -315,7 +317,6 @@ def __init__(

def process_input(self, inp):
inp = super().process_input(inp)
inp = self.layer.input_quant(inp)

is_quant_enabled = self.layer.weight_quant.is_quant_enabled

Expand Down
2 changes: 2 additions & 0 deletions src/brevitas/graph/gptq.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from brevitas.graph.gpxq import StopFwdException
from brevitas.graph.gpxq import SUPPORTED_CONV_OP
import brevitas.nn as qnn
from brevitas.quant_tensor import _unpack_quant_tensor


class gptq_mode(gpxq_mode):
Expand Down Expand Up @@ -144,6 +145,7 @@ def update_batch(self, module, input, current_layer):
# Update reference to current layer
current_layer.layer_names.add(self.name)
inp = self.process_input(input)
inp = _unpack_quant_tensor(inp)
batch_size = inp.shape[0]

# Preprocess the input to compute the Hessian
Expand Down
2 changes: 2 additions & 0 deletions src/brevitas/graph/gpxq.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def process_input(self, inp):
batch_dim = inp.names.index('N')
inp.rename_(None)
inp = inp.transpose(0, batch_dim)

inp = self.layer.input_quant(inp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I think we need to do this before we start reshaping and adjusting dim, etc.
In case of activations with per-channel scale factor we could have unexpected behaviours

return inp

@abstractmethod
Expand Down
Loading