Skip to content

Commit f9bac8c

Browse files
committed
refactor: default _op_preserves_axis_identity's fallback to unsafe
After the previous commit's restructuring, this function is only ever called for ops confirmed to be in _AXIS_REORDERING_ATEN_OPS (transpose, t, permute) - and the three branches above already cover every member of that set exhaustively, so the trailing fallback is unreachable in current operation. Flip it from True to False anyway, so a future op added to _AXIS_REORDERING_ATEN_OPS without a matching branch here fails safe (assumed to move the axis) rather than fails open (assumed to leave it untouched). Before the prior commit, this fallback was still reachable by pooling ops falling through with no explicit branch, so it had to stay True; now that pooling is dispatched to a separate branch in the caller and never reaches this function, the flip is a no-op in practice (confirmed: no test outcome changes) but closes the gap for whatever's added here next.
1 parent 605cc97 commit f9bac8c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/coreai_opt/quantization/_graph/_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,10 @@ def _op_preserves_axis_identity(op_node: Node, axis: int) -> bool:
314314
``axis`` to a different position between its input and output.
315315
316316
Only called for ops in ``_AXIS_REORDERING_ATEN_OPS`` (transpose, t,
317-
permute); the three branches below cover exactly those ops, so the
318-
trailing fallback is unreachable in practice.
317+
permute), which the three branches below exhaustively cover. The
318+
trailing fallback defaults to False rather than True, consistent with
319+
this module's fail-safe default: a reordering op this function doesn't
320+
yet know how to analyze should never be assumed identity-preserving.
319321
"""
320322
if op_node.target == torch.ops.aten.transpose.int:
321323
_, dim0, dim1 = op_node.args
@@ -331,7 +333,7 @@ def _op_preserves_axis_identity(op_node: Node, axis: int) -> bool:
331333
if op_node.target == torch.ops.aten.permute.default:
332334
_, dims = op_node.args
333335
return dims[axis] == axis
334-
return True
336+
return False
335337

336338

337339
def _force_fake_quant_to_per_tensor(fake_quant: FakeQuantizeImplBase, op_node: Node) -> None:

0 commit comments

Comments
 (0)