Skip to content

Commit 29becc9

Browse files
committed
/
1 parent b9d09f3 commit 29becc9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

prototype_source/pt2e_quantizer.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ functions that are used in the example:
304304

305305
A Note on IR for PT2E Quantization Flow
306306
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
307-
IR means the intermediate representation of the model, for example, ``torch`` IR (``torch.nn`` modules, ``torch.nn.functional`` ops) or ``aten`` IR (``torch.ops.aten.linear``, ...). PT2E Quantization Flow is using pre autograd aten IR (the output of `torch.export` API) so that we support training. As is shown before, we need to match the operator or operator patterns before we can do annotations on them, So the question is how do we match the pattern?
307+
IR means the intermediate representation of the model, for example, ``torch`` IR (``torch.nn`` modules, ``torch.nn.functional`` ops) or ``aten`` IR (``torch.ops.aten.linear``, ...). PT2E Quantization Flow is using pre autograd aten IR (the output of `torch.export` API) so that we support training. As is shown before, we need to match the operator or operator patterns before we can attach annotations on them, So the question is how do we match the pattern?
308308

309309
1. Matching ``aten`` IR directly
310310
------------------------------------
@@ -363,7 +363,7 @@ With this, the ``Quantizer`` will still be valid even when the implementation fo
363363
One caveat is that if inputs of the pattern has multiple users, we don't have a good way to identify which user node we want to annotate except for checking the aten op target.
364364

365365
Another caveat is that we need to make sure we have an exhaustive list of examples (e.g. 2D, 3D, 4D inputs, real v.s. symbolic inputs, training=True v.s. training=False etc.) for the pattern to make sure cover different possible ``aten`` IR outcomes captured from the ``torch`` IR pattern.
366-
366+
367367
3. Using ``SubgraphMatcherWithNameNodeMap``
368368
----------------------------------------------
369369
We also introduced a different SubgraphMatcher util called ``SubgraphMatcherWithNameNodeMap`` to make it easier to query the nodes that people want to annotate.
@@ -400,7 +400,15 @@ Example::
400400
...
401401

402402

403-
Similar to ``SubgraphMatcher``, we also need to make sure to capture the PyTorch pattern with different example inputs to cover all possible ``aten`` IR variants.
403+
Similar to ``SubgraphMatcher``, we also need to make sure to capture the PyTorch pattern with different example inputs to cover all possible ``aten`` IR variants.
404+
405+
4. General Recommentation
406+
----------------------------------------------
407+
Given the above UX and constraints/caveats, we recommend people to start with option 3. and make sure the first operator in the pattern are functional ops that map to one aten op (e.g. F.conv2d, F.linear), and provide enough variants of example inputs. (We may provide some (pattern, list of example_inputs) so people can just use them directly in the future)
408+
409+
If people are uncertain if some functional operator is going to be traced into multiple aten operators then they can pick option 2.
410+
411+
We would not recommend option 1. since that's the least stable in all three options.
404412

405413
Conclusion
406414
^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)