ao icon indicating copy to clipboard operation
ao copied to clipboard

Duplicated ZeroPointDomain and MappingType

Open andrewor14 opened this issue 9 months ago • 6 comments

There's one in quant_primitives.py: https://github.com/pytorch/ao/blob/edd8abbfb4f7ef9d3ca4e41598ba9ec1cbebf213/torchao/quantization/quant_primitives.py#L78

Another one in pt2e.observer.py: https://github.com/pytorch/ao/blob/edd8abbfb4f7ef9d3ca4e41598ba9ec1cbebf213/torchao/quantization/pt2e/observer.py#L1662

Looks like MappingType is also copied over to PT2E. Now that these are in the same repo we should consolidate them.

andrewor14 avatar Feb 12 '26 16:02 andrewor14

yeah we have to deduplicate these, also the observer

jerryzh168 avatar Feb 12 '26 18:02 jerryzh168

hey @andrewor14 @jerryzh168 can i work on this? I have to deduplicate ZeroPointDomain from observer and import it from quant_primitives.py right?

omkar-334 avatar Feb 14 '26 22:02 omkar-334

hey @andrewor14 @jerryzh168 can i work on this? I have to deduplicate ZeroPointDomain from observer and import it from quant_primitives.py right?

oh sorry I think my previous comment was not very accurate, I think we'd like to deprecate ZeroPointDomain in the end actually, so probably better spent effort on removing this (doesn't have to be in a single PR)

so the task here would be: find all occurrences of ZeroPointDomain and remove them one by one, and in the end remove ZeroPointDomain from the code base

jerryzh168 avatar Feb 17 '26 20:02 jerryzh168

Another one in pt2e.observer.py:

ao/torchao/quantization/pt2e/observer.py

Line 1662 in edd8abb

class ZeroPointDomain(Enum):

@jerryzh168 This doesn;t exist in the main branch. It also imports from quant_primitives.py.
Right now ZeroPointDomain has one implementation, and it has around 30 occurrences. If we want to remove these one by one, what are we replacing it with?
Do we want to remove the Enum and use it directly as a parameter (Literal) or something like that?

omkar-334 avatar Feb 18 '26 05:02 omkar-334

we can split the functionality of ZeroPointDomain.FLOAT to some other ops, or just drop it, it's not always needed. we mostly just need to preserve the behavior of ZeroPointDomain.INT most of the time

you can check https://github.com/pytorch/ao/commit/04fb450912a3af7c08b45330936132c2d562e462 for examples

jerryzh168 avatar Feb 18 '26 05:02 jerryzh168

This looks already resolved — torchao/quantization/pt2e/observer.py now re-exports MappingType/ZeroPointDomain/TorchAODType from torchao.quantization.quant_primitives instead of defining its own copies (see the comment right above the import: "Re-exported from torchao.quantization.quant_primitives to avoid duplicate definitions."). No duplicate class definitions remain on main. Feel free to close if that matches your intent.

amanyagami avatar Aug 20 '26 21:08 amanyagami