Skip to content

Commit 7633904

Browse files
mcr229facebook-github-bot
authored andcommitted
quant params from static inputs (#573)
Summary: Pull Request resolved: #573 Since we allow tensor constants to be quantized inputs, we need to adjust the from_inputs api to search if this input is static or not. If it is static, then we take the first q node in get_attr --> q --> dq. If it is not static, then we just take the dq node to create the QuantParams object. In the past, we can take in static quant inputs only on weights and biases. Differential Revision: D49850149 fbshipit-source-id: 48bc0d6b0bb258f555201e9f182c1276c5d9247f
1 parent 8b0fc05 commit 7633904

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backends/xnnpack/operators/quant_params.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
import torch
1212
from executorch.backends.xnnpack.passes.tag_implicit_q_dq_pass import TagImplicitQDqPass
1313
from executorch.backends.xnnpack.utils.quant_utils import is_dequant, is_quant
14-
from executorch.backends.xnnpack.utils.utils import check_or_raise
14+
from executorch.backends.xnnpack.utils.utils import check_or_raise, is_param_node
1515
from executorch.exir.dialects._ops import ops as exir_ops
16+
from torch.export import ExportedProgram
1617

1718

1819
class QuantParams:
@@ -183,6 +184,11 @@ def from_inputs(cls, tensor_node: torch.fx.Node) -> Optional[QuantParams]:
183184
if is_dequant(tensor_node) and TagImplicitQDqPass.is_tagged_as_implicit_q_dq(
184185
tensor_node
185186
):
187+
dq_input = cast(torch.fx.Node, tensor_node.args[0])
188+
if is_quant(dq_input):
189+
q_input = cast(torch.fx.Node, dq_input.args[0])
190+
if q_input.op == "placeholder":
191+
return cls.from_q_dq_node(dq_input)
186192
return cls.from_q_dq_node(tensor_node)
187193

188194
return None

0 commit comments

Comments
 (0)