Skip to content

refactor: use dataclass for weight axis defaults table#30

Merged
pkmandke merged 4 commits into
apple:mainfrom
pkmandke:dev/dataclass_for_axis_defaults
Jul 11, 2026
Merged

refactor: use dataclass for weight axis defaults table#30
pkmandke merged 4 commits into
apple:mainfrom
pkmandke:dev/dataclass_for_axis_defaults

Conversation

@pkmandke

@pkmandke pkmandke commented Jul 9, 2026

Copy link
Copy Markdown
Member

Use a dataclass instead of simple dict for the axis defaults table.

Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
}

# Maps aten OpOverload -> nn.Module type for graph-mode op to module type resolution.
_ATEN_OP_TO_MODULE_TYPE: dict[torch._ops.OpOverload, type[nn.Module]] = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This mapping in particular doesn't seem specific to axis defaults but more general to torch. Can we move it to torch_utils.py and have it define the mapping explicitly instead of pulling from _WEIGHT_AXIS_SPECS (which doesn't need to own the mapping)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

makes sense!

My intention here was that when we add a new entry for defaults, we only change it in one place. But with a separate table for the aten to module mapping, it will be 2 places.. I think that's fine since we get the mapping as a util of its own, separate from the defaults.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, yeah I feel like the table is generic enough that other things may also make use of it, feels better to separate out the responsibilities in this case.


if isinstance(granularity, PerChannelGranularity):
expected_axis = _PER_CHANNEL_WEIGHT_AXIS_DEFAULTS[module_type]
expected_axis = _WEIGHT_AXIS_SPECS[module_type].per_channel_axis

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we also test the default_axis_for function here?

pkmandke added 3 commits July 9, 2026 18:14
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
@pkmandke pkmandke merged commit 5cdb1f1 into apple:main Jul 11, 2026
8 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.

2 participants