Annotate supported nodes in a graph with quantization specs. Iterate through call_function nodes, computes quantization properties, and apply input/output annotations. A filter can restrict which nodes are considered. Args: gm (torch.fx.GraphModule): Graph to annotate.
( # type: ignore[return]
gm: torch.fx.GraphModule,
quantization_config: QuantizationConfig,
filter_fn: Optional[Callable[[Node], bool]] = None,
)
| 935 | |
| 936 | |
| 937 | def annotate_graph( # type: ignore[return] |
| 938 | gm: torch.fx.GraphModule, |
| 939 | quantization_config: QuantizationConfig, |
| 940 | filter_fn: Optional[Callable[[Node], bool]] = None, |
| 941 | ) -> Optional[List[List[Node]]]: |
| 942 | """Annotate supported nodes in a graph with quantization specs. |
| 943 | |
| 944 | Iterate through call_function nodes, computes quantization properties, and |
| 945 | apply input/output annotations. A filter can restrict which nodes are |
| 946 | considered. |
| 947 | |
| 948 | Args: |
| 949 | gm (torch.fx.GraphModule): Graph to annotate. |
| 950 | quantization_config (QuantizationConfig): Default qspecs for nodes. |
| 951 | filter_fn (Optional[Callable[[Node], bool]]): Optional node predicate. |
| 952 | |
| 953 | Returns: |
| 954 | Optional[List[List[Node]]]: Reserved for future use; currently None. |
| 955 | |
| 956 | """ |
| 957 | for node in gm.graph.nodes: |
| 958 | if node.op != "call_function": |
| 959 | continue |
| 960 | |
| 961 | if is_annotated(node): |
| 962 | continue |
| 963 | |
| 964 | if filter_fn is not None and not filter_fn(node): |
| 965 | continue |
| 966 | |
| 967 | quant_properties = get_quant_properties(node, gm, quantization_config) |
| 968 | if quant_properties is None: |
| 969 | continue |
| 970 | |
| 971 | for quant_property in quant_properties.quant_inputs: |
| 972 | _annotate_input(node, quant_property) |
| 973 | |
| 974 | if quant_properties.quant_output is not None: |
| 975 | _annotate_output(node, quant_properties.quant_output) |
| 976 | |
| 977 | mark_node_as_annotated(node) # type: ignore[attr-defined] |
no test coverage detected