From ebb5a39ec3cffdbf255c5f753bf4b8a0ce4c146c Mon Sep 17 00:00:00 2001 From: Matthias Cremon Date: Tue, 10 Mar 2026 13:48:50 -0700 Subject: [PATCH] Bugfixes for Quantizer (#18068) Summary: Fixes a bug introducing empty cat operators in the quantizer, and one where the output of a pass is not serializable. Reviewed By: zonglinpeng Differential Revision: D95961290 --- backends/cadence/aot/quantizer/fusion_pass.py | 3 +++ backends/cadence/aot/replace_ops.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/backends/cadence/aot/quantizer/fusion_pass.py b/backends/cadence/aot/quantizer/fusion_pass.py index 349659d1e7f..0cdda1ad3bc 100644 --- a/backends/cadence/aot/quantizer/fusion_pass.py +++ b/backends/cadence/aot/quantizer/fusion_pass.py @@ -563,6 +563,9 @@ def call(self, graph_module: fx.GraphModule) -> PassResult: # noqa: C901 quant_node, ) elif isinstance(pattern, CatPattern): + # Skip fusion if inputs_inputs is empty to avoid creating cat([]) + if not inputs_inputs: + continue args, kwargs = get_args_and_kwargs_cat( inputs_inputs, other_inputs, op_node ) diff --git a/backends/cadence/aot/replace_ops.py b/backends/cadence/aot/replace_ops.py index f563a331975..14a35c01baf 100644 --- a/backends/cadence/aot/replace_ops.py +++ b/backends/cadence/aot/replace_ops.py @@ -2368,8 +2368,18 @@ def maybe_remove_or_replace(self, node: torch.fx.Node) -> bool: args=([1], full_arg), kwargs={"dtype": full_output_dtype}, ) - full_node.meta = node.meta - full_node.meta["val"] = [1] + full_node.meta = node.meta.copy() + # Create a proper FakeTensor for metadata instead of Python list + fake_mode = node.meta["val"].fake_mode + if fake_mode is not None: + with fake_mode: + full_node.meta["val"] = torch.full( + [1], full_arg, dtype=full_output_dtype + ) + else: + full_node.meta["val"] = torch.empty( + [1], dtype=full_output_dtype, device="meta" + ) new_mul_node = node.graph.call_function( torch.ops.aten.mul.Tensor, args=(x_arg, full_node) )