pytorch/torch/ao/quantization/pattern.md
Jerry Zhang 9cb52327a8 [quant][refactor] Move pattern type definition to ao/quantization/utils.py (#68769)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68769

att, since we want to use this type in fuser_method_mapping in later PRs

Test Plan:
no change to logic, just regression test on ci
```
python test/test_quantization.py
```

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D32602636

fbshipit-source-id: 15b95241431dfca9b1088d0920bf75705b37aa9a
2021-12-07 11:00:22 -08:00

22 lines
975 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Fusion Pattern Format
The patterns are we matching against is float modules types, functional operators and pytorch operators in reverse order:
```
operator = module_type | functional | torch op | native op | MatchAllNode
Pattern = (operator, Pattern, Pattern, ...) | operator
```
where the first item for Pattern is the operator we want to match, and the rest are the patterns for the arguments of the operator.
For example, pattern (nn.ReLU, (operator.add, MatchAllNode, (nn.BatchNorm2d, nn.Conv2d))) would match the following graph:
```
tensor_1 tensor_2
| |
*(MatchAllNode) nn.Conv2d
| |
| nn.BatchNorm2d
\ /
-- operator.add --
|
nn.ReLU
```
well match the last node as the anchor point of the match, and we can retrieve the whole graph by tracing back from the node, e.g. in the example above, we matched nn.ReLU node, then node.args[0] is the operator.add node.