Check if the output of a node has a data type other than `torch.float32`. If the output is not `torch.float32`, quantization cannot be performed, as observers only work with floating-point tensors. Args: node (Node): The node to check the output(s) for. Returns: bo
(node: Node)
| 297 | |
| 298 | |
| 299 | def _is_non_float_tensor(node: Node) -> bool: |
| 300 | """Check if the output of a node has a data type other than `torch.float32`. |
| 301 | |
| 302 | If the output is not `torch.float32`, quantization cannot be performed, as |
| 303 | observers only work with floating-point tensors. |
| 304 | |
| 305 | Args: |
| 306 | node (Node): The node to check the output(s) for. |
| 307 | |
| 308 | Returns: |
| 309 | bool: `True` if the data type is not float32, otherwise `False`. |
| 310 | |
| 311 | Note: |
| 312 | - If `node.meta["val"]` is a `list`, the function returns `True` if |
| 313 | any element is not an instance of `FakeTensor` or does not have |
| 314 | `torch.float32` as its data type. |
| 315 | - If node.meta["val"] is missing or is not an instance of `FakeTensor`, |
| 316 | the function returns True. |
| 317 | |
| 318 | """ |
| 319 | if "val" in node.meta and isinstance(node.meta["val"], Sequence): |
| 320 | return any( |
| 321 | not isinstance(fake_tensor, FakeTensor) |
| 322 | or fake_tensor.dtype != torch.float32 |
| 323 | for fake_tensor in node.meta["val"] |
| 324 | ) |
| 325 | |
| 326 | if "val" not in node.meta or not isinstance(node.meta["val"], FakeTensor): |
| 327 | return True |
| 328 | |
| 329 | return node.meta["val"].dtype != torch.float32 |
| 330 | |
| 331 | |
| 332 | def _annotate_input(node: Node, quant_property: _QuantProperty): |
no outgoing calls
no test coverage detected