Skip to content

(fix: quantization) skip non-float module boundary values in graph mode - #173

Merged
pkmandke merged 6 commits into
apple:mainfrom
pkmandke:dev/skip_single_element_node_quant
Nov 5, 2026
Merged

pkmandke merged 6 commits into
apple:mainfrom
pkmandke:dev/skip_single_element_node_quant

Conversation

@pkmandke

@pkmandke pkmandke commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

tl;dr: module_input_spec={0: ...} on a decomposed SDPA module resolved to a SymInt from sym_size. prepare() then attached a FakeQuantize to a Python int and crashed on tensor.ndim. This fix skips non-float boundary values during prepare() in graph mode.


A module-level module_input_spec / module_output_spec that resolves to a
shape integer crashes prepare:

AttributeError: 'int' object has no attribute 'ndim'
  qparams_calculator.py:340  self._resolve_axis(tensor.ndim)

The prepared graph has activation_post_process_N(sym_size_int_M): a
FakeQuantize attached to a Python int.

Change/Fix

Skip non-floating-point values in _find_and_apply_module_level_spec (inputs and
outputs).

How it was found

module_input_spec={0: <fp8>} on a decomposed SDPA module, meant to quantize the
query. SDPA builds its causal mask from shape integers before touching the query,
so boundary input 0 ends up being a SymInt.

Tests

TestNonFloatModuleBoundary in test_graph_mode_quantizer.py, for the wildcard
and {0: spec} cases. Both fail before this change with the error above and
pass after.

Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
@pkmandke
pkmandke requested review from crowbat and vineet-g October 29, 2026 23:38
@pkmandke
pkmandke marked this pull request as ready for review November 2, 2026 23:41
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
@pkmandke
pkmandke requested a review from vineet-g November 3, 2026 01:11
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
@pkmandke
pkmandke enabled auto-merge (squash) November 5, 2026 20:33
@pkmandke
pkmandke merged commit ab6f171 into apple:main Nov 5, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants