MCPcopy Create free account
hub / github.com/pytorch/executorch / _is_large_scalar

Function _is_large_scalar

backends/arm/quantizer/quantization_annotator.py:277–296  ·  view source on GitHub ↗

Return True if input is a large scalar value. Large scalars are skipped because ``torch.histc`` supports values only up to a certain upper bound.

(node: Node, gm: torch.fx.GraphModule)

Source from the content-addressed store, hash-verified

275
276
277def _is_large_scalar(node: Node, gm: torch.fx.GraphModule):
278 """Return True if input is a large scalar value.
279
280 Large scalars are skipped because ``torch.histc`` supports values only up
281 to a certain upper bound.
282
283 """
284 HISTC_UPPER_BOUND = 3.4028235e15
285 if node.op == "get_attr" and isinstance(node.target, str):
286 tensor = _get_node_target(gm, node.target)
287 # torch.histc works until this upper bound
288 return tensor.numel() == 1 and abs(tensor.item()) > HISTC_UPPER_BOUND
289 if node.op == "call_function" and node.target in (
290 torch.ops.aten.full.default,
291 torch.ops.aten.full,
292 torch.ops.aten.fill_.Scalar,
293 ):
294 fill_value = cast(float, node.args[1])
295 return abs(fill_value) > HISTC_UPPER_BOUND
296 return False
297
298
299def _is_non_float_tensor(node: Node) -> bool:

Callers 2

_validate_matchMethod · 0.90
_is_ok_for_quantizationFunction · 0.85

Calls 2

_get_node_targetFunction · 0.85
numelMethod · 0.80

Tested by

no test coverage detected